The Code Repository for the REV0 Steering Wheel.

Dependencies:   CANBuffer KS0108_fork mbed-rtos mbed CAN Addresses

Fork of REVO_Updated_Steering by Penn Electric

Committer:
tmccurbin
Date:
Sat Oct 25 01:33:19 2014 +0000
Revision:
29:9c48604d98b6
Parent:
28:3ebe6db73fe0
extern "C" added

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kiran_mbed 0:313541d8f8be 1 #include "Steering.h"
kiran_mbed 0:313541d8f8be 2
tmccurbin 29:9c48604d98b6 3 extern "C" void mbed_reset();
tmccurbin 29:9c48604d98b6 4
kiran_mbed 0:313541d8f8be 5 void HomeScreen()
kiran_mbed 0:313541d8f8be 6 {
kiran_mbed 0:313541d8f8be 7 CANMessage Rxmsg;
kiran_mbed 0:313541d8f8be 8 ftc rcv;
kiran_mbed 0:313541d8f8be 9 rcv.FLOAT=0.0;
kiran_mbed 0:313541d8f8be 10 char dat[4];
kiran_mbed 0:313541d8f8be 11 float power_ratio=0.0;
kiran_mbed 0:313541d8f8be 12 printf("Homescreen\n\r");
kiran_mbed 0:313541d8f8be 13 display.ClearScreen();
kiran_mbed 0:313541d8f8be 14 display.SelectFont(Arial12,BLACK,ReadData);
kiran_mbed 0:313541d8f8be 15 display.GotoXY(0,0);
kiran_mbed 0:313541d8f8be 16 display.PrintString(" HOME SCREEN");
kiran_mbed 0:313541d8f8be 17 while( !(biSWTL.read() || biSWTR.read() || biSWBR.read()) )
kiran_mbed 0:313541d8f8be 18 {
palimar 16:d2953809fb31 19 if(CAN_Steering_Buffer.rxRead(Rxmsg))
kiran_mbed 0:313541d8f8be 20 {
kiran_mbed 0:313541d8f8be 21 for(int i=0; i<4; i++)
kiran_mbed 0:313541d8f8be 22 rcv.C_FLOAT[i]=Rxmsg.data[i];
kiran_mbed 0:313541d8f8be 23 if(Rxmsg.id == BATTERY_VOLTAGE_ID)
kiran_mbed 0:313541d8f8be 24 {
kiran_mbed 0:313541d8f8be 25 display.GotoXY(0,16);
kiran_mbed 0:313541d8f8be 26 display.PrintString(" PV: ");
kiran_mbed 0:313541d8f8be 27 sprintf(dat,"%2.2f",rcv.FLOAT);
kiran_mbed 0:313541d8f8be 28 display.PrintString(dat);
kiran_mbed 0:313541d8f8be 29 display.PrintString("V");
kiran_mbed 0:313541d8f8be 30 }
kiran_mbed 0:313541d8f8be 31 if(Rxmsg.id == BATTERY_POWER_ID)
kiran_mbed 0:313541d8f8be 32 {
kiran_mbed 0:313541d8f8be 33 display.GotoXY(64,16);
kiran_mbed 0:313541d8f8be 34 display.PrintString(" PP: ");
kiran_mbed 0:313541d8f8be 35 power_ratio=rcv.FLOAT/10000;
kiran_mbed 0:313541d8f8be 36 sprintf(dat,"%2.2f",power_ratio);
kiran_mbed 0:313541d8f8be 37 display.PrintString(dat);
kiran_mbed 0:313541d8f8be 38 display.PrintString("kW");
kiran_mbed 0:313541d8f8be 39 }
kiran_mbed 0:313541d8f8be 40 if(Rxmsg.id == PCM_STATE_ID)
kiran_mbed 0:313541d8f8be 41 {
kiran_mbed 0:313541d8f8be 42 display.GotoXY(0,32);
kiran_mbed 0:313541d8f8be 43 display.PrintString(" STATE: ");
kiran_mbed 0:313541d8f8be 44 display.PrintNumber(rcv.FLOAT);
kiran_mbed 0:313541d8f8be 45 }
kiran_mbed 0:313541d8f8be 46 }
kiran_mbed 0:313541d8f8be 47 }
kiran_mbed 0:313541d8f8be 48 return;
kiran_mbed 0:313541d8f8be 49 }
kiran_mbed 0:313541d8f8be 50
kiran_mbed 0:313541d8f8be 51 void AMSScreen1()
kiran_mbed 0:313541d8f8be 52 {
kiran_mbed 0:313541d8f8be 53 CANMessage Rxmsg;
kiran_mbed 0:313541d8f8be 54 ftc rcv;
kiran_mbed 0:313541d8f8be 55 char dat[4];
kiran_mbed 0:313541d8f8be 56 rcv.FLOAT=0.0;
kiran_mbed 0:313541d8f8be 57 printf("AMSScreen1");
kiran_mbed 0:313541d8f8be 58 display.ClearScreen();
kiran_mbed 0:313541d8f8be 59 display.SelectFont(Arial12,BLACK,ReadData);
kiran_mbed 0:313541d8f8be 60 while( !(biSWTL.read() || biSWTR.read() || biSWBL.read()) )
kiran_mbed 0:313541d8f8be 61 {
kiran_mbed 0:313541d8f8be 62 printf("iN LOOP1");
palimar 16:d2953809fb31 63 if(CAN_Steering_Buffer.rxRead(Rxmsg))
kiran_mbed 0:313541d8f8be 64 {
kiran_mbed 0:313541d8f8be 65 for(int i=0; i<4; i++)
kiran_mbed 0:313541d8f8be 66 rcv.C_FLOAT[i]=Rxmsg.data[i];
kiran_mbed 0:313541d8f8be 67 if(Rxmsg.id == BATTERY_VOLTAGE_ID)
kiran_mbed 0:313541d8f8be 68 {
kiran_mbed 0:313541d8f8be 69 display.GotoXY(0,0);
kiran_mbed 0:313541d8f8be 70 display.PrintString(" pv: ");
kiran_mbed 0:313541d8f8be 71 sprintf(dat,"%2.2f",rcv.FLOAT);
kiran_mbed 0:313541d8f8be 72 display.PrintString(dat);
kiran_mbed 0:313541d8f8be 73 }
kiran_mbed 0:313541d8f8be 74 if(Rxmsg.id == BATTERY_POWER_ID)
kiran_mbed 0:313541d8f8be 75 {
kiran_mbed 0:313541d8f8be 76 display.GotoXY(0,16);
kiran_mbed 0:313541d8f8be 77 display.PrintString(" pp: ");
kiran_mbed 0:313541d8f8be 78 sprintf(dat,"%2.2f",rcv.FLOAT);
kiran_mbed 0:313541d8f8be 79 display.PrintString(dat);
kiran_mbed 0:313541d8f8be 80 }
kiran_mbed 0:313541d8f8be 81 if(Rxmsg.id == BATTERY_CURRENT_ID)
kiran_mbed 0:313541d8f8be 82 {
kiran_mbed 0:313541d8f8be 83 display.GotoXY(0,32);
kiran_mbed 0:313541d8f8be 84 display.PrintString(" pi: ");
kiran_mbed 0:313541d8f8be 85 sprintf(dat,"%2.2f",rcv.FLOAT);
kiran_mbed 0:313541d8f8be 86 display.PrintString(dat);
kiran_mbed 0:313541d8f8be 87 }
kiran_mbed 0:313541d8f8be 88
kiran_mbed 0:313541d8f8be 89 //Column 2
kiran_mbed 0:313541d8f8be 90 if(Rxmsg.id == BATTERY_MIN_CELLVOLTAGE_ID)
kiran_mbed 0:313541d8f8be 91 {
kiran_mbed 0:313541d8f8be 92 display.GotoXY(49,0);
kiran_mbed 0:313541d8f8be 93 display.PrintString(" min cell V: ");
kiran_mbed 0:313541d8f8be 94 sprintf(dat,"%2.2f",rcv.FLOAT);
kiran_mbed 0:313541d8f8be 95 display.PrintString(dat);
kiran_mbed 0:313541d8f8be 96 }
kiran_mbed 0:313541d8f8be 97 if(Rxmsg.id == BATTERY_MAX_CELLVOLTAGE_ID)
kiran_mbed 0:313541d8f8be 98 {
kiran_mbed 0:313541d8f8be 99 display.GotoXY(49,16);
kiran_mbed 0:313541d8f8be 100 display.PrintString(" max cell V: ");
kiran_mbed 0:313541d8f8be 101 sprintf(dat,"%2.2f",rcv.FLOAT);
kiran_mbed 0:313541d8f8be 102 display.PrintString(dat);
kiran_mbed 0:313541d8f8be 103 }
kiran_mbed 0:313541d8f8be 104 if(Rxmsg.id == BATTERY_AVG_CELLVOLTAGE_ID)
kiran_mbed 0:313541d8f8be 105 {
kiran_mbed 0:313541d8f8be 106 display.GotoXY(49,32);
kiran_mbed 0:313541d8f8be 107 display.PrintString(" avg cell V: ");
kiran_mbed 0:313541d8f8be 108 sprintf(dat,"%2.2f",rcv.FLOAT);
kiran_mbed 0:313541d8f8be 109 display.PrintString(dat);
kiran_mbed 0:313541d8f8be 110 }
kiran_mbed 0:313541d8f8be 111 }
kiran_mbed 0:313541d8f8be 112 screen=1;
kiran_mbed 0:313541d8f8be 113 }
kiran_mbed 0:313541d8f8be 114 return;
kiran_mbed 0:313541d8f8be 115 }
kiran_mbed 0:313541d8f8be 116
kiran_mbed 0:313541d8f8be 117 void AMSScreen2()
kiran_mbed 0:313541d8f8be 118 {
kiran_mbed 0:313541d8f8be 119 CANMessage Rxmsg;
kiran_mbed 0:313541d8f8be 120 ftc rcv;
kiran_mbed 0:313541d8f8be 121 char dat[4];
kiran_mbed 0:313541d8f8be 122 //ftc send;
kiran_mbed 0:313541d8f8be 123 rcv.FLOAT=0.0;
kiran_mbed 0:313541d8f8be 124 //send.FLOAT=65.6432;
kiran_mbed 0:313541d8f8be 125 printf("AMSScreen2\n\r");
kiran_mbed 0:313541d8f8be 126 display.ClearScreen();
kiran_mbed 0:313541d8f8be 127 display.SelectFont(Arial12,BLACK,ReadData);
kiran_mbed 0:313541d8f8be 128 while( !(biSWTL.read() || biSWTR.read() || biSWBL.read()) )
kiran_mbed 0:313541d8f8be 129 {
kiran_mbed 0:313541d8f8be 130 printf("iN LOOP2");
palimar 16:d2953809fb31 131 if(CAN_Steering_Buffer.rxRead(Rxmsg))
kiran_mbed 0:313541d8f8be 132 {
kiran_mbed 0:313541d8f8be 133 for(int i=0; i<4; i++)
kiran_mbed 0:313541d8f8be 134 rcv.C_FLOAT[i]=Rxmsg.data[i];
kiran_mbed 0:313541d8f8be 135 if(Rxmsg.id == BATTERY_MIN_CELLTEMPERATURE_ID)
kiran_mbed 0:313541d8f8be 136 {
kiran_mbed 0:313541d8f8be 137 display.GotoXY(0,0);
kiran_mbed 0:313541d8f8be 138 display.PrintString(" mn cll T: ");
kiran_mbed 0:313541d8f8be 139 sprintf(dat,"%2.2f",rcv.FLOAT);
kiran_mbed 0:313541d8f8be 140 display.PrintString(dat);
kiran_mbed 0:313541d8f8be 141 }
kiran_mbed 0:313541d8f8be 142 if(Rxmsg.id == BATTERY_MAX_CELLTEMPERATURE_ID)
kiran_mbed 0:313541d8f8be 143 {
kiran_mbed 0:313541d8f8be 144 display.GotoXY(0,16);
kiran_mbed 0:313541d8f8be 145 display.PrintString(" mx cll T: ");
kiran_mbed 0:313541d8f8be 146 sprintf(dat,"%2.2f",rcv.FLOAT);
kiran_mbed 0:313541d8f8be 147 display.PrintString(dat);
kiran_mbed 0:313541d8f8be 148 }
kiran_mbed 0:313541d8f8be 149 if(Rxmsg.id == BATTERY_AVG_CELLTEMPERATURE_ID)
kiran_mbed 0:313541d8f8be 150 {
kiran_mbed 0:313541d8f8be 151 display.GotoXY(0,32);
kiran_mbed 0:313541d8f8be 152 display.PrintString(" avg cell T: ");
kiran_mbed 0:313541d8f8be 153 sprintf(dat,"%2.2f",rcv.FLOAT);
kiran_mbed 0:313541d8f8be 154 display.PrintString(dat);
kiran_mbed 0:313541d8f8be 155 }
kiran_mbed 0:313541d8f8be 156
kiran_mbed 0:313541d8f8be 157 //Column 2
kiran_mbed 0:313541d8f8be 158 if(Rxmsg.id == AMS_BATTERY_STATE)
kiran_mbed 0:313541d8f8be 159 {
kiran_mbed 0:313541d8f8be 160 if((rcv.C_FLOAT[0] & 0xC0) == 0xC0)
kiran_mbed 0:313541d8f8be 161 {
kiran_mbed 0:313541d8f8be 162 display.GotoXY(70,0);
kiran_mbed 0:313541d8f8be 163 display.PrintString(" AIRS: ");
kiran_mbed 0:313541d8f8be 164 display.PrintString("CLOS");
kiran_mbed 0:313541d8f8be 165 }
kiran_mbed 0:313541d8f8be 166 else
kiran_mbed 0:313541d8f8be 167 {
kiran_mbed 0:313541d8f8be 168 display.GotoXY(70,0);
kiran_mbed 0:313541d8f8be 169 display.PrintString(" AIRS: ");
kiran_mbed 0:313541d8f8be 170 display.PrintString("OPEN");
kiran_mbed 0:313541d8f8be 171 }
kiran_mbed 0:313541d8f8be 172
kiran_mbed 0:313541d8f8be 173 if((rcv.C_FLOAT[0] & 0x04) == 0x04)
kiran_mbed 0:313541d8f8be 174 {
kiran_mbed 0:313541d8f8be 175 display.GotoXY(70,16);
kiran_mbed 0:313541d8f8be 176 display.PrintString(" Prchrg: ");
kiran_mbed 0:313541d8f8be 177 display.PrintString("on");
kiran_mbed 0:313541d8f8be 178 }
kiran_mbed 0:313541d8f8be 179 else
kiran_mbed 0:313541d8f8be 180 {
kiran_mbed 0:313541d8f8be 181 display.GotoXY(70,16);
kiran_mbed 0:313541d8f8be 182 display.PrintString(" Prchrg: ");
kiran_mbed 0:313541d8f8be 183 display.PrintString("off");
kiran_mbed 0:313541d8f8be 184 }
kiran_mbed 0:313541d8f8be 185 }
kiran_mbed 0:313541d8f8be 186 if(Rxmsg.id == AMS_BATTERY_STATE)
kiran_mbed 0:313541d8f8be 187 {
kiran_mbed 0:313541d8f8be 188 display.GotoXY(70,16);
kiran_mbed 0:313541d8f8be 189 display.PrintString(" Prchrg: ");
kiran_mbed 0:313541d8f8be 190 display.PrintString("off");
kiran_mbed 0:313541d8f8be 191 }
kiran_mbed 0:313541d8f8be 192 }
kiran_mbed 0:313541d8f8be 193 screen=0;
kiran_mbed 0:313541d8f8be 194 }
kiran_mbed 0:313541d8f8be 195 return;
kiran_mbed 0:313541d8f8be 196 }
kiran_mbed 0:313541d8f8be 197
palimar 6:99e754ac888f 198 void display_speed_data(void const *args) {
palimar 6:99e754ac888f 199 while (true) {
palimar 6:99e754ac888f 200 display.GotoXY(10,16);
palimar 6:99e754ac888f 201 display.SelectFont(Arial_14,BLACK,ReadData);
palimar 6:99e754ac888f 202 char buf[10];
palimar 6:99e754ac888f 203 int a = rand()%100;
palimar 6:99e754ac888f 204 sprintf(buf, "%d", a);
palimar 6:99e754ac888f 205 display.PrintString("Speed: ");
palimar 6:99e754ac888f 206 display.PrintString(buf);
palimar 6:99e754ac888f 207 display.PrintString("mph");
palimar 6:99e754ac888f 208 }
palimar 6:99e754ac888f 209 }
palimar 6:99e754ac888f 210
palimar 6:99e754ac888f 211
palimar 9:e946cafa3cae 212 void request_status_change()
kiran_mbed 0:313541d8f8be 213 {
palimar 13:1f05dcd9ae0e 214
palimar 13:1f05dcd9ae0e 215 char drive_status_request = !drive_status;
palimar 13:1f05dcd9ae0e 216 char * status_string;
palimar 9:e946cafa3cae 217
palimar 13:1f05dcd9ae0e 218 if(drive_status_request){
palimar 13:1f05dcd9ae0e 219 status_string = "ON";
palimar 13:1f05dcd9ae0e 220 }
palimar 13:1f05dcd9ae0e 221 else{
palimar 13:1f05dcd9ae0e 222 status_string = "OFF";
palimar 13:1f05dcd9ae0e 223 }
palimar 13:1f05dcd9ae0e 224
palimar 13:1f05dcd9ae0e 225 for(int i = 0; i < 10; i++){
palimar 16:d2953809fb31 226 CAN_Steering_Buffer.txWrite(Txmsg_drive_status_request);
palimar 13:1f05dcd9ae0e 227 }
palimar 6:99e754ac888f 228
kiran_mbed 0:313541d8f8be 229 display.ClearScreen();
kiran_mbed 0:313541d8f8be 230 display.SelectFont(Arial12,BLACK,ReadData);
kiran_mbed 0:313541d8f8be 231 display.GotoXY(26,16);
palimar 13:1f05dcd9ae0e 232 display.PrintString("REQUEST SENT TO CHANGE DRIVE STATUS TO: ");
palimar 13:1f05dcd9ae0e 233 display.PrintString(status_string);
palimar 13:1f05dcd9ae0e 234 display.PrintString(".\n");
palimar 9:e946cafa3cae 235
palimar 13:1f05dcd9ae0e 236 printf("DRIVE STATUS CHANGE Initiated\n\r");
kiran_mbed 0:313541d8f8be 237 return;
kiran_mbed 0:313541d8f8be 238 }
kiran_mbed 0:313541d8f8be 239
palimar 9:e946cafa3cae 240 void reset()
kiran_mbed 0:313541d8f8be 241 {
palimar 16:d2953809fb31 242 CAN_Steering_Buffer.txWriteDirect(Txmsg_reset);
palimar 16:d2953809fb31 243 mbed_reset();
kiran_mbed 0:313541d8f8be 244 display.ClearScreen();
kiran_mbed 0:313541d8f8be 245 display.SelectFont(Arial12,BLACK,ReadData);
kiran_mbed 0:313541d8f8be 246 display.GotoXY(16,16);
kiran_mbed 0:313541d8f8be 247 display.PrintString(" RESET INITIATED");
kiran_mbed 0:313541d8f8be 248 printf("Reset Initiated\n\r");
kiran_mbed 0:313541d8f8be 249
kiran_mbed 0:313541d8f8be 250 return;
kiran_mbed 0:313541d8f8be 251 }
kiran_mbed 0:313541d8f8be 252
kiran_mbed 0:313541d8f8be 253 void Powerstream()
kiran_mbed 0:313541d8f8be 254 {
kiran_mbed 0:313541d8f8be 255 CANMessage Rxmsg;
kiran_mbed 0:313541d8f8be 256 float power_ratio;
kiran_mbed 0:313541d8f8be 257 ftc rcv;
kiran_mbed 0:313541d8f8be 258 rcv.FLOAT=0.0;
palimar 16:d2953809fb31 259 if(CAN_Steering_Buffer.rxRead(Rxmsg))
kiran_mbed 0:313541d8f8be 260 {
kiran_mbed 0:313541d8f8be 261 if(Rxmsg.id == BATTERY_POWER_ID)
kiran_mbed 0:313541d8f8be 262 {
palimar 6:99e754ac888f 263 for(int i=0; i<4; i++){
kiran_mbed 0:313541d8f8be 264 rcv.C_FLOAT[i]=Rxmsg.data[i];
palimar 6:99e754ac888f 265 }
kiran_mbed 0:313541d8f8be 266 power_ratio=rcv.FLOAT/80000;
kiran_mbed 0:313541d8f8be 267 ledstream.write(power_ratio);
kiran_mbed 0:313541d8f8be 268 }
kiran_mbed 0:313541d8f8be 269 }
kiran_mbed 0:313541d8f8be 270 }
kiran_mbed 0:313541d8f8be 271
kiran_mbed 0:313541d8f8be 272 void Init()
kiran_mbed 0:313541d8f8be 273 {
kiran_mbed 0:313541d8f8be 274 pc.baud(230400);
palimar 9:e946cafa3cae 275 drive_status = 0;
palimar 13:1f05dcd9ae0e 276 drive_status_request = 1;
palimar 9:e946cafa3cae 277 reset_body = 0;
kiran_mbed 0:313541d8f8be 278 ledstream.write(0);
kiran_mbed 0:313541d8f8be 279 call_ledstream.attach(&Powerstream,0.1);
kiran_mbed 0:313541d8f8be 280 }
kiran_mbed 0:313541d8f8be 281
kiran_mbed 0:313541d8f8be 282 int main()
kiran_mbed 0:313541d8f8be 283 {
palimar 4:a4fb060e7840 284 // Init all
kiran_mbed 0:313541d8f8be 285 Init();
kiran_mbed 0:313541d8f8be 286 wait(0.1);
palimar 4:a4fb060e7840 287
palimar 4:a4fb060e7840 288 //Init Display
kiran_mbed 0:313541d8f8be 289 display.GotoXY(10,16);
kiran_mbed 0:313541d8f8be 290 display.SelectFont(Arial_14,BLACK,ReadData);
kiran_mbed 0:313541d8f8be 291 display.PrintString("Penn Electric Racing");
palimar 6:99e754ac888f 292
palimar 6:99e754ac888f 293 wait(1);
palimar 4:a4fb060e7840 294
palimar 4:a4fb060e7840 295 // Start to read buttons on main thread
kiran_mbed 0:313541d8f8be 296
kiran_mbed 0:313541d8f8be 297 while(1)
kiran_mbed 0:313541d8f8be 298 {
tmccurbin 28:3ebe6db73fe0 299 if(biSWTR.read())
kiran_mbed 0:313541d8f8be 300 {
palimar 9:e946cafa3cae 301 request_status_change();
kiran_mbed 0:313541d8f8be 302 }
tmccurbin 28:3ebe6db73fe0 303 if(biSWTL.read())
kiran_mbed 0:313541d8f8be 304 {
palimar 9:e946cafa3cae 305 reset();
kiran_mbed 0:313541d8f8be 306 }
palimar 9:e946cafa3cae 307
kiran_mbed 0:313541d8f8be 308 }
kiran_mbed 0:313541d8f8be 309 }