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.
Dependencies: BridgeDriver FrontPanelButtons MCP23017 SDFileSystem TextLCD mbed
Diff: Devices/Motor.cpp
- Revision:
- 11:bc9cd2869f95
- Parent:
- 10:e8db892fbc52
- Child:
- 14:953820302fb7
--- a/Devices/Motor.cpp Wed Sep 24 22:54:36 2014 +0000
+++ b/Devices/Motor.cpp Wed Oct 01 18:11:38 2014 +0000
@@ -79,6 +79,10 @@
return 0; //Function operated successfully but doesn't return a value
bridges.forceBrake(getMotor());
+
+ //Record the settings for Pause and Resume
+ currDir = 0;
+ currSpeed = 0;
}
@@ -131,6 +135,10 @@
return 0; //Function operated successfully but doesn't return a value
bridges.drive(getMotor(), dirValue, speedValue); //Turn on the Motor
+
+ //Record the settings for Pause and Resume
+ currDir = dirValue;
+ currSpeed = speedValue;
}
@@ -164,75 +172,22 @@
//For stopping the entire system if an error occurs, can be called from main
int Motor::off(void){
bridges.drive(getMotor(), 0, 0); //Turn off the Motor
+
+ //Record the settings for Pause and Resume, and exit
+ currDir = 0;
+ currSpeed = 0;
return 0;
}
-/*
-int Motor::enableBrake(){
-
- if (lineData.numWords != 4){
- //Error Check, incorrect number of parameter, error out
- return 0;
- }
-
- //Initialize and Convert Parameters
- char *enable = lineData.word[2];
- int enableValue = atoi(enable);
-
- //If the atoi returned anything besides 0, it worked properly
- if (enableValue)
- bridges.enableBraking(getMotor(), enableValue);
- else{
- //Error Check, incorrect number of parameter, error out
- return 0;
- }
-
- return 1;
+//Stop the motor without changing the previous known settings, so that it will be saved on resume
+int Motor::pause(void){
+ bridges.drive(getMotor(), 0, 0); //Turn off the Motor
+ return 0;
}
-int Motor::forceBrake(){
-
- if (lineData.numWords != 3){
- //Error Check, incorrect number of parameter, error out
- return 0;
- }
-
- bridges.forceBrake(getMotor());
+//Resume the motor using its previously known settings
+int Motor::resume(void){
+ bridges.drive(getMotor(), this->currDir, this->currSpeed); //Resume Motor from it's last known state
+ return 0;
}
-
-int Motor::drive(){
-
- if (lineData.numWords != 4){
- //Error Check, incorrect number of parameter, error out
- return 0;
- }
-
- //Initialize Parameters
- char *speed = lineData.word[2];
- char *dir = lineData.word[3];
-
- //Initialize Convertion Variables if needed
- float speedValue;
- int dirValue = 0;
-
- //Convert string to usable values
- //NOTE both atof and atoi functions return 0 if no valid conversion could be performed
- speedValue = atof(speed) / 100;
-
- if (speedValue <= 0)
- return 0; //Error Out because a value gives no functionality or is wrong
-
- if (strncmp(dir,"CC", 2) == 0 || strncmp(dir,"cc", 2) == 0)
- dirValue = -1; //Turn Clockwise
- else if (strncmp(dir,"C", 1) == 0 || strncmp(dir,"c", 1) == 0)
- dirValue = 1; //Turn CounterClockwise
- else
- return 0; //Error Out since the parameter is incorrect
-
- bridges.drive(getMotor(), dirValue, speedValue); //Turn on the Motor
-}
-*/
-
-
-
\ No newline at end of file