This is some awesome robot code

Dependencies:   mbed-rtos mbed QEI

Fork of ICRSEurobot13 by Thomas Branch

Committer:
madcowswe
Date:
Wed Apr 10 02:01:51 2013 +0000
Revision:
25:b16f1045108f
Parent:
24:50805ef8c499
Parent:
22:6e3218cf75f8
Child:
26:7cb3a21d9a2e
Child:
30:791739422122
Motion and motor works, but needs tuning

Who changed what in which revision?

UserRevisionLine numberNew contents of line
madcowswe 16:52250d8d8fce 1
madcowswe 20:70d651156779 2 #ifndef GLOBALS_H
madcowswe 20:70d651156779 3 #define GLOBALS_H
madcowswe 20:70d651156779 4
madcowswe 20:70d651156779 5 #include "mbed.h"
madcowswe 20:70d651156779 6
madcowswe 20:70d651156779 7 const float KALMAN_PREDICT_PERIOD = 0.05; //seconds
madcowswe 20:70d651156779 8
madcowswe 20:70d651156779 9 #define ENABLE_GLOBAL_ENCODERS
madcowswe 20:70d651156779 10
madcowswe 20:70d651156779 11 const float ENCODER_M_PER_TICK = 0.00084; //TODO: measure this!!
madcowswe 20:70d651156779 12 const float ENCODER_WHEELBASE = 0.068; //TODO: measrue this!!
madcowswe 20:70d651156779 13 const float TURRET_FWD_PLACEMENT = 0.042;
madcowswe 20:70d651156779 14
madcowswe 20:70d651156779 15 //Robot movement constants
madcowswe 20:70d651156779 16 const float fwdvarperunit = 0.01; //1 std dev = 7% //TODO: measrue this!!
madcowswe 20:70d651156779 17 const float varperang = 0.01; //around 1 degree stddev per 180 turn //TODO: measrue this!!
madcowswe 20:70d651156779 18 const float xyvarpertime = 0.0005; //(very poorly) accounts for hitting things
madcowswe 20:70d651156779 19 const float angvarpertime = 0.001;
madcowswe 20:70d651156779 20
madcowswe 22:6e3218cf75f8 21 extern Timer SystemTime;
madcowswe 22:6e3218cf75f8 22
madcowswe 25:b16f1045108f 23 const float MOTORCONTROLLER_FILTER_K = 0.5;// TODO: tune this
madcowswe 22:6e3218cf75f8 24 const float MOTOR_MAX_POWER = 0.4f;
madcowswe 22:6e3218cf75f8 25
madcowswe 20:70d651156779 26 /*
madcowswe 20:70d651156779 27 PINOUT Sensors
madcowswe 20:70d651156779 28 5: RF:SDI
madcowswe 20:70d651156779 29 6 SDO
madcowswe 20:70d651156779 30 7 SCK
madcowswe 20:70d651156779 31 8 NCS
madcowswe 20:70d651156779 32 9 NIRQ
madcowswe 20:70d651156779 33 10-15 6 echo pins
madcowswe 20:70d651156779 34 16 trig
madcowswe 20:70d651156779 35 17 IRin
madcowswe 20:70d651156779 36 18-20 unused
madcowswe 20:70d651156779 37 21 stepper step
madcowswe 20:70d651156779 38 22-27 unused
madcowswe 20:70d651156779 39 28 Serial TX
madcowswe 20:70d651156779 40 29-30 unused
madcowswe 20:70d651156779 41
madcowswe 20:70d651156779 42
madcowswe 20:70d651156779 43 PINOUT Main
madcowswe 20:70d651156779 44 5: Lower arm servo
madcowswe 20:70d651156779 45 6: Upper arm servo
madcowswe 20:70d651156779 46
madcowswe 20:70d651156779 47 14: Serial RX
madcowswe 20:70d651156779 48 15: Cake distance sensor
madcowswe 20:70d651156779 49 16: Fwd distance sensor
madcowswe 20:70d651156779 50
madcowswe 20:70d651156779 51 20: color sensor in
madcowswe 20:70d651156779 52 21-24: Motors PWM IN 1-4
madcowswe 20:70d651156779 53 25-26: Encoders
madcowswe 20:70d651156779 54 27-28: Encoders
madcowswe 20:70d651156779 55 29: Color sensor RED LED
madcowswe 20:70d651156779 56 30: Color sensor BLUE LED
madcowswe 20:70d651156779 57
madcowswe 20:70d651156779 58 */
madcowswe 20:70d651156779 59
madcowswe 20:70d651156779 60 const PinName P_SERVO_LOWER_ARM = p5;
madcowswe 20:70d651156779 61 const PinName P_SERVO_UPPER_ARM = p6;
madcowswe 20:70d651156779 62
madcowswe 20:70d651156779 63 const PinName P_SERIAL_RX = p14;
madcowswe 20:70d651156779 64 const PinName P_DISTANCE_SENSOR = p15;
madcowswe 20:70d651156779 65
madcowswe 20:70d651156779 66 const PinName P_COLOR_SENSOR_IN = p20;
madcowswe 20:70d651156779 67
madcowswe 25:b16f1045108f 68 const PinName P_MOT_LEFT_A = p21;
madcowswe 25:b16f1045108f 69 const PinName P_MOT_LEFT_B = p22;
madcowswe 25:b16f1045108f 70 const PinName P_MOT_RIGHT_A = p23;
madcowswe 25:b16f1045108f 71 const PinName P_MOT_RIGHT_B = p24;
madcowswe 20:70d651156779 72
madcowswe 25:b16f1045108f 73 const PinName P_ENC_RIGHT_A = p26;
madcowswe 25:b16f1045108f 74 const PinName P_ENC_RIGHT_B = p25;
madcowswe 25:b16f1045108f 75 const PinName P_ENC_LEFT_A = p27;
madcowswe 25:b16f1045108f 76 const PinName P_ENC_LEFT_B = p28;
madcowswe 20:70d651156779 77
madcowswe 20:70d651156779 78 const PinName P_COLOR_SENSOR_RED = p29;
madcowswe 20:70d651156779 79 const PinName P_COLOR_SENSOR_BLUE = p30;
madcowswe 20:70d651156779 80
madcowswe 20:70d651156779 81
madcowswe 20:70d651156779 82
madcowswe 20:70d651156779 83 //a type which is a pointer to a rtos thread function
madcowswe 20:70d651156779 84 typedef void (*tfuncptr_t)(void const *argument);
madcowswe 16:52250d8d8fce 85
madcowswe 16:52250d8d8fce 86 //Solving for sonar bias is done by entering the following into wolfram alpha
madcowswe 16:52250d8d8fce 87 //(a-f)^2 = x^2 + y^2; (b-f)^2 = (x-3)^2 + y^2; (c-f)^2 = (x-1.5)^2+(y-2)^2: solve for x,y,f
madcowswe 16:52250d8d8fce 88 //where a, b, c are the measured distances, and f is the bias
madcowswe 16:52250d8d8fce 89
madcowswe 19:4b993a9a156e 90 //const float sonartimebias = 0; // TODO: measure and stick in the coprocessor code
madcowswe 17:6263e90bf3ba 91
madcowswe 17:6263e90bf3ba 92 struct pos {
madcowswe 17:6263e90bf3ba 93 float x;
madcowswe 17:6263e90bf3ba 94 float y;
madcowswe 17:6263e90bf3ba 95 };
madcowswe 17:6263e90bf3ba 96
madcowswe 19:4b993a9a156e 97 extern pos beaconpos[3];
madcowswe 19:4b993a9a156e 98
madcowswe 20:70d651156779 99 const float PI = 3.14159265359;
madcowswe 20:70d651156779 100
rsavitski 24:50805ef8c499 101 typedef struct State
rsavitski 24:50805ef8c499 102 {
rsavitski 24:50805ef8c499 103 float x;
rsavitski 24:50805ef8c499 104 float y;
rsavitski 24:50805ef8c499 105 float theta;
rsavitski 24:50805ef8c499 106 } State;
rsavitski 24:50805ef8c499 107
rsavitski 24:50805ef8c499 108 typedef struct Waypoint
rsavitski 24:50805ef8c499 109 {
rsavitski 24:50805ef8c499 110 float x;
rsavitski 24:50805ef8c499 111 float y;
rsavitski 24:50805ef8c499 112 float theta;
rsavitski 24:50805ef8c499 113 float pos_threshold;
rsavitski 24:50805ef8c499 114 float angle_threshold;
rsavitski 24:50805ef8c499 115 } Waypoint;
rsavitski 24:50805ef8c499 116
rsavitski 24:50805ef8c499 117 //TODO: hack, move to AI layer
rsavitski 24:50805ef8c499 118 namespace AI
rsavitski 24:50805ef8c499 119 {
madcowswe 25:b16f1045108f 120 extern Waypoint* current_waypoint;
rsavitski 24:50805ef8c499 121 }
rsavitski 24:50805ef8c499 122
rsavitski 24:50805ef8c499 123
madcowswe 20:70d651156779 124 #endif //GLOBALS_H