module 3 n.
Skip this Video
Loading SlideShow in 5 Seconds..
Module:3 PowerPoint Presentation


129 Vues Download Presentation
Télécharger la présentation


- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Module:3 Sensors Programming

  2. 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.

  3. Module Contents

  4. 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.

  5. Different types of sensors

  6. Lego Mindstorms NXT Sensors • Touch Sensor. • Sound Sensor. • Light Sensor. • Ultrasonic Sensor.

  7. 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.

  8. Sensor Block The blocks in the table above are used to adjust the sensors and view the possible readings ranges

  9. 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

  10. 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.

  11. Configuration panel • Port • Action • Feedback box

  12. Wait: Touch sensor Block • Waits for an action or sensor reading to perform a task • Port • Action

  13. Configuring Wait - Touch Sensor Block • Control • Sensor • Port • Action • Feedback Box

  14. Conditional and Unconditional Loop • Repeats a code sequence without any condition (forever) • Repeats a code sequence based on certain condition

  15. 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

  16. 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

  17. Switch – Touch Sensor Block • Chooses between to code sequences based on a value or a sensor. • Control: Sensor. • Sensor: Touch Sensor.

  18. 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.

  19. 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

  20. Flat View • Switch block will use a tabbed interface to show the alternative sequences of programming blocks.

  21. Touch Sensor- Task-1

  22. Touch Sensor – Task-2 • Control a motor using a touch sensor; run the motor when the touch sensor is pressed.

  23. 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.

  24. 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%).

  25. 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.

  26. 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.

  27. 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.

  28. Sound Sensor :Tasks-1

  29. 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”

  30. 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.

  31. 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%).

  32. Light Sensor – Task-3 Without Generate Light option With Generate Light option

  33. Light Sensor – Task-3

  34. 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.

  35. 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

  36. Configuring Ultrasonic Sensor Block • Port • Radio button • left radio button • right radio button • Select to read values in Centimeters or Inches. • The feedback box

  37. Ultrasonic Sensor: Tasks Measure the distance with the following setting and observe the reading in the feedback box

  38. 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)

  39. Ultrasonic Sensor: Task-2

  40. 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

  41. 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

  42. 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

  43. 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.

  44. Wait block: Rotation Sensor

  45. Loop Block: Rotation Sensor

  46. Switch Block: Rotation Sensor

  47. Rotation Sensor: Task • Rotate the Motor Manually forth and back and observe the readings, what kind of readings are you getting

  48. 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.

  49. 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