Clare Coleman / Mbed 2 deprecated UTCSBootcamp

Dependencies:   MMA8451Q mbed

Committer:
ccoleman
Date:
Fri Aug 23 16:21:47 2013 +0000
Revision:
8:eb1307992dd1
Parent:
6:4b101f051a1f
Um. Fixed sleep. Apparently I need more of that.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ccoleman 0:2010bcffbae0 1 #include "CarAPI.h"
ccoleman 6:4b101f051a1f 2 #include "Includes/CarBaseAPI.h"
ccoleman 0:2010bcffbae0 3
ccoleman 0:2010bcffbae0 4 /******************************** Init and Finish ********************************/
ccoleman 0:2010bcffbae0 5
ccoleman 0:2010bcffbae0 6 void init(){
ccoleman 0:2010bcffbae0 7 _initialize();
ccoleman 0:2010bcffbae0 8 }
ccoleman 0:2010bcffbae0 9
ccoleman 0:2010bcffbae0 10 void finish(){
ccoleman 0:2010bcffbae0 11 _finish();
ccoleman 0:2010bcffbae0 12 }
ccoleman 0:2010bcffbae0 13
ccoleman 0:2010bcffbae0 14 /******************************** Wheels and Motor ********************************/
ccoleman 0:2010bcffbae0 15
ccoleman 0:2010bcffbae0 16 void turn(float turnAngle){
ccoleman 0:2010bcffbae0 17 turn(0,turnAngle);
ccoleman 0:2010bcffbae0 18 }
ccoleman 0:2010bcffbae0 19
ccoleman 0:2010bcffbae0 20 void move(float power, float seconds){
ccoleman 0:2010bcffbae0 21 move (power,power,seconds);
ccoleman 0:2010bcffbae0 22 }
ccoleman 0:2010bcffbae0 23
ccoleman 0:2010bcffbae0 24 void move(float leftWheelPower,float rightWheelPower, float seconds){
ccoleman 4:4233d072b5af 25 if(debug) utrace("move(%f,%f,%f)\r\n",leftWheelPower,rightWheelPower,seconds);
ccoleman 0:2010bcffbae0 26 TFC_SetMotorPWM(leftWheelPower,rightWheelPower); // power for n seconds with both wheels the same power
ccoleman 0:2010bcffbae0 27 wait(seconds);
ccoleman 0:2010bcffbae0 28 TFC_SetMotorPWM(0,0); // turn off power to both wheels
ccoleman 0:2010bcffbae0 29 wait(0.05); //need a wait to register or sebsequent calls to this method won't spin the wheel; hardware can't detect instaneous input?
ccoleman 0:2010bcffbae0 30 }
ccoleman 0:2010bcffbae0 31
ccoleman 0:2010bcffbae0 32 void parkingBrake(){
ccoleman 4:4233d072b5af 33 if(debug) utrace("parkingBrake()\r\n");
ccoleman 0:2010bcffbae0 34 TFC_SetMotorPWM(0.1,0.1); //slight spinning of wheel
ccoleman 0:2010bcffbae0 35 wait(0.1);
ccoleman 0:2010bcffbae0 36 }
ccoleman 0:2010bcffbae0 37
ccoleman 4:4233d072b5af 38 void sleep(float seconds){
ccoleman 4:4233d072b5af 39 if(debug) utrace("sleep(%f)\r\n",seconds);
ccoleman 8:eb1307992dd1 40 wait(seconds);
ccoleman 4:4233d072b5af 41 }
ccoleman 3:1afe0cfab2d1 42
ccoleman 4:4233d072b5af 43
ccoleman 4:4233d072b5af 44 /******************************** INPUTS AND OUTPUTS ********************************/
ccoleman 5:8dde418f0d1e 45
ccoleman 0:2010bcffbae0 46 bool checkIsCrashing(){
ccoleman 4:4233d072b5af 47 if(debug) utrace("checkIsCrashing()\r\n");
ccoleman 0:2010bcffbae0 48 return abs(accelerometer.getAccX()) >= crashSensitivity;
ccoleman 0:2010bcffbae0 49 }
ccoleman 0:2010bcffbae0 50
ccoleman 4:4233d072b5af 51 bool isStopped()
ccoleman 4:4233d072b5af 52 {
ccoleman 4:4233d072b5af 53 double x = accelerometer.getAccX();
ccoleman 4:4233d072b5af 54 double y = accelerometer.getAccY();
ccoleman 4:4233d072b5af 55 double z = accelerometer.getAccZ();
ccoleman 4:4233d072b5af 56 double calAcc = sqrt(x*x + y*y + z*z);
ccoleman 4:4233d072b5af 57 if (calAcc < stopSensitivity)
ccoleman 4:4233d072b5af 58 return 1;
ccoleman 4:4233d072b5af 59 return 0;
ccoleman 4:4233d072b5af 60 }
ccoleman 4:4233d072b5af 61
ccoleman 0:2010bcffbae0 62 float lineDirection(){
ccoleman 0:2010bcffbae0 63 return 0;
ccoleman 0:2010bcffbae0 64 }
ccoleman 0:2010bcffbae0 65
ccoleman 0:2010bcffbae0 66 void toggleLED0(){
ccoleman 4:4233d072b5af 67 if(debug) utrace("toggleLED0()\r\n");
ccoleman 0:2010bcffbae0 68 TFC_BAT_LED0_TOGGLE;
ccoleman 0:2010bcffbae0 69 }
ccoleman 0:2010bcffbae0 70
ccoleman 0:2010bcffbae0 71 void toggleLED1(){
ccoleman 4:4233d072b5af 72 if(debug) utrace("toggleLED1()\r\n");
ccoleman 0:2010bcffbae0 73 TFC_BAT_LED1_TOGGLE;
ccoleman 0:2010bcffbae0 74 }
ccoleman 0:2010bcffbae0 75
ccoleman 0:2010bcffbae0 76 void toggleLED2(){
ccoleman 4:4233d072b5af 77 if(debug) utrace("toggleLED2()\r\n");
ccoleman 0:2010bcffbae0 78 TFC_BAT_LED2_TOGGLE;
ccoleman 0:2010bcffbae0 79 }
ccoleman 0:2010bcffbae0 80
ccoleman 0:2010bcffbae0 81 void toggleLED3(){
ccoleman 4:4233d072b5af 82 if(debug) utrace("toggleLED3()\r\n");
ccoleman 0:2010bcffbae0 83 TFC_BAT_LED3_TOGGLE;
ccoleman 0:2010bcffbae0 84 }
ccoleman 0:2010bcffbae0 85
ccoleman 0:2010bcffbae0 86 bool isButtonBPressed(){
ccoleman 4:4233d072b5af 87 if(debug) utrace("isButtonBPressed()=%d\r\n",TFC_PUSH_BUTTON_1_PRESSED);
ccoleman 0:2010bcffbae0 88 return TFC_PUSH_BUTTON_1_PRESSED;
ccoleman 0:2010bcffbae0 89 }
ccoleman 0:2010bcffbae0 90
ccoleman 0:2010bcffbae0 91 float getPot0(){
ccoleman 4:4233d072b5af 92 if(debug) utrace("getPot0()= %f\r\n", TFC_ReadPot(0));
ccoleman 0:2010bcffbae0 93 return TFC_ReadPot(0);
ccoleman 0:2010bcffbae0 94 }
ccoleman 0:2010bcffbae0 95
ccoleman 0:2010bcffbae0 96 float getPot1(){
ccoleman 4:4233d072b5af 97 if(debug) utrace("getPot1()= %f\r\n", TFC_ReadPot(1));
ccoleman 0:2010bcffbae0 98 return TFC_ReadPot(1);
ccoleman 0:2010bcffbae0 99 }
ccoleman 0:2010bcffbae0 100
ccoleman 0:2010bcffbae0 101 float batteryLife(){
ccoleman 4:4233d072b5af 102 if(debug) utrace("batteryLife()= %f\r\n", TFC_ReadBatteryVoltage());
ccoleman 0:2010bcffbae0 103 return TFC_ReadBatteryVoltage();
ccoleman 0:2010bcffbae0 104 }
ccoleman 0:2010bcffbae0 105
ccoleman 0:2010bcffbae0 106 /******************************** Changing Variables ********************************/
ccoleman 0:2010bcffbae0 107
ccoleman 0:2010bcffbae0 108 void setOffset(float _turnOffset){
ccoleman 4:4233d072b5af 109 if(debug) utrace("setOffset(%f)\r\n", _turnOffset);
ccoleman 0:2010bcffbae0 110 turnOffset = _turnOffset;
ccoleman 0:2010bcffbae0 111 }
ccoleman 0:2010bcffbae0 112
ccoleman 0:2010bcffbae0 113 float getOffset(){
ccoleman 4:4233d072b5af 114 if(debug) utrace("getOffset()= %f\r\n", turnOffset);
ccoleman 0:2010bcffbae0 115 return turnOffset;
ccoleman 0:2010bcffbae0 116 }
ccoleman 0:2010bcffbae0 117
ccoleman 0:2010bcffbae0 118 void setCrashSensitivity(float _sensitivity){
ccoleman 4:4233d072b5af 119 if(debug) utrace("setCrashSensitivity(%f)\r\n", _sensitivity);
ccoleman 0:2010bcffbae0 120 crashSensitivity = _sensitivity;
ccoleman 0:2010bcffbae0 121 }
ccoleman 0:2010bcffbae0 122
ccoleman 0:2010bcffbae0 123 float getCrashSensitivity(){
ccoleman 4:4233d072b5af 124 if(debug) utrace("getCrashSensitivity()= %f\r\n", crashSensitivity);
ccoleman 0:2010bcffbae0 125 return crashSensitivity;
ccoleman 0:2010bcffbae0 126 }
ccoleman 0:2010bcffbae0 127
ccoleman 4:4233d072b5af 128 void setStopSensitivity(float _sensitivity){
ccoleman 4:4233d072b5af 129 if(debug) utrace("setStopSensitivity(%f)\r\n", _sensitivity);
ccoleman 4:4233d072b5af 130 stopSensitivity = _sensitivity;
ccoleman 4:4233d072b5af 131 }
ccoleman 4:4233d072b5af 132
ccoleman 4:4233d072b5af 133 float getStopSensitivity(){
ccoleman 4:4233d072b5af 134 if(debug) utrace("getStopSensitivity()= %f\r\n", stopSensitivity);
ccoleman 4:4233d072b5af 135 return stopSensitivity;
ccoleman 4:4233d072b5af 136 }
ccoleman 4:4233d072b5af 137
ccoleman 0:2010bcffbae0 138 void setDebug(bool _debug){
ccoleman 4:4233d072b5af 139 if(debug) utrace("setDebug()= %d\r\n", _debug);
ccoleman 0:2010bcffbae0 140 debug = _debug;
ccoleman 0:2010bcffbae0 141 }