Robot Programming Tips

Document Sample
Robot Programming Tips Powered By Docstoc
					                                                     Engineering H193 - Team Project




                  Robot Programming Tips


                            Week 4 Day 2

                 By Matt Gates and James Beams



Spring Quarter        Gateway Engineering Education Coalition                 P. 1
                                                  Engineering H193 - Team Project



                 Robot Programming Tips




Spring Quarter     Gateway Engineering Education Coalition                 P. 2
                                                     Engineering H193 - Team Project



                 Limitations of the Handy Board

• Limited memory (16K available for program code)
• Limited CPU speed
• Very slow floating point (no floating point
  hardware)
• Limited I/O (LCD screen, 7 analog, 8 digital ports)

• Strategy: Code must be small, fast, and make
  efficient use of the resources you have.



Spring Quarter        Gateway Engineering Education Coalition                 P. 3
                                                   Engineering H193 - Team Project



                 Limitations of the System

• Controlling a mechanical system is much
  different than controlling a computer!
   – Why? System will never run the same way
     twice!
   – System runs in real time, independent of your
     program.
• You must constantly monitor the system and
  ensure that what you want to happen is actually
  happening.
   – Test, test, and test some more!!!

Spring Quarter      Gateway Engineering Education Coalition                 P. 4
                                                     Engineering H193 - Team Project



                 Strategies I: What NOT To Do

• DO NOT write one large main ( )
• DO NOT write code without error checking
• DO NOT assume your code will work right
• DO NOT use lots of memory or complex
  algorithms
• DO NOT wait until the last minute to test your
  code




Spring Quarter        Gateway Engineering Education Coalition                 P. 5
                                                      Engineering H193 - Team Project



                 Strategies II: Maintainable Code

• Break your code into small segments (functions)
  that perform specific, simple tasks.
   – Example: motors_half_speed ( )
• Use symbolic constants (#define) instead of
  literals.
   – “motor (LEFT_SIDE, FULL_POWER)”
   – NOT: “motor (1, 100)”
• Makes it easier to update your code if you make
  changes to the robot design or your goals.


Spring Quarter         Gateway Engineering Education Coalition                 P. 6
                                                     Engineering H193 - Team Project



                 Strategies III: Getting Around

• The most difficult part of your task will be getting
  from Point A to Point B.
   – Driving straight
   – Turning
   – Avoiding obstacles




Spring Quarter        Gateway Engineering Education Coalition                 P. 7
                                                     Engineering H193 - Team Project



                 Strategies III: Getting Around

• You should spend time developing and testing a
  routine that allows you to move around reliably.
   – Use shaft encoder data to keep wheels @
     same RPM.
   – Shaft encoders can also help in turning.
   – Have adequate bump sensors and intelligent
     responses.




Spring Quarter        Gateway Engineering Education Coalition                 P. 8
                                                  Engineering H193 - Team Project



                 Pseudo code Example #1

• The following pseudo code example is for a
  „drive_straight‟ function for a specific distance to
  be traveled and which corrects for uneven motor
  speeds.




Spring Quarter     Gateway Engineering Education Coalition                 P. 9
                                   Engineering H193 - Team Project




•




    Gateway Engineering Education Coalition
                                                     Engineering H193 - Team Project



                 Strategies IV: Break up Course

• The course can be handled more easily if you
  break it up into sections or tasks.
   – Ex: Determine object values, navigate to and
     pick up object, navigate and drop off object.
• Write code to handle each section separately.
   – Now you can test parts of the course
     individually.
   – Use the knob to select what section of code to
     execute.


Spring Quarter        Gateway Engineering Education Coalition                P. 11
                                                  Engineering H193 - Team Project



                 Pseudo code Example #2

• The following pseudo code example breaks the
  course (for that year) into six routines.




Spring Quarter     Gateway Engineering Education Coalition                P. 12
                                                Engineering H193 - Team Project




Spring Quarter   Gateway Engineering Education Coalition                P. 13
                                                    Engineering H193 - Team Project



                 Strategies V: Multithreading

• IC can run more than one functional “thread” at
  once.
   – Useful to perform background monitoring
     while doing main tasks.
   – Ex: Run “drive straight” code to make
     corrections to motor power while driving.




Spring Quarter       Gateway Engineering Education Coalition                P. 14
                                                    Engineering H193 - Team Project



                 Strategies V: Multithreading

• The more threads running, the more CPU
  resources used.
   – Can hurt IR reception, shaft encoder counts,
     etc.
   – Should keep number of threads small.
• See IC documentation on start_process () for
  more info.




Spring Quarter       Gateway Engineering Education Coalition                P. 15
                                                 Engineering H193 - Team Project



                 Strategies VI: Testing
• Thorough testing is essential!
• Tips:
   – Begin by testing individual course sections,
     then combine until you can do the whole
     course.
   – Use the LCD screen to output useful values
     (ex. shaft encoder ticks, motor power, course
     side, IR output).
   – Make sure your robot will work even if the
     battery charge is low.
   – Don‟t stop testing until the competition is over!
Spring Quarter    Gateway Engineering Education Coalition                P. 16
                                                            Engineering H193 - Team Project



   Grade Sheet for Pseudo Code / Flow Chart
                                  Item                                 Points


                 Cover Page                                              2
                 Introduction / Purpose                                  2
                 Logic / Illustration / Description                     14
                 Modular by Function                                     4
                 Completeness                                            4
                 Format / Clarity / Neatness                             4




                     TOTAL                                              30

Spring Quarter               Gateway Engineering Education Coalition                P. 17