Spring 2014, ECE 4180 project, Georgia Institute of Technolgoy. This is the human driver (RF controller) program for the Robotics Cat and Mouse program.
Dependencies: ADXL345_I2C_NEST HMC6352 IMUfilter ITG3200_NEST USBHost mbed-rtos mbed
Fork of Project by
AI.cpp@5:210cd333f770, 2014-04-30 (annotated)
- Committer:
- Strikewolf
- Date:
- Wed Apr 30 05:53:51 2014 +0000
- Revision:
- 5:210cd333f770
- Child:
- 6:3fb9f96765f6
works without any motors
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Strikewolf | 5:210cd333f770 | 1 | #include "mbed.h" |
Strikewolf | 5:210cd333f770 | 2 | #include "rtos.h" |
Strikewolf | 5:210cd333f770 | 3 | #include "IMU_RPY.h" |
Strikewolf | 5:210cd333f770 | 4 | #include "GameCode.h" |
Strikewolf | 5:210cd333f770 | 5 | #include "AIPosition.h" |
Strikewolf | 5:210cd333f770 | 6 | #include "AIControl.h" |
Strikewolf | 5:210cd333f770 | 7 | |
Strikewolf | 5:210cd333f770 | 8 | InterruptIn sw(p30); |
Strikewolf | 5:210cd333f770 | 9 | |
Strikewolf | 5:210cd333f770 | 10 | void StopISR() |
Strikewolf | 5:210cd333f770 | 11 | { |
Strikewolf | 5:210cd333f770 | 12 | rightMotorPWM = 0; |
Strikewolf | 5:210cd333f770 | 13 | leftMotorPWM = 0; |
Strikewolf | 5:210cd333f770 | 14 | exit(1); |
Strikewolf | 5:210cd333f770 | 15 | } |
Strikewolf | 5:210cd333f770 | 16 | |
Strikewolf | 5:210cd333f770 | 17 | int main() |
Strikewolf | 5:210cd333f770 | 18 | { |
Strikewolf | 5:210cd333f770 | 19 | pc.printf("\n\rStartup...\r\n"); |
Strikewolf | 5:210cd333f770 | 20 | |
Strikewolf | 5:210cd333f770 | 21 | //Emergency stop mechanism |
Strikewolf | 5:210cd333f770 | 22 | sw.rise(&StopISR); |
Strikewolf | 5:210cd333f770 | 23 | |
Strikewolf | 5:210cd333f770 | 24 | //Reset xbee |
Strikewolf | 5:210cd333f770 | 25 | pc.printf("Resetting XBee...\r\n"); |
Strikewolf | 5:210cd333f770 | 26 | rst1 = 0; |
Strikewolf | 5:210cd333f770 | 27 | wait_us(1); |
Strikewolf | 5:210cd333f770 | 28 | rst1 = 1; |
Strikewolf | 5:210cd333f770 | 29 | wait_us(1); |
Strikewolf | 5:210cd333f770 | 30 | |
Strikewolf | 5:210cd333f770 | 31 | //Initialize IMU and filter |
Strikewolf | 5:210cd333f770 | 32 | pc.printf("Initializing IMU...\r\n"); |
Strikewolf | 5:210cd333f770 | 33 | imuFilter.reset(); |
Strikewolf | 5:210cd333f770 | 34 | rpy_init(); |
Strikewolf | 5:210cd333f770 | 35 | |
Strikewolf | 5:210cd333f770 | 36 | // start positioning system |
Strikewolf | 5:210cd333f770 | 37 | pc.printf("Starting Positioning System...\n\r"); |
Strikewolf | 5:210cd333f770 | 38 | Thread position(PositionSystemMain, NULL, osPriorityRealtime, 256 * 4); |
Strikewolf | 5:210cd333f770 | 39 | wait(3); // wait for the mouse sensor to boot up |
Strikewolf | 5:210cd333f770 | 40 | |
Strikewolf | 5:210cd333f770 | 41 | // get away from user before starting game |
Strikewolf | 5:210cd333f770 | 42 | pc.printf("Getting head start (straight)...\n\r"); |
Strikewolf | 5:210cd333f770 | 43 | wait(5); |
Strikewolf | 5:210cd333f770 | 44 | // gyroDriveStraight(0.7, false, 10000); |
Strikewolf | 5:210cd333f770 | 45 | // pc.printf("Getting head start (turn right)...\n\r"); |
Strikewolf | 5:210cd333f770 | 46 | // centerTurnRight(90); |
Strikewolf | 5:210cd333f770 | 47 | |
Strikewolf | 5:210cd333f770 | 48 | // bursts of 10 seconds for driving straight |
Strikewolf | 5:210cd333f770 | 49 | pc.printf("Running!\r\n"); |
Strikewolf | 5:210cd333f770 | 50 | while(!gameOver) { |
Strikewolf | 5:210cd333f770 | 51 | gyroDriveStraight(0.7, true, 10000); |
Strikewolf | 5:210cd333f770 | 52 | } |
Strikewolf | 5:210cd333f770 | 53 | } |