Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: CarAPI.cpp
- Revision:
- 4:4233d072b5af
- Parent:
- 3:1afe0cfab2d1
- Child:
- 5:8dde418f0d1e
--- a/CarAPI.cpp Thu Aug 22 21:52:21 2013 +0000
+++ b/CarAPI.cpp Fri Aug 23 00:38:23 2013 +0000
@@ -13,102 +13,156 @@
/******************************** Wheels and Motor ********************************/
+/* turn the car. turnAngle should be between [-1,1] */
void turn(float turnAngle){
turn(0,turnAngle);
}
+/** move forward with the given power, turn angle, for a specified time */
void move(float power, float seconds){
move (power,power,seconds);
}
+/** move forward with the given powers for each wheel, turn angle, for a specified time */
void move(float leftWheelPower,float rightWheelPower, float seconds){
- if(debug) pc.printf("move(%f,%f,%f)",leftWheelPower,rightWheelPower,seconds);
+ if(debug) utrace("move(%f,%f,%f)\r\n",leftWheelPower,rightWheelPower,seconds);
TFC_SetMotorPWM(leftWheelPower,rightWheelPower); // power for n seconds with both wheels the same power
wait(seconds);
TFC_SetMotorPWM(0,0); // turn off power to both wheels
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?
}
+/** lock the wheels*/
void parkingBrake(){
- if(debug) pc.printf("parkingBrake()");
+ if(debug) utrace("parkingBrake()\r\n");
TFC_SetMotorPWM(0.1,0.1); //slight spinning of wheel
wait(0.1);
}
-/******************************** INPUTS AND OUTPUTS ********************************/
+/** do nothing for the specified time */
+void sleep(float seconds){
+ if(debug) utrace("sleep(%f)\r\n",seconds);
+}
+
+/******************************** INPUTS AND OUTPUTS ********************************/
+/** check to see if the car is crashing into something */
bool checkIsCrashing(){
- if(debug) pc.printf("checkIsCrashing()");
+ if(debug) utrace("checkIsCrashing()\r\n");
return abs(accelerometer.getAccX()) >= crashSensitivity;
}
+/** check to see if the car has stopped */
+bool isStopped()
+{
+ double x = accelerometer.getAccX();
+ double y = accelerometer.getAccY();
+ double z = accelerometer.getAccZ();
+ double calAcc = sqrt(x*x + y*y + z*z);
+ if (calAcc < stopSensitivity)
+ return 1;
+ return 0;
+}
+
+
+
+/** Return the line direction
+ line to the left of center. return [-1,0
+ line to the right of center. return (0,1]
+ line in center. return 0
+*/
float lineDirection(){
return 0;
}
+/* toggle led 0 */
void toggleLED0(){
- if(debug) pc.printf("toggleLED0()");
+ if(debug) utrace("toggleLED0()\r\n");
TFC_BAT_LED0_TOGGLE;
}
+/* toggle led 1 */
void toggleLED1(){
- if(debug) pc.printf("toggleLED1()");
+ if(debug) utrace("toggleLED1()\r\n");
TFC_BAT_LED1_TOGGLE;
}
+/* toggle led 2 */
void toggleLED2(){
- if(debug) pc.printf("toggleLED2()");
+ if(debug) utrace("toggleLED2()\r\n");
TFC_BAT_LED2_TOGGLE;
}
+/* toggle led 3 */
void toggleLED3(){
- if(debug) pc.printf("toggleLED3()");
+ if(debug) utrace("toggleLED3()\r\n");
TFC_BAT_LED3_TOGGLE;
}
+/** is Button B pressed */
bool isButtonBPressed(){
- if(debug) pc.printf("isButtonBPressed()=",TFC_PUSH_BUTTON_1_PRESSED);
+ if(debug) utrace("isButtonBPressed()=%d\r\n",TFC_PUSH_BUTTON_1_PRESSED);
return TFC_PUSH_BUTTON_1_PRESSED;
}
+/** read Potentiometer 0. returns [-1,1] */
float getPot0(){
- if(debug) pc.printf("getPot0()= %f", TFC_ReadPot(0));
+ if(debug) utrace("getPot0()= %f\r\n", TFC_ReadPot(0));
return TFC_ReadPot(0);
}
+/** read Potentiometer 1. returns [-1,1] */
float getPot1(){
- if(debug) pc.printf("getPot1()= %f", TFC_ReadPot(1));
+ if(debug) utrace("getPot1()= %f\r\n", TFC_ReadPot(1));
return TFC_ReadPot(1);
}
+/** How much batter remains. returns [0,1] */
float batteryLife(){
- if(debug) pc.printf("batteryLife()= %f", TFC_ReadBatteryVoltage());
+ if(debug) utrace("batteryLife()= %f\r\n", TFC_ReadBatteryVoltage());
return TFC_ReadBatteryVoltage();
}
/******************************** Changing Variables ********************************/
+/** set the base turn offset*/
void setOffset(float _turnOffset){
- if(debug) pc.printf("setOffset()= %f", _turnOffset);
+ if(debug) utrace("setOffset(%f)\r\n", _turnOffset);
turnOffset = _turnOffset;
}
+/** get the base turn offset */
float getOffset(){
- if(debug) pc.printf("getOffset()= %f", turnOffset);
+ if(debug) utrace("getOffset()= %f\r\n", turnOffset);
return turnOffset;
}
+/** set the base crash sensitivity*/
void setCrashSensitivity(float _sensitivity){
- if(debug) pc.printf("setCrashSensitivity()= %f", _sensitivity);
+ if(debug) utrace("setCrashSensitivity(%f)\r\n", _sensitivity);
crashSensitivity = _sensitivity;
}
+/** return the crash sensitivity */
float getCrashSensitivity(){
- if(debug) pc.printf("getCrashSensitivity()= %f", crashSensitivity);
+ if(debug) utrace("getCrashSensitivity()= %f\r\n", crashSensitivity);
return crashSensitivity;
}
+/** set the base stop sensitivity*/
+void setStopSensitivity(float _sensitivity){
+ if(debug) utrace("setStopSensitivity(%f)\r\n", _sensitivity);
+ stopSensitivity = _sensitivity;
+}
+
+/** return the stop sensitivity */
+float getStopSensitivity(){
+ if(debug) utrace("getStopSensitivity()= %f\r\n", stopSensitivity);
+ return stopSensitivity;
+}
+
+/** turn on debugging*/
void setDebug(bool _debug){
- if(debug) pc.printf("setDebug()= %d", _debug);
+ if(debug) utrace("setDebug()= %d\r\n", _debug);
debug = _debug;
}
\ No newline at end of file
