12Events_2

12Events_2 - Solution Monitoring Multiple Events Add to the...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Events Comp106 Problem #1 • You want the rover to go forward until the touch sensor is pressed, then stop.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Simple! Checks every 0.01 second Problem #2 • What if we want the robot to patrol in a square until sensor #1 is touched?
Background image of page 2
Problem #2 • Would this work? The Real Problem • Problem #2 is easy in RCX… • Not possible in NQC, since loops are NOT interrupt-based. • We want the robot to continually monitor the touch sensor. • If the touch sensor is pressed AT ANY TIME, stop the motors.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Solution (with events) To Monitor An Event • You can have up to 16 events • First, set the event to one of the 16 slots. – SetEvent( <event num>, <sensor>, <event type>); • Then, use the “monitor…catch” construct. • Once the event is caught, we exit the monitor block. – The catch block is executed. • Also known as interrupt in OS.
Background image of page 4
Exercise • Have the robot patrol in a square forever. • If touch sensor 1 is touched, stop for 0.5 second, beep, and then continue.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Solution Monitoring Multiple Events Add to the previous program such that if the right sensor is touched, the robot would spin 360 degrees before resuming the square patrol. Solution Setting multiple events Monitor the events Catch the events Practical Robotics Many times, we want a robot to cover an entire area without getting stuck. We dont know what the area looks like. Example: vacuum robot http://www.irobot.com/consumer/ Use the random walk algorithm. Random Walk The robot goes forward for a pre-determined amount of steps. After each step, the robot turns randomly to any of one of n directions. Continues forever. http://en.wikipedia.org/wiki/Random_walk Improvements We dont want the robot to keep ramming into objects. Use events. If either of the sensors is touched, back up a bit and turn until the sensor is released....
View Full Document

Page1 / 8

12Events_2 - Solution Monitoring Multiple Events Add to the...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online