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 18 17:05:45 2014 +0000
Revision:
12:e99a0f23e91a
Parent:
10:493f2151d5f1
Child:
14:3e21d6c764a5
Added soft reset command:; mbed_reset();

Who changed what in which revision?

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