580 likes | 722 Views
Module:3. Sensors 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.
E N D
Module:3 Sensors 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.
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.
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 The blocks in the table above are used to adjust the sensors and view the possible readings ranges
Flow Block 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: • NXT’s port to which sensor is connected • This icon will show which action will send a “true” signal (Bumped, Pressed, or Released). • 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. • NXT’s port • This icon will show which action will send a “true” signal (Bumped, Pressed, or Released). • Showing an icon for the chosen sensor
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 • Port • Until • Feedback Box • 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.
Example • This icon indicates the sensor or other condition that will cause the block to choose between the two rows of programming blocks. • The upper blocks will run if the touch sensor is pressed. • 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. • Flat View • Port • Action
Flat View • Switch block will use a tabbed interface to show the alternative sequences of programming blocks.
Touch Sensor – Task-2 • Control a motor using a touch sensor; run the motor when the touch sensor is pressed.
Sound Sensor Block: • NXT’s ports • level the trigger point is set. • 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: • Choose the port • Use the slider to set the trigger value or type a value directly into the input box. • 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-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: • NXT’s ports. • This icon indicates at what level the trigger point is set. • This icon is displayed if “Generated Light” is turned on. • 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 Without Generate Light option With Generate Light option
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 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)
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.
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