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 04 17:57:44 2014 +0000
Revision:
7:df257df56363
Parent:
5:05f8a36b5cdd
Parent:
6:99e754ac888f
Child:
9:e946cafa3cae
Merged the two 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
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
palimar 6:99e754ac888f 197 void display_speed_data(void const *args) {
palimar 6:99e754ac888f 198 while (true) {
palimar 6:99e754ac888f 199 display.GotoXY(10,16);
palimar 6:99e754ac888f 200 display.SelectFont(Arial_14,BLACK,ReadData);
palimar 6:99e754ac888f 201 char buf[10];
palimar 6:99e754ac888f 202 int a = rand()%100;
palimar 6:99e754ac888f 203 sprintf(buf, "%d", a);
palimar 6:99e754ac888f 204 display.PrintString("Speed: ");
palimar 6:99e754ac888f 205 display.PrintString(buf);
palimar 6:99e754ac888f 206 display.PrintString("mph");
palimar 6:99e754ac888f 207 }
palimar 6:99e754ac888f 208 }
palimar 6:99e754ac888f 209
palimar 6:99e754ac888f 210
kiran_mbed 0:313541d8f8be 211 void ON()
kiran_mbed 0:313541d8f8be 212 {
kiran_mbed 0:313541d8f8be 213 Txmsg_Drive.data[0]|=(1<<0);
kiran_mbed 0:313541d8f8be 214 wait(0.1);
palimar 6:99e754ac888f 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(26,16);
kiran_mbed 0:313541d8f8be 219 display.PrintString(" ON INITIATED");
kiran_mbed 0:313541d8f8be 220 printf("ON Initiated\n\r");
kiran_mbed 0:313541d8f8be 221 //screen=0;
kiran_mbed 0:313541d8f8be 222 return;
kiran_mbed 0:313541d8f8be 223 }
kiran_mbed 0:313541d8f8be 224
kiran_mbed 0:313541d8f8be 225 void ResetCommand()
kiran_mbed 0:313541d8f8be 226 {
kiran_mbed 0:313541d8f8be 227 Txmsg_Drive.data[0]&=~(1<<0);
kiran_mbed 0:313541d8f8be 228 wait(0.1);
kiran_mbed 0:313541d8f8be 229
kiran_mbed 0:313541d8f8be 230 display.ClearScreen();
kiran_mbed 0:313541d8f8be 231 display.SelectFont(Arial12,BLACK,ReadData);
kiran_mbed 0:313541d8f8be 232 display.GotoXY(16,16);
kiran_mbed 0:313541d8f8be 233 display.PrintString(" RESET INITIATED");
kiran_mbed 0:313541d8f8be 234 printf("Reset Initiated\n\r");
kiran_mbed 0:313541d8f8be 235
kiran_mbed 0:313541d8f8be 236 return;
kiran_mbed 0:313541d8f8be 237 }
kiran_mbed 0:313541d8f8be 238
kiran_mbed 0:313541d8f8be 239 void Powerstream()
kiran_mbed 0:313541d8f8be 240 {
kiran_mbed 0:313541d8f8be 241 CANMessage Rxmsg;
kiran_mbed 0:313541d8f8be 242 float power_ratio;
kiran_mbed 0:313541d8f8be 243 ftc rcv;
kiran_mbed 0:313541d8f8be 244 rcv.FLOAT=0.0;
kiran_mbed 0:313541d8f8be 245 if(CAN_Steering.read(Rxmsg))
kiran_mbed 0:313541d8f8be 246 {
kiran_mbed 0:313541d8f8be 247 if(Rxmsg.id == BATTERY_POWER_ID)
kiran_mbed 0:313541d8f8be 248 {
palimar 6:99e754ac888f 249 for(int i=0; i<4; i++){
kiran_mbed 0:313541d8f8be 250 rcv.C_FLOAT[i]=Rxmsg.data[i];
palimar 6:99e754ac888f 251 }
kiran_mbed 0:313541d8f8be 252 power_ratio=rcv.FLOAT/80000;
kiran_mbed 0:313541d8f8be 253 ledstream.write(power_ratio);
kiran_mbed 0:313541d8f8be 254 }
kiran_mbed 0:313541d8f8be 255 }
kiran_mbed 0:313541d8f8be 256 }
kiran_mbed 0:313541d8f8be 257
kiran_mbed 0:313541d8f8be 258 void Init()
kiran_mbed 0:313541d8f8be 259 {
kiran_mbed 0:313541d8f8be 260 pc.baud(230400);
kiran_mbed 0:313541d8f8be 261 CAN_Steering.frequency(500000);
palimar 6:99e754ac888f 262 for(int i = 0; i<4; i++){
kiran_mbed 0:313541d8f8be 263 drive[i] = (0x00);
palimar 6:99e754ac888f 264 }
kiran_mbed 0:313541d8f8be 265 ledstream.write(0);
kiran_mbed 0:313541d8f8be 266 call_ledstream.attach(&Powerstream,0.1);
kiran_mbed 0:313541d8f8be 267 }
kiran_mbed 0:313541d8f8be 268
kiran_mbed 0:313541d8f8be 269 int main()
kiran_mbed 0:313541d8f8be 270 {
palimar 4:a4fb060e7840 271 // Init all
kiran_mbed 0:313541d8f8be 272 Init();
kiran_mbed 0:313541d8f8be 273 wait(0.1);
palimar 4:a4fb060e7840 274
palimar 4:a4fb060e7840 275 //Init Display
kiran_mbed 0:313541d8f8be 276 display.GotoXY(10,16);
kiran_mbed 0:313541d8f8be 277 display.SelectFont(Arial_14,BLACK,ReadData);
kiran_mbed 0:313541d8f8be 278 display.PrintString("Penn Electric Racing");
palimar 6:99e754ac888f 279
palimar 6:99e754ac888f 280 wait(1);
palimar 6:99e754ac888f 281
palimar 6:99e754ac888f 282 Thread thread(display_speed_data);
palimar 4:a4fb060e7840 283
palimar 4:a4fb060e7840 284 // Start to read buttons on main thread
kiran_mbed 0:313541d8f8be 285 screen=0;
kiran_mbed 0:313541d8f8be 286 wait(1);
kiran_mbed 0:313541d8f8be 287
kiran_mbed 0:313541d8f8be 288 while(1)
kiran_mbed 0:313541d8f8be 289 {
kiran_mbed 0:313541d8f8be 290 if(biSWBL.read())
kiran_mbed 0:313541d8f8be 291 {
kiran_mbed 0:313541d8f8be 292 ON();
tmccurbin 5:05f8a36b5cdd 293 //wait(1);
tmccurbin 5:05f8a36b5cdd 294 // HomeScreen();
kiran_mbed 0:313541d8f8be 295 }
kiran_mbed 0:313541d8f8be 296 if(biSWBR.read())
kiran_mbed 0:313541d8f8be 297 {
tmccurbin 5:05f8a36b5cdd 298 ResetCommand();
kiran_mbed 0:313541d8f8be 299 }
kiran_mbed 0:313541d8f8be 300 CAN_Steering.write(Txmsg_Drive);
kiran_mbed 0:313541d8f8be 301 wait(0.3);
kiran_mbed 0:313541d8f8be 302 }
kiran_mbed 0:313541d8f8be 303 }