![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Component Test's Software to work with "Universal Controller Box" - Software is an interpreter or "compiler" for programs to be done with a .txt file and read off of the SD Card
Dependencies: BridgeDriver FrontPanelButtons MCP23017 SDFileSystem TextLCD mbed
Devices/VoltageDriver.cpp@16:2482d226cf4d, 2014-10-03 (annotated)
- Committer:
- mehatfie
- Date:
- Fri Oct 03 21:33:46 2014 +0000
- Revision:
- 16:2482d226cf4d
- Parent:
- 14:953820302fb7
- Updated Errors; - Initializes SD Card to work every time; - Cycle timer starts immediately on first cycle
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mehatfie | 2:3e7baa3e3fec | 1 | #include "VoltageDriver.hpp" |
mehatfie | 2:3e7baa3e3fec | 2 | |
mehatfie | 2:3e7baa3e3fec | 3 | //Constructor |
mehatfie | 5:e36e0538a903 | 4 | VoltageDriver::VoltageDriver(LineData lineData){ |
mehatfie | 14:953820302fb7 | 5 | this->errorFlag = 0; |
mehatfie | 14:953820302fb7 | 6 | |
mehatfie | 2:3e7baa3e3fec | 7 | //Order of Line: Command, Local_Name, VOLTAGE_DRIVER, Channel(1,2,3,4,5,6,7,8) |
mehatfie | 9:5a0c4c6e39c7 | 8 | if (lineData.numWords != 4) |
mehatfie | 9:5a0c4c6e39c7 | 9 | this->errorFlag = 1; |
mehatfie | 2:3e7baa3e3fec | 10 | |
mehatfie | 2:3e7baa3e3fec | 11 | string channelstr = lineData.word[3]; //Parameter is a number |
mehatfie | 9:5a0c4c6e39c7 | 12 | int numValuesFound = sscanf(channelstr.c_str(), "%d", &channel); |
mehatfie | 9:5a0c4c6e39c7 | 13 | if (numValuesFound < 1) |
mehatfie | 9:5a0c4c6e39c7 | 14 | this->errorFlag = 1; |
mehatfie | 9:5a0c4c6e39c7 | 15 | |
mehatfie | 2:3e7baa3e3fec | 16 | //Channel Value between 1 to 8 |
mehatfie | 2:3e7baa3e3fec | 17 | if (channel >= 1 && channel <= 8){ |
mehatfie | 2:3e7baa3e3fec | 18 | |
mehatfie | 2:3e7baa3e3fec | 19 | switch (channel){ |
mehatfie | 2:3e7baa3e3fec | 20 | case 1: |
mehatfie | 2:3e7baa3e3fec | 21 | case 2: |
mehatfie | 2:3e7baa3e3fec | 22 | bridges.enablePwm(BridgeDriver::MOTOR_A, 0); |
mehatfie | 2:3e7baa3e3fec | 23 | break; |
mehatfie | 2:3e7baa3e3fec | 24 | case 3: |
mehatfie | 2:3e7baa3e3fec | 25 | case 4: |
mehatfie | 2:3e7baa3e3fec | 26 | bridges.enablePwm(BridgeDriver::MOTOR_B, 0); |
mehatfie | 2:3e7baa3e3fec | 27 | break; |
mehatfie | 2:3e7baa3e3fec | 28 | case 5: |
mehatfie | 2:3e7baa3e3fec | 29 | case 6: |
mehatfie | 2:3e7baa3e3fec | 30 | bridges.enablePwm(BridgeDriver::MOTOR_C, 0); |
mehatfie | 2:3e7baa3e3fec | 31 | break; |
mehatfie | 2:3e7baa3e3fec | 32 | case 7: |
mehatfie | 2:3e7baa3e3fec | 33 | case 8: |
mehatfie | 2:3e7baa3e3fec | 34 | bridges.enablePwm(BridgeDriver::MOTOR_D, 0); |
mehatfie | 2:3e7baa3e3fec | 35 | break; |
mehatfie | 2:3e7baa3e3fec | 36 | } |
mehatfie | 2:3e7baa3e3fec | 37 | } |
mehatfie | 9:5a0c4c6e39c7 | 38 | |
mehatfie | 9:5a0c4c6e39c7 | 39 | //Channel does not fall into valid selection |
mehatfie | 9:5a0c4c6e39c7 | 40 | else |
mehatfie | 9:5a0c4c6e39c7 | 41 | this->errorFlag = 1; |
mehatfie | 2:3e7baa3e3fec | 42 | } |
mehatfie | 2:3e7baa3e3fec | 43 | |
mehatfie | 2:3e7baa3e3fec | 44 | |
mehatfie | 9:5a0c4c6e39c7 | 45 | int VoltageDriver::getChannel(){ |
mehatfie | 2:3e7baa3e3fec | 46 | return this->channel; |
mehatfie | 2:3e7baa3e3fec | 47 | } |
mehatfie | 2:3e7baa3e3fec | 48 | |
mehatfie | 2:3e7baa3e3fec | 49 | |
mehatfie | 2:3e7baa3e3fec | 50 | //A line consists of [ __(Local_Name)__ __(function)__ __(parameter1)__ __(parameter2)__ __(parameter3)__ ... and so on] |
mehatfie | 5:e36e0538a903 | 51 | int VoltageDriver::interpret(LineData &lineData){ |
mehatfie | 11:bc9cd2869f95 | 52 | |
mehatfie | 9:5a0c4c6e39c7 | 53 | //Order of line: local_name, function_name, param1, param2, param3,....... |
mehatfie | 2:3e7baa3e3fec | 54 | string func = lineData.word[1]; |
mehatfie | 2:3e7baa3e3fec | 55 | |
mehatfie | 2:3e7baa3e3fec | 56 | /******************************************************************************/ |
mehatfie | 2:3e7baa3e3fec | 57 | /*** <func: forcebrake> ***/ |
mehatfie | 2:3e7baa3e3fec | 58 | /******************************************************************************/ |
mehatfie | 2:3e7baa3e3fec | 59 | if (func.compare("forcebrake") == 0){ |
mehatfie | 2:3e7baa3e3fec | 60 | |
mehatfie | 9:5a0c4c6e39c7 | 61 | if (lineData.numWords != 2){ |
mehatfie | 9:5a0c4c6e39c7 | 62 | ErrorOut("Incorrect number of parameters", lineData.lineNumber); |
mehatfie | 9:5a0c4c6e39c7 | 63 | return -1; |
mehatfie | 2:3e7baa3e3fec | 64 | } |
mehatfie | 2:3e7baa3e3fec | 65 | |
mehatfie | 10:e8db892fbc52 | 66 | //All syntax checking done by this point, if Dummy then return success in order to check the code, no need to perform functionality |
mehatfie | 10:e8db892fbc52 | 67 | if (DummyMode) |
mehatfie | 10:e8db892fbc52 | 68 | return 0; //Function operated successfully but doesn't return a value |
mehatfie | 10:e8db892fbc52 | 69 | |
mehatfie | 2:3e7baa3e3fec | 70 | bridges.forceBrake(channel); |
mehatfie | 11:bc9cd2869f95 | 71 | |
mehatfie | 11:bc9cd2869f95 | 72 | //Record the settings for Pause and Resume |
mehatfie | 11:bc9cd2869f95 | 73 | currState = 0; |
mehatfie | 2:3e7baa3e3fec | 74 | } |
mehatfie | 2:3e7baa3e3fec | 75 | |
mehatfie | 2:3e7baa3e3fec | 76 | |
mehatfie | 2:3e7baa3e3fec | 77 | /******************************************************************************/ |
mehatfie | 2:3e7baa3e3fec | 78 | /*** <func: drive> ***/ |
mehatfie | 2:3e7baa3e3fec | 79 | /******************************************************************************/ |
mehatfie | 2:3e7baa3e3fec | 80 | else if (func.compare("drive") == 0){ |
mehatfie | 2:3e7baa3e3fec | 81 | //order of line: local_name, drive |
mehatfie | 11:bc9cd2869f95 | 82 | |
mehatfie | 2:3e7baa3e3fec | 83 | if (lineData.numWords != 2){ |
mehatfie | 9:5a0c4c6e39c7 | 84 | ErrorOut("Incorrect number of parameters", lineData.lineNumber); |
mehatfie | 9:5a0c4c6e39c7 | 85 | return -1; |
mehatfie | 2:3e7baa3e3fec | 86 | } |
mehatfie | 11:bc9cd2869f95 | 87 | |
mehatfie | 10:e8db892fbc52 | 88 | //All syntax checking done by this point, if Dummy then return success in order to check the code, no need to perform functionality |
mehatfie | 10:e8db892fbc52 | 89 | if (DummyMode) |
mehatfie | 10:e8db892fbc52 | 90 | return 0; //Function operated successfully but doesn't return a value |
mehatfie | 11:bc9cd2869f95 | 91 | |
mehatfie | 2:3e7baa3e3fec | 92 | bridges.drive(channel, 1); //turn channel on |
mehatfie | 11:bc9cd2869f95 | 93 | |
mehatfie | 11:bc9cd2869f95 | 94 | //Record the settings for Pause and Resume |
mehatfie | 11:bc9cd2869f95 | 95 | currState = 1; |
mehatfie | 2:3e7baa3e3fec | 96 | } |
mehatfie | 2:3e7baa3e3fec | 97 | |
mehatfie | 2:3e7baa3e3fec | 98 | |
mehatfie | 2:3e7baa3e3fec | 99 | /******************************************************************************/ |
mehatfie | 2:3e7baa3e3fec | 100 | /**** <func: off> ****/ |
mehatfie | 2:3e7baa3e3fec | 101 | /******************************************************************************/ |
mehatfie | 3:078e9a1e8be3 | 102 | else if (func.compare("off") == 0){ |
mehatfie | 2:3e7baa3e3fec | 103 | |
mehatfie | 2:3e7baa3e3fec | 104 | if (lineData.numWords != 2){ |
mehatfie | 9:5a0c4c6e39c7 | 105 | ErrorOut("Incorrect number of parameters", lineData.lineNumber); |
mehatfie | 9:5a0c4c6e39c7 | 106 | return -1; |
mehatfie | 2:3e7baa3e3fec | 107 | } |
mehatfie | 2:3e7baa3e3fec | 108 | |
mehatfie | 10:e8db892fbc52 | 109 | //All syntax checking done by this point, if Dummy then return success in order to check the code, no need to perform functionality |
mehatfie | 10:e8db892fbc52 | 110 | if (DummyMode) |
mehatfie | 10:e8db892fbc52 | 111 | return 0; //Function operated successfully but doesn't return a value |
mehatfie | 10:e8db892fbc52 | 112 | |
mehatfie | 9:5a0c4c6e39c7 | 113 | off(); |
mehatfie | 2:3e7baa3e3fec | 114 | } |
mehatfie | 2:3e7baa3e3fec | 115 | |
mehatfie | 9:5a0c4c6e39c7 | 116 | |
mehatfie | 2:3e7baa3e3fec | 117 | else { |
mehatfie | 9:5a0c4c6e39c7 | 118 | ErrorOut("Unknown Command for Voltage Driver Class", lineData.lineNumber); |
mehatfie | 9:5a0c4c6e39c7 | 119 | return -1; |
mehatfie | 9:5a0c4c6e39c7 | 120 | } |
mehatfie | 2:3e7baa3e3fec | 121 | |
mehatfie | 9:5a0c4c6e39c7 | 122 | return 0; //Return success as 0 since no condition had to be met |
mehatfie | 9:5a0c4c6e39c7 | 123 | } |
mehatfie | 9:5a0c4c6e39c7 | 124 | |
mehatfie | 9:5a0c4c6e39c7 | 125 | |
mehatfie | 9:5a0c4c6e39c7 | 126 | //For stopping the entire system if an error occurs, can be called from main |
mehatfie | 9:5a0c4c6e39c7 | 127 | int VoltageDriver::off(void){ |
mehatfie | 9:5a0c4c6e39c7 | 128 | bridges.drive(getChannel(), 0); //turn channel off |
mehatfie | 11:bc9cd2869f95 | 129 | |
mehatfie | 11:bc9cd2869f95 | 130 | //Record the settings for Pause and Resume, and exit |
mehatfie | 11:bc9cd2869f95 | 131 | currState = 0; |
mehatfie | 10:e8db892fbc52 | 132 | return 0; |
mehatfie | 9:5a0c4c6e39c7 | 133 | } |
mehatfie | 9:5a0c4c6e39c7 | 134 | |
mehatfie | 11:bc9cd2869f95 | 135 | |
mehatfie | 11:bc9cd2869f95 | 136 | //Stop the driver without changing the previous known settings, so that it will be saved on resume |
mehatfie | 11:bc9cd2869f95 | 137 | int VoltageDriver::pause(void){ |
mehatfie | 11:bc9cd2869f95 | 138 | bridges.drive(getChannel(), 0); //turn channel off |
mehatfie | 11:bc9cd2869f95 | 139 | return 0; |
mehatfie | 11:bc9cd2869f95 | 140 | } |
mehatfie | 11:bc9cd2869f95 | 141 | |
mehatfie | 11:bc9cd2869f95 | 142 | //Resume the driver using its previously known settings |
mehatfie | 11:bc9cd2869f95 | 143 | int VoltageDriver::resume(void){ |
mehatfie | 11:bc9cd2869f95 | 144 | bridges.drive(getChannel(), this->currState); //turn channel off |
mehatfie | 11:bc9cd2869f95 | 145 | return 0; |
mehatfie | 11:bc9cd2869f95 | 146 | } |
mehatfie | 11:bc9cd2869f95 | 147 | |
mehatfie | 11:bc9cd2869f95 | 148 |