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:
palimar
Date:
Sat Oct 18 17:19:43 2014 +0000
Revision:
15:da14227cdd1d
Parent:
14:3e21d6c764a5
Parent:
13:1f05dcd9ae0e
Child:
16:d2953809fb31
merged 2 tips

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 13:1f05dcd9ae0e 212
palimar 13:1f05dcd9ae0e 213 char drive_status_request = !drive_status;
palimar 13:1f05dcd9ae0e 214 char * status_string;
palimar 9:e946cafa3cae 215
palimar 13:1f05dcd9ae0e 216 if(drive_status_request){
palimar 13:1f05dcd9ae0e 217 status_string = "ON";
palimar 13:1f05dcd9ae0e 218 }
palimar 13:1f05dcd9ae0e 219 else{
palimar 13:1f05dcd9ae0e 220 status_string = "OFF";
palimar 13:1f05dcd9ae0e 221 }
palimar 13:1f05dcd9ae0e 222
palimar 13:1f05dcd9ae0e 223 for(int i = 0; i < 10; i++){
palimar 13:1f05dcd9ae0e 224 CAN_Steering.write(Txmsg_drive_status_request);
palimar 13:1f05dcd9ae0e 225 }
palimar 6:99e754ac888f 226
kiran_mbed 0:313541d8f8be 227 display.ClearScreen();
kiran_mbed 0:313541d8f8be 228 display.SelectFont(Arial12,BLACK,ReadData);
kiran_mbed 0:313541d8f8be 229 display.GotoXY(26,16);
palimar 13:1f05dcd9ae0e 230 display.PrintString("REQUEST SENT TO CHANGE DRIVE STATUS TO: ");
palimar 13:1f05dcd9ae0e 231 display.PrintString(status_string);
palimar 13:1f05dcd9ae0e 232 display.PrintString(".\n");
palimar 9:e946cafa3cae 233
palimar 13:1f05dcd9ae0e 234 printf("DRIVE STATUS CHANGE Initiated\n\r");
kiran_mbed 0:313541d8f8be 235 return;
kiran_mbed 0:313541d8f8be 236 }
kiran_mbed 0:313541d8f8be 237
palimar 9:e946cafa3cae 238 void reset()
kiran_mbed 0:313541d8f8be 239 {
kiran_mbed 0:313541d8f8be 240 display.ClearScreen();
kiran_mbed 0:313541d8f8be 241 display.SelectFont(Arial12,BLACK,ReadData);
kiran_mbed 0:313541d8f8be 242 display.GotoXY(16,16);
kiran_mbed 0:313541d8f8be 243 display.PrintString(" RESET INITIATED");
kiran_mbed 0:313541d8f8be 244 printf("Reset Initiated\n\r");
kiran_mbed 0:313541d8f8be 245
kiran_mbed 0:313541d8f8be 246 return;
kiran_mbed 0:313541d8f8be 247 }
kiran_mbed 0:313541d8f8be 248
kiran_mbed 0:313541d8f8be 249 void Powerstream()
kiran_mbed 0:313541d8f8be 250 {
kiran_mbed 0:313541d8f8be 251 CANMessage Rxmsg;
kiran_mbed 0:313541d8f8be 252 float power_ratio;
kiran_mbed 0:313541d8f8be 253 ftc rcv;
kiran_mbed 0:313541d8f8be 254 rcv.FLOAT=0.0;
kiran_mbed 0:313541d8f8be 255 if(CAN_Steering.read(Rxmsg))
kiran_mbed 0:313541d8f8be 256 {
kiran_mbed 0:313541d8f8be 257 if(Rxmsg.id == BATTERY_POWER_ID)
kiran_mbed 0:313541d8f8be 258 {
palimar 6:99e754ac888f 259 for(int i=0; i<4; i++){
kiran_mbed 0:313541d8f8be 260 rcv.C_FLOAT[i]=Rxmsg.data[i];
palimar 6:99e754ac888f 261 }
kiran_mbed 0:313541d8f8be 262 power_ratio=rcv.FLOAT/80000;
kiran_mbed 0:313541d8f8be 263 ledstream.write(power_ratio);
kiran_mbed 0:313541d8f8be 264 }
kiran_mbed 0:313541d8f8be 265 }
kiran_mbed 0:313541d8f8be 266 }
kiran_mbed 0:313541d8f8be 267
kiran_mbed 0:313541d8f8be 268 void Init()
kiran_mbed 0:313541d8f8be 269 {
kiran_mbed 0:313541d8f8be 270 pc.baud(230400);
kiran_mbed 0:313541d8f8be 271 CAN_Steering.frequency(500000);
palimar 9:e946cafa3cae 272 drive_status = 0;
palimar 13:1f05dcd9ae0e 273 drive_status_request = 1;
palimar 9:e946cafa3cae 274 reset_body = 0;
kiran_mbed 0:313541d8f8be 275 ledstream.write(0);
kiran_mbed 0:313541d8f8be 276 call_ledstream.attach(&Powerstream,0.1);
kiran_mbed 0:313541d8f8be 277 }
kiran_mbed 0:313541d8f8be 278
kiran_mbed 0:313541d8f8be 279 int main()
kiran_mbed 0:313541d8f8be 280 {
palimar 4:a4fb060e7840 281 // Init all
kiran_mbed 0:313541d8f8be 282 Init();
kiran_mbed 0:313541d8f8be 283 wait(0.1);
palimar 4:a4fb060e7840 284
palimar 4:a4fb060e7840 285 //Init Display
kiran_mbed 0:313541d8f8be 286 display.GotoXY(10,16);
kiran_mbed 0:313541d8f8be 287 display.SelectFont(Arial_14,BLACK,ReadData);
kiran_mbed 0:313541d8f8be 288 display.PrintString("Penn Electric Racing");
palimar 6:99e754ac888f 289
palimar 6:99e754ac888f 290 wait(1);
palimar 4:a4fb060e7840 291
palimar 4:a4fb060e7840 292 // Start to read buttons on main thread
kiran_mbed 0:313541d8f8be 293
kiran_mbed 0:313541d8f8be 294 while(1)
kiran_mbed 0:313541d8f8be 295 {
kiran_mbed 0:313541d8f8be 296 if(biSWBL.read())
kiran_mbed 0:313541d8f8be 297 {
palimar 9:e946cafa3cae 298 request_status_change();
kiran_mbed 0:313541d8f8be 299 }
kiran_mbed 0:313541d8f8be 300 if(biSWBR.read())
kiran_mbed 0:313541d8f8be 301 {
palimar 9:e946cafa3cae 302 reset();
kiran_mbed 0:313541d8f8be 303 }
palimar 9:e946cafa3cae 304
kiran_mbed 0:313541d8f8be 305 }
kiran_mbed 0:313541d8f8be 306 }