Module:3
description
Transcript of Module:3
![Page 1: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/1.jpg)
Module:3Sensors Programming
![Page 2: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/2.jpg)
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.
![Page 3: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/3.jpg)
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)
![Page 4: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/4.jpg)
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.
![Page 5: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/5.jpg)
Different types of sensors
![Page 6: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/6.jpg)
Lego Mindstorms NXT Sensors• Touch Sensor.• Sound Sensor.• Light Sensor.• Ultrasonic Sensor.
![Page 7: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/7.jpg)
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.
![Page 8: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/8.jpg)
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
![Page 9: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/9.jpg)
![Page 10: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/10.jpg)
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
![Page 11: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/11.jpg)
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.
![Page 12: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/12.jpg)
Configuration panel
• Port• Action• Feedback box
![Page 13: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/13.jpg)
Wait: Touch sensor Block • Waits for an action or sensor reading
to perform a task
• Port• Action
![Page 14: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/14.jpg)
Configuring Wait - Touch Sensor Block
• Control• Sensor• Port• Action• Feedback Box
![Page 15: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/15.jpg)
Conditional and Unconditional Loop
• Repeats a code sequence without any condition (forever)
Repeats a code sequence based on certain condition
![Page 16: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/16.jpg)
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
![Page 17: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/17.jpg)
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
![Page 18: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/18.jpg)
Switch – Touch Sensor Block• Chooses between to code sequences
based on a value or a sensor.
– Control: Sensor.– Sensor: Touch Sensor.
![Page 19: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/19.jpg)
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.
![Page 20: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/20.jpg)
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
![Page 21: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/21.jpg)
Flat View• Switch block will use a tabbed
interface to show the alternative sequences of programming blocks.
![Page 22: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/22.jpg)
Touch Sensor- Task-1
Action Feedback box / color / reset!!
Pressed
Released
Bumped
![Page 23: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/23.jpg)
Touch Sensor – Task-2• Control a motor using a touch sensor;
run the motor when the touch sensor is pressed.
![Page 24: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/24.jpg)
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.
![Page 25: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/25.jpg)
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%).
![Page 26: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/26.jpg)
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.
![Page 27: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/27.jpg)
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.
![Page 28: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/28.jpg)
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.
![Page 29: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/29.jpg)
Sound Sensor :Tasks-1
Compare Feedback box – values
Loud Medium soft
> 25
<80
>50
![Page 30: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/30.jpg)
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”
![Page 31: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/31.jpg)
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.
![Page 32: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/32.jpg)
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%).
![Page 33: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/33.jpg)
Light Sensor – Task-3
Feedback box – valuesBlack Green Red Yellow
Feedback box – valuesBlack Green Red Yellow
Without Generate Light option
With Generate Light option
![Page 34: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/34.jpg)
Light Sensor – Task-3
Color
Action Black Green Yellow
Forward
Backward
Stop
![Page 35: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/35.jpg)
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.
![Page 36: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/36.jpg)
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
![Page 37: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/37.jpg)
Configuring Ultrasonic Sensor Block• Port• Radio button
– left radio button– right radio button
• Select to read values in Centimeters or Inches.
• The feedback box
![Page 38: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/38.jpg)
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
![Page 39: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/39.jpg)
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)
![Page 40: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/40.jpg)
Ultrasonic Sensor: Task-2
Distance Action<10 cm – close to the table surface
<50 cm
> 50 cm – make it far
![Page 41: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/41.jpg)
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
![Page 42: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/42.jpg)
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
![Page 43: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/43.jpg)
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
![Page 44: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/44.jpg)
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.
![Page 45: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/45.jpg)
Wait block: Rotation Sensor
![Page 46: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/46.jpg)
Loop Block: Rotation Sensor
![Page 47: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/47.jpg)
Switch Block: Rotation Sensor
![Page 48: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/48.jpg)
Rotation Sensor: Task• Rotate the Motor Manually forth and
back and observe the readings, what kind of readings are you getting
![Page 49: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/49.jpg)
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.
![Page 50: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/50.jpg)
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
![Page 51: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/51.jpg)
NXT Buttons Block• The icon at the bottom of the block
indicates which NXT button has been selected.
• The block’s data hub
![Page 52: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/52.jpg)
Configuration Panel• NXT button• Action• The feedback box
![Page 53: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/53.jpg)
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.
![Page 54: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/54.jpg)
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.
![Page 55: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/55.jpg)
Sensor Calibration• Use this block to calibrate the
minimum (0%) and maximum (100%) values detected by a sound or light sensor.
![Page 56: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/56.jpg)
Calibaration Block• Data hub will open automatically
when the block is placed in the work area
![Page 57: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/57.jpg)
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.
![Page 58: Module:3](https://reader036.fdocuments.net/reader036/viewer/2022062501/568163d5550346895dd521bb/html5/thumbnails/58.jpg)
Tasks:
Value ResultMinimum
Maximum