1 / 32

Software Tutorial

Software Tutorial. 26 Sept 2009. Agenda. Development Environment Brain Board API Sensors Basic Behaviour Control. MPLAB/C18. MPLAB: IDE, free download from microchip.com C18: C compiler for PIC microcontrollers, also from microchip.com. MPLAB IDE. Brain Board Capabilities. PIC18F4580

sheila
Download Presentation

Software Tutorial

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. Software Tutorial 26 Sept 2009

  2. Agenda • Development Environment • Brain Board API • Sensors • Basic Behaviour Control

  3. MPLAB/C18 • MPLAB: IDE, free download from microchip.com • C18: C compiler for PIC microcontrollers, also from microchip.com

  4. MPLAB IDE

  5. Brain Board Capabilities • PIC18F4580 • 32KB program memory, 16K instructions • 1536 B SRAM • 256 B EEPROM • Board • 2 independent 5A motor drivers • 6 Analog inputs (10-bit) • 4 LEDs

  6. API • main.c: Master loop, setup functions • brain.c: Functions called by master loop • control.c: I/O filtering • utilities.c: String output, delay function

  7. API • sensor_val[0-5] automatically updated • Set motor1_speed, motor2_speed to a value in [-100,100] • Logic: brain.c/stateMachine() • Sensor conversion: control.c/readDist()

  8. Sensors • IR rangefinders • Sharp GP2D120 (4-30 cm) • IR line sensors • QRD1114

  9. Sharp IR Rangefinders • Pros • Low cost, low power, low mass • Sensor emissions are at speed of light • Divergence is not too bad • Cons • Other IR sources can interfere (sun, other sensors) • Surface properties (absorption/reflection/transmission)

  10. Sharp IR Rangefinders

  11. Line Sensor Circuit

  12. Behaviour Control • Deliberative Control • “Traditional approach”, tends to use brute force • Better at being goal-directed • Path planning, localization, “AI” • Reactive Control • Freeform, attempts to mirror nature • Roomba vacuum, “BEAM” robotics

  13. Deliberative Control Localization Cognition Perception Motion Control

  14. Reactive Control React Perception Motion Control

  15. Finite State Machines • Easy to implement • Easy to debug

  16. Finite State Machines • Exhibits different behaviour depending on the state • “State” is general description of behaviour • Explore/Recharge/Hide • One state at a time • “State transitions” are defined

  17. Example State Diagram Search Attack Avoid Line

  18. state = SEARCH while(true) { switch(state) case ATTACK: drive_straight if (nothing_on_sensors) state = SEARCH case SEARCH: drive_in_circles if (something_on_sensors) state = ATTACK else if (line_sensors_on) state = LINE case LINE: back_up state = SEARCH } Example Code Ignores lines Prioritizes ATTACK over LINE Hardcoded, unchanging behaviour

  19. Example State Diagram Search Attack Avoid Line

  20. Example State Diagram Search case LINE Reversing Attack Turning Augmented Finite State Machine (AFSM)

  21. state = SEARCH while(true) { switch(state) case ATTACK: drive_straight if (nothing_on_sensors) state = SEARCH case SEARCH: drive_in_circles if (something_on_sensors) state = ATTACK else if (line_sensors_on) state = LINE Example Code • case LINE: • counter1 = 0 • if (something_on_sensors) • state = ATTACK • else if counter1 < 10 • drive_back • else if counter1 < 20 • turn_around • else • state = SEARCH • } Global variable Allows transition to attack at any point Sequenced behaviour within state

  22. Questions? Me: James (jdservos@uwaterloo.ca)

  23. Appendix A Calibrating IR Rangefinders

  24. Response Graph • Important note: • Here, independent variable is distance • From a software perspective, independent variable is input voltage • Need to invert the function (in a swap x&y sense)

  25. Response Graph

  26. Possible Models • y = a1e-a0x • y = a1ln(x) + a0 • y = a1x-a0 • y = a1/x + a0 Fastest to compute All models have a decent fit

  27. Example Data

  28. Fitting Curve • y = a1/x + a0 • Can find a1,a0 in many ways • Invert matrix, iterative techniques • Software: MATLAB, Excel • Excel Worksheet available • Uses built-in Excel matrix functions • Can also use “Goal Seek” (not in all versions of Excel)

  29. Worksheet Input From debug output From measurement

  30. Worksheet Output Intermediate calculation Final result (also, these cells contain the solution equations) Fitted data for display on graph (solid line)

  31. Using Worksheet • Fill in analog value/distance pairs (bordered in red on sheet) • 14 pairs – take this amount of measurements or modify the sheet • Results are bordered in blue on sheet

  32. Integrating into API • In main.c/setup(): • Set sensor_type[i] to SENSOR_RANGE or SENSOR_LINE (depending on type) • In example code: for (i = 0; i < 3; i++) //first 4 inputs range sensors sensor_type[i] = SENSOR_RANGE; for (i = 3; i < 6; i++) //last 4 are line sensors sensor_type[i] = SENSOR_LINE; • In control.h: • For IR sensors, set each sensor’s constants to Excel-computed values #define ADx_MULT 6000 #define ADx_ADD 5 • If the i-th sensor is a line, just check: • sensor_val[i] == ON_LINE or sensor_val[i] == OFF_LINE • Otherwise, sensor_val[i] contains the distance in cm

More Related