1 / 20

Robot Movement and Navigation

CPSC 120 Principles of Computer Science February 22, 2012. Robot Movement and Navigation. Where we are now. We know how to use the Basic Editor, download code to BS2, blink LEDs, PULSOUT to turn wheels, etc. We have basic loops available such as DO…LOOP and FOR…NEXT

rich
Télécharger la présentation

Robot Movement and Navigation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CPSC 120 Principles of Computer Science February 22, 2012 Robot Movement and Navigation

  2. Where we are now We know how to use the Basic Editor, download code to BS2, blink LEDs, PULSOUT to turn wheels, etc. We have basic loops available such as DO…LOOP and FOR…NEXT We understand how variables are used to assign/change/increment values. We understand how to use DEBUG to get program feedback to check variable values.

  3. Moving Your Robot ' Right servo turns clockwise three seconds, stops 1 second, ‘ then counterclockwise three seconds. ' {$STAMP BS2} ' {PBASIC 2.5} counter VAR Word ‘ Declare our loop control variable DEBUG "Program Running!" ‘ Give the user notice we are running FOR counter = 1 TO 122 ' Turn clockwise about 3 seconds. PULSOUT 12, 650 ‘ Send a 1300 us = 1.3 ms pulse PAUSE 20 ‘ Let the servo respond for 20 ms NEXT ‘ Bottom of loop, repeat or leave loop FOR counter = 1 TO 40 ' Stop servo one second. PULSOUT 12, 750 ‘ Send center value to servo PAUSE 20 ‘ Let the servo respond NEXT ' Bottom of loop FOR counter = 1 TO 122 ' Counterclockwise three seconds. PULSOUT 12, 850 ‘ Send 1.7 ms pulse to servo, reverse PAUSE 20 ‘ Let it respond NEXT ‘ Bottom of loop END ‘ End of program

  4. Driving Lessons ' Move robot forward, left, right, then backward for testing. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Program Running!” counter VAR Word ‘ Loop control counter FOR counter = 1 TO 64 ' Drive forward PULSOUT 13, 850 PULSOUT 12, 650 PAUSE 20 NEXT PAUSE 200 ‘ Do nothing for 0.2 seconds FOR counter = 1 TO 24 ' Rotate left-about 1/4 turn PULSOUT 13, 650 PULSOUT 12, 650 PAUSE 20 NEXT ‘ Continued next page

  5. Driving Lessons (cont) ‘Code continued from previous slide PAUSE 200 ‘ Pause again for a bit FOR counter = 1 TO 24 ' Rotate right-about 1/4 turn PULSOUT 13, 850 PULSOUT 12, 850 PAUSE 20 NEXT PAUSE 200 ‘ Stop once more briefly FOR counter = 1 TO 64 ’ Drive backward PULSOUT 13, 650 PULSOUT 12, 850 PAUSE 20 NEXT END

  6. Useful Facts to Remember Once a PBASIC program is downloaded to BOE-BOT, it remains in RAM until the program is overwritten. Switch position off, 1, 2 does not remove the program. When the Reset button on BOE-BOT is pressed, the current program in RAM is restarted at its beginning. Once a program is downloaded, you can unplug the USB cable, put the robot on the floor, press Reset and watch your program control your robot! Your robot is autonomous. Only your program controls it. Smarter robots mean more complex PBASIC programs. Putting a PAUSE 2000 as the first real instruction in your program helps avoid physical starting issues such as catching your fingers on the moving robot board. WATCH OUT FOR RUNAWAY ROBOTS!

  7. Where we are going Build the robot and learn how to fully control our robot using PULSOUT commands. Learn more PBASIC control structures so we can react to infrared (IR) obstacle sensor information to avoid obstacles. Use subroutines and IR information to avoid obstacles and traverse a maze without using dead reckoning (guess distances/code loops) Add two more downward looking IR sensors to detect a white line on a dark floor Write and test code to follow a white line around a loop Add an obstacle or two to make it interesting

  8. Subroutines in PBASICallow out-of-order execution

  9. Using Subroutines to Move

  10. Using Infrared to Detect Obstacles

  11. IR Circuit Schematic Note we can rapidly blink our LEDs using a FREQOUT command in PBASIC on pins P0 and P2 then read the signal (0 or 1) at pins P8 and P9 which report any reflected IR signal.

  12. IR Circuit Wiring Note we need to be careful to be sure that the IR LEDs are inserted correctly, LEDs don't shine when reversed! Also notice that things are getting crowded on the breadboard. Neatness is helpful.

  13. IR Testing Program ' IR testing code. See pages 235-242 in BOE manual. ' Test two sided IR object detection circuits before using for navigation ' {$STAMP BS2} ' {$PBASIC 2.5} irDetectLeft VAR Bit ' Variable to hold left detector value irDetectRight VAR Bit ' Variable to hold right detector value DO ' Repeat forever FREQOUT 8, 1, 38500 ' Pulse Left IR LED for 1 ms irDetectLeft = IN9 ' Read pin for IR bounce and store FREQOUT 2, 1, 38500 ' Pulse Right IR LED for 1 ms irDetectRight = IN0 ' Read pin for IR bounce and store DEBUG CLS, "irDetectLeft = ", BIN1 irDetectLeft , "irDetectRight = ", BIN1 irDetectRight PAUSE 1000 ' Wait one second to read the news LOOP END

  14. Navigation Using IR Sensors ‘ Skeleton code for navigation to avoid obstacles using IR DO FREQOUT 8, 1, 38500 ‘ Flash left IR LED irDetectLeft = IN9 ‘ Record any IR bounce FREQOUT 2, 1, 38500 ‘ Flash right IR LED irDetectRight = IN0 ‘ Record any IR bounce IF (irDetectLeft = 0) THEN ‘ Look out on left, evasive action GOSUB Turn_Right ELSE GOSUB Forward_Pulse ‘ Clear on left, continue ENDIF IF (irDetectRight = 0) THEN ‘ Danger on right, swerve left GOSUB Turn_Left ELSE GOSUB Forward_Pulse ‘ Clear on right, continue ENDIF LOOP

  15. More Complex Decisions: Logic Again! DO FREQOUT 8, 1, 38500 ‘ Get the IR data irDetectLeft = IN9 FREQOUT 2, 1, 38500 irDetectRight = IN0 IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN ‘ Blocked ahead! GOSUB Back_Up GOSUB Turn_Left GOSUB Turn_Left ELSEIF (irDetectLeft = 0) THEN ‘ Blocked only on left GOSUB Turn_Right ELSEIF (irDetectRight = 0) THEN ‘ Blocked only on right GOSUB Turn_Right ELSE GOSUB Forward_Pulse ‘ No obstacles, full speed ahead! ENDIF LOOP

  16. Using QTI sensors to follow lines

  17. Using QTI Sensors to Follow Lines Here is the schematic for the QTI line following sensors. These bounce IR off the floor which triggers a sensor. White tape reflects more than black so we can detect being over a line.

  18. Wiring diagram for QTI sensors We do not include the 10K resistors! Again, it will be crowded on the breadboard. You need to plan your wiring and pin use.

  19. Code for testing QTI sensors ' Boe-Bot detects white tape with 2 QTI modules. '{$STAMP BS2} '{$PBASIC 2.5}‘ Notice we are using the colon : to put several ‘ commands on a single line. This makes the code ‘ more compact but a bit harder to read. qtiLeft VAR Bit qtiRight VAR BitDO HIGH 5: PAUSE 1: qtiRight = IN4: INPUT 5 HIGH 7: PAUSE 1: qtiLeft = IN6: INPUT 7 DEBUG HOME, BIN1 qtiLeft, BIN1 qtiRight PAUSE 100 LOOP END

  20. This is the maze/obstacle course your robot will need to traverse on Monday in lab.

More Related