The Code Repository for the REV0 Steering Wheel.
Dependencies: CANBuffer KS0108_fork mbed-rtos mbed CAN Addresses
Fork of REVO_Updated_Steering by
Steering.cpp@5:05f8a36b5cdd, 2014-10-04 (annotated)
- Committer:
- tmccurbin
- Date:
- Sat Oct 04 17:55:27 2014 +0000
- Revision:
- 5:05f8a36b5cdd
- Parent:
- 4:a4fb060e7840
- Child:
- 7:df257df56363
Removed TL and TR Button functionality.; Set BL to ON; BR to Reset
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kiran_mbed | 0:313541d8f8be | 1 | #include "Steering.h" |
kiran_mbed | 0:313541d8f8be | 2 | |
tmccurbin | 5:05f8a36b5cdd | 3 | |
kiran_mbed | 0:313541d8f8be | 4 | void HomeScreen() |
kiran_mbed | 0:313541d8f8be | 5 | { |
kiran_mbed | 0:313541d8f8be | 6 | CANMessage Rxmsg; |
kiran_mbed | 0:313541d8f8be | 7 | ftc rcv; |
kiran_mbed | 0:313541d8f8be | 8 | rcv.FLOAT=0.0; |
kiran_mbed | 0:313541d8f8be | 9 | char dat[4]; |
kiran_mbed | 0:313541d8f8be | 10 | float power_ratio=0.0; |
kiran_mbed | 0:313541d8f8be | 11 | printf("Homescreen\n\r"); |
kiran_mbed | 0:313541d8f8be | 12 | display.ClearScreen(); |
kiran_mbed | 0:313541d8f8be | 13 | display.SelectFont(Arial12,BLACK,ReadData); |
kiran_mbed | 0:313541d8f8be | 14 | display.GotoXY(0,0); |
kiran_mbed | 0:313541d8f8be | 15 | display.PrintString(" HOME SCREEN"); |
kiran_mbed | 0:313541d8f8be | 16 | while( !(biSWTL.read() || biSWTR.read() || biSWBR.read()) ) |
kiran_mbed | 0:313541d8f8be | 17 | { |
kiran_mbed | 0:313541d8f8be | 18 | if(CAN_Steering.read(Rxmsg)) |
kiran_mbed | 0:313541d8f8be | 19 | { |
kiran_mbed | 0:313541d8f8be | 20 | for(int i=0; i<4; i++) |
kiran_mbed | 0:313541d8f8be | 21 | rcv.C_FLOAT[i]=Rxmsg.data[i]; |
kiran_mbed | 0:313541d8f8be | 22 | if(Rxmsg.id == BATTERY_VOLTAGE_ID) |
kiran_mbed | 0:313541d8f8be | 23 | { |
kiran_mbed | 0:313541d8f8be | 24 | display.GotoXY(0,16); |
kiran_mbed | 0:313541d8f8be | 25 | display.PrintString(" PV: "); |
kiran_mbed | 0:313541d8f8be | 26 | sprintf(dat,"%2.2f",rcv.FLOAT); |
kiran_mbed | 0:313541d8f8be | 27 | display.PrintString(dat); |
kiran_mbed | 0:313541d8f8be | 28 | display.PrintString("V"); |
kiran_mbed | 0:313541d8f8be | 29 | } |
kiran_mbed | 0:313541d8f8be | 30 | if(Rxmsg.id == BATTERY_POWER_ID) |
kiran_mbed | 0:313541d8f8be | 31 | { |
kiran_mbed | 0:313541d8f8be | 32 | display.GotoXY(64,16); |
kiran_mbed | 0:313541d8f8be | 33 | display.PrintString(" PP: "); |
kiran_mbed | 0:313541d8f8be | 34 | power_ratio=rcv.FLOAT/10000; |
kiran_mbed | 0:313541d8f8be | 35 | sprintf(dat,"%2.2f",power_ratio); |
kiran_mbed | 0:313541d8f8be | 36 | display.PrintString(dat); |
kiran_mbed | 0:313541d8f8be | 37 | display.PrintString("kW"); |
kiran_mbed | 0:313541d8f8be | 38 | } |
kiran_mbed | 0:313541d8f8be | 39 | if(Rxmsg.id == PCM_STATE_ID) |
kiran_mbed | 0:313541d8f8be | 40 | { |
kiran_mbed | 0:313541d8f8be | 41 | display.GotoXY(0,32); |
kiran_mbed | 0:313541d8f8be | 42 | display.PrintString(" STATE: "); |
kiran_mbed | 0:313541d8f8be | 43 | display.PrintNumber(rcv.FLOAT); |
kiran_mbed | 0:313541d8f8be | 44 | } |
kiran_mbed | 0:313541d8f8be | 45 | } |
kiran_mbed | 0:313541d8f8be | 46 | } |
kiran_mbed | 0:313541d8f8be | 47 | return; |
kiran_mbed | 0:313541d8f8be | 48 | } |
kiran_mbed | 0:313541d8f8be | 49 | |
kiran_mbed | 0:313541d8f8be | 50 | void AMSScreen1() |
kiran_mbed | 0:313541d8f8be | 51 | { |
kiran_mbed | 0:313541d8f8be | 52 | CANMessage Rxmsg; |
kiran_mbed | 0:313541d8f8be | 53 | ftc rcv; |
kiran_mbed | 0:313541d8f8be | 54 | char dat[4]; |
kiran_mbed | 0:313541d8f8be | 55 | rcv.FLOAT=0.0; |
kiran_mbed | 0:313541d8f8be | 56 | printf("AMSScreen1"); |
kiran_mbed | 0:313541d8f8be | 57 | display.ClearScreen(); |
kiran_mbed | 0:313541d8f8be | 58 | display.SelectFont(Arial12,BLACK,ReadData); |
kiran_mbed | 0:313541d8f8be | 59 | while( !(biSWTL.read() || biSWTR.read() || biSWBL.read()) ) |
kiran_mbed | 0:313541d8f8be | 60 | { |
kiran_mbed | 0:313541d8f8be | 61 | printf("iN LOOP1"); |
kiran_mbed | 0:313541d8f8be | 62 | if(CAN_Steering.read(Rxmsg)) |
kiran_mbed | 0:313541d8f8be | 63 | { |
kiran_mbed | 0:313541d8f8be | 64 | for(int i=0; i<4; i++) |
kiran_mbed | 0:313541d8f8be | 65 | rcv.C_FLOAT[i]=Rxmsg.data[i]; |
kiran_mbed | 0:313541d8f8be | 66 | if(Rxmsg.id == BATTERY_VOLTAGE_ID) |
kiran_mbed | 0:313541d8f8be | 67 | { |
kiran_mbed | 0:313541d8f8be | 68 | display.GotoXY(0,0); |
kiran_mbed | 0:313541d8f8be | 69 | display.PrintString(" pv: "); |
kiran_mbed | 0:313541d8f8be | 70 | sprintf(dat,"%2.2f",rcv.FLOAT); |
kiran_mbed | 0:313541d8f8be | 71 | display.PrintString(dat); |
kiran_mbed | 0:313541d8f8be | 72 | } |
kiran_mbed | 0:313541d8f8be | 73 | if(Rxmsg.id == BATTERY_POWER_ID) |
kiran_mbed | 0:313541d8f8be | 74 | { |
kiran_mbed | 0:313541d8f8be | 75 | display.GotoXY(0,16); |
kiran_mbed | 0:313541d8f8be | 76 | display.PrintString(" pp: "); |
kiran_mbed | 0:313541d8f8be | 77 | sprintf(dat,"%2.2f",rcv.FLOAT); |
kiran_mbed | 0:313541d8f8be | 78 | display.PrintString(dat); |
kiran_mbed | 0:313541d8f8be | 79 | } |
kiran_mbed | 0:313541d8f8be | 80 | if(Rxmsg.id == BATTERY_CURRENT_ID) |
kiran_mbed | 0:313541d8f8be | 81 | { |
kiran_mbed | 0:313541d8f8be | 82 | display.GotoXY(0,32); |
kiran_mbed | 0:313541d8f8be | 83 | display.PrintString(" pi: "); |
kiran_mbed | 0:313541d8f8be | 84 | sprintf(dat,"%2.2f",rcv.FLOAT); |
kiran_mbed | 0:313541d8f8be | 85 | display.PrintString(dat); |
kiran_mbed | 0:313541d8f8be | 86 | } |
kiran_mbed | 0:313541d8f8be | 87 | |
kiran_mbed | 0:313541d8f8be | 88 | //Column 2 |
kiran_mbed | 0:313541d8f8be | 89 | if(Rxmsg.id == BATTERY_MIN_CELLVOLTAGE_ID) |
kiran_mbed | 0:313541d8f8be | 90 | { |
kiran_mbed | 0:313541d8f8be | 91 | display.GotoXY(49,0); |
kiran_mbed | 0:313541d8f8be | 92 | display.PrintString(" min cell V: "); |
kiran_mbed | 0:313541d8f8be | 93 | sprintf(dat,"%2.2f",rcv.FLOAT); |
kiran_mbed | 0:313541d8f8be | 94 | display.PrintString(dat); |
kiran_mbed | 0:313541d8f8be | 95 | } |
kiran_mbed | 0:313541d8f8be | 96 | if(Rxmsg.id == BATTERY_MAX_CELLVOLTAGE_ID) |
kiran_mbed | 0:313541d8f8be | 97 | { |
kiran_mbed | 0:313541d8f8be | 98 | display.GotoXY(49,16); |
kiran_mbed | 0:313541d8f8be | 99 | display.PrintString(" max cell V: "); |
kiran_mbed | 0:313541d8f8be | 100 | sprintf(dat,"%2.2f",rcv.FLOAT); |
kiran_mbed | 0:313541d8f8be | 101 | display.PrintString(dat); |
kiran_mbed | 0:313541d8f8be | 102 | } |
kiran_mbed | 0:313541d8f8be | 103 | if(Rxmsg.id == BATTERY_AVG_CELLVOLTAGE_ID) |
kiran_mbed | 0:313541d8f8be | 104 | { |
kiran_mbed | 0:313541d8f8be | 105 | display.GotoXY(49,32); |
kiran_mbed | 0:313541d8f8be | 106 | display.PrintString(" avg cell V: "); |
kiran_mbed | 0:313541d8f8be | 107 | sprintf(dat,"%2.2f",rcv.FLOAT); |
kiran_mbed | 0:313541d8f8be | 108 | display.PrintString(dat); |
kiran_mbed | 0:313541d8f8be | 109 | } |
kiran_mbed | 0:313541d8f8be | 110 | } |
kiran_mbed | 0:313541d8f8be | 111 | screen=1; |
kiran_mbed | 0:313541d8f8be | 112 | } |
kiran_mbed | 0:313541d8f8be | 113 | return; |
kiran_mbed | 0:313541d8f8be | 114 | } |
kiran_mbed | 0:313541d8f8be | 115 | |
kiran_mbed | 0:313541d8f8be | 116 | void AMSScreen2() |
kiran_mbed | 0:313541d8f8be | 117 | { |
kiran_mbed | 0:313541d8f8be | 118 | CANMessage Rxmsg; |
kiran_mbed | 0:313541d8f8be | 119 | ftc rcv; |
kiran_mbed | 0:313541d8f8be | 120 | char dat[4]; |
kiran_mbed | 0:313541d8f8be | 121 | //ftc send; |
kiran_mbed | 0:313541d8f8be | 122 | rcv.FLOAT=0.0; |
kiran_mbed | 0:313541d8f8be | 123 | //send.FLOAT=65.6432; |
kiran_mbed | 0:313541d8f8be | 124 | printf("AMSScreen2\n\r"); |
kiran_mbed | 0:313541d8f8be | 125 | display.ClearScreen(); |
kiran_mbed | 0:313541d8f8be | 126 | display.SelectFont(Arial12,BLACK,ReadData); |
kiran_mbed | 0:313541d8f8be | 127 | while( !(biSWTL.read() || biSWTR.read() || biSWBL.read()) ) |
kiran_mbed | 0:313541d8f8be | 128 | { |
kiran_mbed | 0:313541d8f8be | 129 | printf("iN LOOP2"); |
kiran_mbed | 0:313541d8f8be | 130 | if(CAN_Steering.read(Rxmsg)) |
kiran_mbed | 0:313541d8f8be | 131 | { |
kiran_mbed | 0:313541d8f8be | 132 | for(int i=0; i<4; i++) |
kiran_mbed | 0:313541d8f8be | 133 | rcv.C_FLOAT[i]=Rxmsg.data[i]; |
kiran_mbed | 0:313541d8f8be | 134 | if(Rxmsg.id == BATTERY_MIN_CELLTEMPERATURE_ID) |
kiran_mbed | 0:313541d8f8be | 135 | { |
kiran_mbed | 0:313541d8f8be | 136 | display.GotoXY(0,0); |
kiran_mbed | 0:313541d8f8be | 137 | display.PrintString(" mn cll T: "); |
kiran_mbed | 0:313541d8f8be | 138 | sprintf(dat,"%2.2f",rcv.FLOAT); |
kiran_mbed | 0:313541d8f8be | 139 | display.PrintString(dat); |
kiran_mbed | 0:313541d8f8be | 140 | } |
kiran_mbed | 0:313541d8f8be | 141 | if(Rxmsg.id == BATTERY_MAX_CELLTEMPERATURE_ID) |
kiran_mbed | 0:313541d8f8be | 142 | { |
kiran_mbed | 0:313541d8f8be | 143 | display.GotoXY(0,16); |
kiran_mbed | 0:313541d8f8be | 144 | display.PrintString(" mx cll T: "); |
kiran_mbed | 0:313541d8f8be | 145 | sprintf(dat,"%2.2f",rcv.FLOAT); |
kiran_mbed | 0:313541d8f8be | 146 | display.PrintString(dat); |
kiran_mbed | 0:313541d8f8be | 147 | } |
kiran_mbed | 0:313541d8f8be | 148 | if(Rxmsg.id == BATTERY_AVG_CELLTEMPERATURE_ID) |
kiran_mbed | 0:313541d8f8be | 149 | { |
kiran_mbed | 0:313541d8f8be | 150 | display.GotoXY(0,32); |
kiran_mbed | 0:313541d8f8be | 151 | display.PrintString(" avg cell T: "); |
kiran_mbed | 0:313541d8f8be | 152 | sprintf(dat,"%2.2f",rcv.FLOAT); |
kiran_mbed | 0:313541d8f8be | 153 | display.PrintString(dat); |
kiran_mbed | 0:313541d8f8be | 154 | } |
kiran_mbed | 0:313541d8f8be | 155 | |
kiran_mbed | 0:313541d8f8be | 156 | //Column 2 |
kiran_mbed | 0:313541d8f8be | 157 | if(Rxmsg.id == AMS_BATTERY_STATE) |
kiran_mbed | 0:313541d8f8be | 158 | { |
kiran_mbed | 0:313541d8f8be | 159 | if((rcv.C_FLOAT[0] & 0xC0) == 0xC0) |
kiran_mbed | 0:313541d8f8be | 160 | { |
kiran_mbed | 0:313541d8f8be | 161 | display.GotoXY(70,0); |
kiran_mbed | 0:313541d8f8be | 162 | display.PrintString(" AIRS: "); |
kiran_mbed | 0:313541d8f8be | 163 | display.PrintString("CLOS"); |
kiran_mbed | 0:313541d8f8be | 164 | } |
kiran_mbed | 0:313541d8f8be | 165 | else |
kiran_mbed | 0:313541d8f8be | 166 | { |
kiran_mbed | 0:313541d8f8be | 167 | display.GotoXY(70,0); |
kiran_mbed | 0:313541d8f8be | 168 | display.PrintString(" AIRS: "); |
kiran_mbed | 0:313541d8f8be | 169 | display.PrintString("OPEN"); |
kiran_mbed | 0:313541d8f8be | 170 | } |
kiran_mbed | 0:313541d8f8be | 171 | |
kiran_mbed | 0:313541d8f8be | 172 | if((rcv.C_FLOAT[0] & 0x04) == 0x04) |
kiran_mbed | 0:313541d8f8be | 173 | { |
kiran_mbed | 0:313541d8f8be | 174 | display.GotoXY(70,16); |
kiran_mbed | 0:313541d8f8be | 175 | display.PrintString(" Prchrg: "); |
kiran_mbed | 0:313541d8f8be | 176 | display.PrintString("on"); |
kiran_mbed | 0:313541d8f8be | 177 | } |
kiran_mbed | 0:313541d8f8be | 178 | else |
kiran_mbed | 0:313541d8f8be | 179 | { |
kiran_mbed | 0:313541d8f8be | 180 | display.GotoXY(70,16); |
kiran_mbed | 0:313541d8f8be | 181 | display.PrintString(" Prchrg: "); |
kiran_mbed | 0:313541d8f8be | 182 | display.PrintString("off"); |
kiran_mbed | 0:313541d8f8be | 183 | } |
kiran_mbed | 0:313541d8f8be | 184 | } |
kiran_mbed | 0:313541d8f8be | 185 | if(Rxmsg.id == AMS_BATTERY_STATE) |
kiran_mbed | 0:313541d8f8be | 186 | { |
kiran_mbed | 0:313541d8f8be | 187 | display.GotoXY(70,16); |
kiran_mbed | 0:313541d8f8be | 188 | display.PrintString(" Prchrg: "); |
kiran_mbed | 0:313541d8f8be | 189 | display.PrintString("off"); |
kiran_mbed | 0:313541d8f8be | 190 | } |
kiran_mbed | 0:313541d8f8be | 191 | } |
kiran_mbed | 0:313541d8f8be | 192 | screen=0; |
kiran_mbed | 0:313541d8f8be | 193 | } |
kiran_mbed | 0:313541d8f8be | 194 | return; |
kiran_mbed | 0:313541d8f8be | 195 | } |
kiran_mbed | 0:313541d8f8be | 196 | |
kiran_mbed | 0:313541d8f8be | 197 | void ON() |
kiran_mbed | 0:313541d8f8be | 198 | { |
kiran_mbed | 0:313541d8f8be | 199 | Txmsg_Drive.data[0]|=(1<<0); |
kiran_mbed | 0:313541d8f8be | 200 | wait(0.1); |
kiran_mbed | 0:313541d8f8be | 201 | |
kiran_mbed | 0:313541d8f8be | 202 | display.ClearScreen(); |
kiran_mbed | 0:313541d8f8be | 203 | display.SelectFont(Arial12,BLACK,ReadData); |
kiran_mbed | 0:313541d8f8be | 204 | display.GotoXY(26,16); |
kiran_mbed | 0:313541d8f8be | 205 | display.PrintString(" ON INITIATED"); |
kiran_mbed | 0:313541d8f8be | 206 | printf("ON Initiated\n\r"); |
kiran_mbed | 0:313541d8f8be | 207 | //screen=0; |
kiran_mbed | 0:313541d8f8be | 208 | return; |
kiran_mbed | 0:313541d8f8be | 209 | } |
kiran_mbed | 0:313541d8f8be | 210 | |
kiran_mbed | 0:313541d8f8be | 211 | void ResetCommand() |
kiran_mbed | 0:313541d8f8be | 212 | { |
kiran_mbed | 0:313541d8f8be | 213 | Txmsg_Drive.data[0]&=~(1<<0); |
kiran_mbed | 0:313541d8f8be | 214 | wait(0.1); |
kiran_mbed | 0:313541d8f8be | 215 | |
kiran_mbed | 0:313541d8f8be | 216 | display.ClearScreen(); |
kiran_mbed | 0:313541d8f8be | 217 | display.SelectFont(Arial12,BLACK,ReadData); |
kiran_mbed | 0:313541d8f8be | 218 | display.GotoXY(16,16); |
kiran_mbed | 0:313541d8f8be | 219 | display.PrintString(" RESET INITIATED"); |
kiran_mbed | 0:313541d8f8be | 220 | printf("Reset Initiated\n\r"); |
kiran_mbed | 0:313541d8f8be | 221 | //screen=0; |
kiran_mbed | 0:313541d8f8be | 222 | |
kiran_mbed | 0:313541d8f8be | 223 | return; |
kiran_mbed | 0:313541d8f8be | 224 | } |
kiran_mbed | 0:313541d8f8be | 225 | |
kiran_mbed | 0:313541d8f8be | 226 | void Powerstream() |
kiran_mbed | 0:313541d8f8be | 227 | { |
kiran_mbed | 0:313541d8f8be | 228 | CANMessage Rxmsg; |
kiran_mbed | 0:313541d8f8be | 229 | float power_ratio; |
kiran_mbed | 0:313541d8f8be | 230 | ftc rcv; |
kiran_mbed | 0:313541d8f8be | 231 | rcv.FLOAT=0.0; |
kiran_mbed | 0:313541d8f8be | 232 | if(CAN_Steering.read(Rxmsg)) |
kiran_mbed | 0:313541d8f8be | 233 | { |
kiran_mbed | 0:313541d8f8be | 234 | if(Rxmsg.id == BATTERY_POWER_ID) |
kiran_mbed | 0:313541d8f8be | 235 | { |
kiran_mbed | 0:313541d8f8be | 236 | for(int i=0; i<4; i++) |
kiran_mbed | 0:313541d8f8be | 237 | rcv.C_FLOAT[i]=Rxmsg.data[i]; |
kiran_mbed | 0:313541d8f8be | 238 | power_ratio=rcv.FLOAT/80000; |
kiran_mbed | 0:313541d8f8be | 239 | ledstream.write(power_ratio); |
kiran_mbed | 0:313541d8f8be | 240 | } |
kiran_mbed | 0:313541d8f8be | 241 | } |
kiran_mbed | 0:313541d8f8be | 242 | } |
kiran_mbed | 0:313541d8f8be | 243 | |
kiran_mbed | 0:313541d8f8be | 244 | void Init() |
kiran_mbed | 0:313541d8f8be | 245 | { |
kiran_mbed | 0:313541d8f8be | 246 | pc.baud(230400); |
kiran_mbed | 0:313541d8f8be | 247 | CAN_Steering.frequency(500000); |
kiran_mbed | 0:313541d8f8be | 248 | for(int i = 0; i<4; i++) |
kiran_mbed | 0:313541d8f8be | 249 | drive[i] = (0x00); |
kiran_mbed | 0:313541d8f8be | 250 | ledstream.write(0); |
kiran_mbed | 0:313541d8f8be | 251 | call_ledstream.attach(&Powerstream,0.1); |
kiran_mbed | 0:313541d8f8be | 252 | } |
kiran_mbed | 0:313541d8f8be | 253 | |
kiran_mbed | 0:313541d8f8be | 254 | int main() |
kiran_mbed | 0:313541d8f8be | 255 | { |
palimar | 4:a4fb060e7840 | 256 | // Init all |
kiran_mbed | 0:313541d8f8be | 257 | Init(); |
kiran_mbed | 0:313541d8f8be | 258 | wait(0.1); |
palimar | 4:a4fb060e7840 | 259 | |
palimar | 4:a4fb060e7840 | 260 | //Init Display |
kiran_mbed | 0:313541d8f8be | 261 | display.GotoXY(10,16); |
kiran_mbed | 0:313541d8f8be | 262 | display.SelectFont(Arial_14,BLACK,ReadData); |
kiran_mbed | 0:313541d8f8be | 263 | display.PrintString("Penn Electric Racing"); |
palimar | 4:a4fb060e7840 | 264 | |
palimar | 4:a4fb060e7840 | 265 | // Start to read buttons on main thread |
kiran_mbed | 0:313541d8f8be | 266 | screen=0; |
kiran_mbed | 0:313541d8f8be | 267 | wait(1); |
kiran_mbed | 0:313541d8f8be | 268 | |
kiran_mbed | 0:313541d8f8be | 269 | while(1) |
kiran_mbed | 0:313541d8f8be | 270 | { |
kiran_mbed | 0:313541d8f8be | 271 | if(biSWBL.read()) |
kiran_mbed | 0:313541d8f8be | 272 | { |
kiran_mbed | 0:313541d8f8be | 273 | ON(); |
tmccurbin | 5:05f8a36b5cdd | 274 | //wait(1); |
tmccurbin | 5:05f8a36b5cdd | 275 | // HomeScreen(); |
kiran_mbed | 0:313541d8f8be | 276 | } |
kiran_mbed | 0:313541d8f8be | 277 | if(biSWBR.read()) |
kiran_mbed | 0:313541d8f8be | 278 | { |
tmccurbin | 5:05f8a36b5cdd | 279 | ResetCommand(); |
kiran_mbed | 0:313541d8f8be | 280 | } |
kiran_mbed | 0:313541d8f8be | 281 | CAN_Steering.write(Txmsg_Drive); |
kiran_mbed | 0:313541d8f8be | 282 | wait(0.3); |
kiran_mbed | 0:313541d8f8be | 283 | } |
kiran_mbed | 0:313541d8f8be | 284 | } |