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
Motor.cpp
- Committer:
- mehatfie
- Date:
- 2014-09-16
- Revision:
- 0:22618cf06f45
- Child:
- 2:3e7baa3e3fec
File content as of revision 0:22618cf06f45:
//#include "Motor.hpp" //#include "mbed.h" //#include "LocalPinNames.h" //#include "BridgeDriver.h" // ////Constructor //Motor::Motor(){ // /* // //Order of Line: Command, Local_Name, VOLTAGE_DRIVER, Channel(1,2,3,4,5,6,7,8) // if (lineData.numWords != 4){ // //Error Check, incorrect number of parameter, error out // //return 0; // }*/ // // char channel = *lineData.word[3]; //Parameter is a single character, so dereference the point to the word // // switch (channel){ // case 'A': // case 'a': // this->motor = BridgeDriver::MOTOR_A; // break; // case 'B': // case 'b': // this->motor = BridgeDriver::MOTOR_B; // break; // case 'C': // case 'c': // this->motor = BridgeDriver::MOTOR_C; // break; // case 'D': // case 'd': // this->motor = BridgeDriver::MOTOR_D; // break; // } //} // // //enum BridgeDriver::Motors Motor::getMotor(){ // return this->motor; //} // ////A line consists of [ __(Local_Name)__ __(function)__ __(parameter1)__ __(parameter2)__ __(parameter3)__ ... and so on] //int Motor::interpret(){ // // // //Order of Line: Local_Name, Function_Name, Param1, Param2, Param3,....... // char *localname = lineData.word[0]; //just for the sake of following the variable easily and understanding // char *func = lineData.word[1]; // // /******************************************************************************/ // /*** <Func: enableBrake> ***/ // /******************************************************************************/ // if (strncmp(func,"enableBrake", 11) == 0){ // // 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); // // bridges.enableBraking(getMotor(), enableValue); // } // // /******************************************************************************/ // /*** <Func: forceBrake> ***/ // /******************************************************************************/ // else if (strncmp(func,"forceBrake", 10) == 0){ // // if (lineData.numWords != 3){ // //Error Check, incorrect number of parameter, error out // return 0; // } // // bridges.forceBrake(getMotor()); // } // // // /******************************************************************************/ // /*** <Func: drive> ***/ // /******************************************************************************/ // // // /******************************************************************************/ // /**** <Func: off> ****/ // /******************************************************************************/ // else if (strncmp(func,"off", 3) == 0){ // // if (lineData.numWords != 2){ // //Error Check, incorrect number of parameter, error out // return 0; // } // // bridges.drive(getMotor(), 0, 0); //Turn off the Motor // } // // else { // return 0; // // } // // // return 1; //} // // // // // // // ///* //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; //} // //int Motor::forceBrake(){ // // if (lineData.numWords != 3){ // //Error Check, incorrect number of parameter, error out // return 0; // } // // bridges.forceBrake(getMotor()); //} // //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 //} //*/ // // //