Presentation is loading. Please wait.

Presentation is loading. Please wait.

Software Tutorial 26 Sept 2009. Agenda Development Environment Brain Board API Sensors Basic Behaviour Control.

Similar presentations


Presentation on theme: "Software Tutorial 26 Sept 2009. Agenda Development Environment Brain Board API Sensors Basic Behaviour Control."— 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 LocalizationCognition 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 Example Code 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 } Ignores lines Prioritizes ATTACK over LINE Hardcoded, unchanging behaviour

19 Example State Diagram Search Attack Avoid Line

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

21 Example Code 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: counter1 = 0 if (something_on_sensors) state = ATTACK else if counter1 < 10 drive_back else if counter1 < 20 turn_around else state = SEARCH } Allows transition to attack at any point Sequenced behaviour within state Global variable

22 Questions? Me: James (jdservos@uwaterloo.ca)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 = a 1 e -a 0 x y = a 1 ln(x) + a 0 y = a 1 x -a 0 y = a 1 /x + a 0 Fastest to compute All models have a decent fit

27 Example Data Analog ValueActual Distance [cm] 6144 4516 2668 28710 20512 15414 18416 11318 12320 12322 11324 8226 7228 8230

28 Fitting Curve y = a 1 /x + a 0 Can find a 1,a 0 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_MULT6000 #define ADx_ADD5 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


Download ppt "Software Tutorial 26 Sept 2009. Agenda Development Environment Brain Board API Sensors Basic Behaviour Control."

Similar presentations


Ads by Google