Module:3
description
Transcript of Module:3
Module:3Sensors Programming
Module Objectives
• Understand the use of sensors.• Program and use a touch sensor.• Program, calibrate and use a Sound
sensor.• Program, calibrate and use a Light sensor.• Program and use an ultrasonic sensor.• Program and use a Rotation sensor.• Program and use the NXT buttons as a
sensor.• Use the Calibrate sensor block to calibrate
sensors.
Module Contents Sensors
LEGO MINDSTORMS NXT Sensors
Programming Palette Blocks for Sensors
Learning Tasks -1 (Touch Sensor)
Learning Tasks -2 (Sound Sensor)
Learning Tasks -3 (Light Sensor)
Learning Tasks -4 (Ultrasonic Sensor)
Learning Tasks -5 (Rotation Sensors)
Learning Tasks -6 (NXT Buttons)
Learning Tasks -7 (Sensor Calibration)
Sensors• Sensors are the robot senses which
help the robot to sense the environment
• Definition:– Sensors could be defined as an electronic
device used to measure a physical quantity such as temperature, pressure or loudness and convert it into an electronic signal.
Different types of sensors
Lego Mindstorms NXT Sensors• Touch Sensor.• Sound Sensor.• Light Sensor.• Ultrasonic Sensor.
Programming palette blocks for Sensors• Common Palette: wait, loop and
Switch blocks could use the sensor readings.
• Complete Palette: it has the common palette block with the blocks mentioned above, the flow and the Sensor blocks.
• Custom Palette: can create a program and save it to be used as a single block later.
Sensor Block
Touch Sensor
Sound Sensor
Light Sensor
Ultrasonic Sensor
NXT Buttons
Rotation Sensors
Timer Receive message
The blocks in the table above are used to adjust the sensors and view the possible readings ranges
Flow Block
Wait Loop Switch Stop
The flow block icons are mainly conditional blocks – waiting for a certain reading or input from the sensor, looping until a certain sensor reading, switch between two actions depending on a sensor reading
Touch Sensor Block:1. NXT’s port to which sensor is connected
2. This icon will show which action will send a “true” signal (Bumped, Pressed, or Released).
3. Block’s data hub: A data wire must be dragged from the block’s output plug to another block’s data hub.
Configuration panel
• Port• Action• Feedback box
Wait: Touch sensor Block • Waits for an action or sensor reading
to perform a task
• Port• Action
Configuring Wait - Touch Sensor Block
• Control• Sensor• Port• Action• Feedback Box
Conditional and Unconditional Loop
• Repeats a code sequence without any condition (forever)
Repeats a code sequence based on certain condition
Loop – Touch Sensor Block• Repeats a code sequence based on a
condition, for example a sensor.
1. NXT’s port2. This icon will show which action will
send a “true” signal (Bumped, Pressed, or Released).
3. Showing an icon for the chosen sensor
1
2 3
Configuring Loop - Touch Sensor Block:
• If you choose “Touch Sensor,” the programming blocks within the loop will repeat until a touch sensor is bumped, pressed, or released
1. Port2. Until3. Feedback Box4. Counter- allows you to use the number of completed loops as an
input elsewhere in your program
Switch – Touch Sensor Block• Chooses between to code sequences
based on a value or a sensor.
– Control: Sensor.– Sensor: Touch Sensor.
Example1. This icon indicates the sensor or other
condition that will cause the block to choose between the two rows of programming blocks.
2. The upper blocks will run if the touch sensor is pressed.
3. The lower block will run if the touch sensor is not being pressed.
Configuring Switch - Touch Sensor Block
Choose this control property if you want the condition of a touch sensor to determine which way your program will switch.
1. Flat View2. Port3. Action
Flat View• Switch block will use a tabbed
interface to show the alternative sequences of programming blocks.
Touch Sensor- Task-1
Action Feedback box / color / reset!!
Pressed
Released
Bumped
Touch Sensor – Task-2• Control a motor using a touch sensor;
run the motor when the touch sensor is pressed.
Sound Sensor Block:
1. NXT’s ports2. level the trigger point is set. 3. The block’s data hub will open
automatically when the block is attached to a sequence beam.
– At least one data wire must be dragged from the block’s output plug to another block’s data hub.
Configuring Sound Sensor Block:
1. Choose the port2. Use the slider to set the trigger value or type a
value directly into the input box. 3. The feedback box displays the current sound
reading (0-100%).
Blocks Data Hubs & Wiring:• Data wires carrying input information
to a block are connected to the plugs on the left side of its data hub.
• Data wires carrying output information are connected to the plugs on the right side as shown in the figure below.
Blocks Data Hubs & Wiring:• [A] Input plug
[B] Output plug[C] Number data wire (yellow)[D] Logic data wire (green)[E] Text data wire (orange)[F] Broken data wire (gray) --- error – your program wont run if you have gray wires.
Important Points • Note: when connecting blocks hubs to each other
(wiring) be aware that you connect as follows:• • Data plug to Data plug.• A number data to a number data.• Logic data to logic data• Text data to text data
• Otherwise you’ll get the gray broken wire which indicates an error, where your program will not run.
Sound Sensor :Tasks-1
Compare Feedback box – values
Loud Medium soft
> 25
<80
>50
Sound Sensor :Tasks-2• Use wiring and switch
block to do the following:– If the sound detected by
the sound sensor is higher than 50 the NXT brick will generate a sound saying “ you are good”
– If the sound detected is less than 50 the sound generated will be “Woops”
Light Sensor Block:1. NXT’s ports.
2. This icon indicates at what level the trigger point is set.
3. This icon is displayed if “Generated Light” is turned on.
4. The block’s data hub will open automatically when the block is placed in the work area.
Configuring Light Sensor Block:• Choose the port• Use the slider to set the trigger value or type a
value directly into the input box. • If you check the “Generated Light” checkbox, the
light sensor will turn on its own small light source and detect this light if it is reflected back to it.
• feedback box displays the current light reading (0-100%).
Light Sensor – Task-3
Feedback box – valuesBlack Green Red Yellow
Feedback box – valuesBlack Green Red Yellow
Without Generate Light option
With Generate Light option
Light Sensor – Task-3
Color
Action Black Green Yellow
Forward
Backward
Stop
Calibration (Adjusting):
• Calibration is the process of adjusting a device or a sensor knowing its standards, limits and responses.
• • Sensor Calibration is the
relationship between input and output for a given measurement.
Ultrasonic Sensor• This block can detect objects at a
maximum range of about 250 cm (or 100 inches).
• NXT’s port• Shows whether the ultrasonic sensor
is set to detect objects nearby or farther away. – The more colored bars, the farther away
the detection. • Data hub
Configuring Ultrasonic Sensor Block• Port• Radio button
– left radio button– right radio button
• Select to read values in Centimeters or Inches.
• The feedback box
Ultrasonic Sensor: Tasks
Compare Feedback box – values
0-2 cm 100 cm 200 cm 300 cm> 25<80>50
Measure the distance with the following setting and observe the reading in the feedback box
Ultrasonic Sensor: Task-2• Create a program that does the
following:– Runs a motor forward – duration
unlimited.– Using a switch block & Depending
on the Ultrasonic sensor reading:• Distance is almost zero (0-
2cm)--close: Stop the motor, play a sound (file: Ouch 02) and run backward.
• If distance less than 50: forward at power of 40.
• If more than 50 cm: forward with power of 80 & play a sound (file: Forward)
Ultrasonic Sensor: Task-2
Distance Action<10 cm – close to the table surface
<50 cm
> 50 cm – make it far
Rotation Sensor• The rotation sensor is a built in
sensor inside each Motor, so it is not visible where the rotational feedback from these sensors allows the NXT to control movements very precisely.
This block counts the number of degrees (one full rotation is 360 degrees) or full rotation that your motor turns
Rotation Sensor• NXT port the Rotation Sensor block
will be monitoring. • This icon will show whether the block
is counting in rotations or degrees
• The block’s data hub
Configuring Rotation Sensor Block• Port you would like the block to monitor (A, B, or C). • To read a rotation sensor's current value or to reset a
sensor's value back to zero. • Set the direction you want to monitor using the radio
buttons: forwards or backwards. • Number of rotations or degrees. • Trigger value• The feedback box will show the current count in
Rotation Sensor• Forward (positive) direction
– Black-colored text for rotations or degrees;
• Backward (negative) direction– it will be in red-colored text rotations or
degrees.
Wait block: Rotation Sensor
Loop Block: Rotation Sensor
Switch Block: Rotation Sensor
Rotation Sensor: Task• Rotate the Motor Manually forth and
back and observe the readings, what kind of readings are you getting
Program• Build your program to do the following:
– Let the motor run forward for 3 rotations.– Stop the motor.– Wait for 3 seconds.– Reverse your motor direction for 720 degrees.
NXT Buttons Block• The NXT button (three: Orange (Enter
Button) and the triangular buttons) can be used as sensors in your program, for example you can stop a motor if the orange button is pressed
NXT Buttons Block• The icon at the bottom of the block
indicates which NXT button has been selected.
• The block’s data hub
Configuration Panel• NXT button• Action• The feedback box
Tasks:
Button/ Action Pressed Released Bumped
Enter
Right
Left
Monitor the NXT button selected through the feedback box.Fill the following table when the button is pressed.
Program• Create a program that uses the Enter
button (orange) to run a motor forward and backward it as follows:– Wait for the orange button to be
pressed to run the motor forward for 5 seconds.
– Wait for the orange button to be pressed again to run it backward for two rotations.
Sensor Calibration• Use this block to calibrate the
minimum (0%) and maximum (100%) values detected by a sound or light sensor.
Calibaration Block• Data hub will open automatically
when the block is placed in the work area
Configuration Panel• Choose the port that the sensor is connected to. • Select whether you are calibrating a Sound
Sensor or a Light Sensor. • With this pull-down menu, choose to either
calibrate a new value or delete a previously set value.
• Use the radio buttons to set either the maximum or minimum value of the sensor.
Tasks:
Value ResultMinimum
Maximum