Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: CANBuffer KS0108_fork mbed-rtos mbed CAN Addresses
Fork of REVO_Updated_Steering by
Revision 23:6681a38918c6, committed 2014-11-13
- Comitter:
- palimar
- Date:
- Thu Nov 13 23:45:12 2014 +0000
- Parent:
- 21:56890c41ecf1
- Child:
- 24:ba3428215006
- Commit message:
- Major Milestone 1: Reset and Start/Stop Functionality works!
Changed in this revision
--- a/CANBuffer.lib Sat Oct 25 17:24:58 2014 +0000 +++ b/CANBuffer.lib Thu Nov 13 23:45:12 2014 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/teams/Penn-Electric-Racing/code/CANBuffer/#110f268af846 +http://developer.mbed.org/teams/Penn-Electric-Racing/code/CANBuffer/#4baa7251c6c0
--- a/CAN_Filter_LUT.h Sat Oct 25 17:24:58 2014 +0000
+++ b/CAN_Filter_LUT.h Thu Nov 13 23:45:12 2014 +0000
@@ -38,7 +38,7 @@
// STANDARD ID RANGES - CAN CONTROLLER 2
//( 0xLOWERBOUND & STDMASK | 1<<13) << 16 | ( 0xUPPERBOUND & STDMASK | 1<<13), lower/upperbounds are inclusive
- ( 0x400 & STDMASK | 1<<13) << 16 | ( 0x4FF & STDMASK | 1<<13), // Index1
+//( 0x400 & STDMASK | 1<<13) << 16 | ( 0x4FF & STDMASK | 1<<13), // Index1
};
const uint32_t AF_LUT_EEI[] = {
--- a/Steering.cpp Sat Oct 25 17:24:58 2014 +0000
+++ b/Steering.cpp Thu Nov 13 23:45:12 2014 +0000
@@ -1,226 +1,23 @@
#include "Steering.h"
-void HomeScreen()
-{
-
- ftc rcv;
- rcv.FLOAT=0.0;
- char dat[4];
- float power_ratio=0.0;
- printf("Homescreen\n\r");
- display.ClearScreen();
- display.SelectFont(Arial12,BLACK,ReadData);
- display.GotoXY(0,0);
- display.PrintString(" HOME SCREEN");
- while( !(biSWTL.read() || biSWTR.read() || biSWBR.read()) )
- {
- CANMessage Rxmsg;
- if(CAN_Steering_Buffer.rxRead(Rxmsg))
- {
- for(int i=0; i<4; i++)
- rcv.C_FLOAT[i]=Rxmsg.data[i];
- if(Rxmsg.id == BATTERY_VOLTAGE_ID)
- {
- display.GotoXY(0,16);
- display.PrintString(" PV: ");
- sprintf(dat,"%2.2f",rcv.FLOAT);
- display.PrintString(dat);
- display.PrintString("V");
- }
- if(Rxmsg.id == BATTERY_POWER_ID)
- {
- display.GotoXY(64,16);
- display.PrintString(" PP: ");
- power_ratio=rcv.FLOAT/10000;
- sprintf(dat,"%2.2f",power_ratio);
- display.PrintString(dat);
- display.PrintString("kW");
- }
- if(Rxmsg.id == PCM_STATE_ID)
- {
- display.GotoXY(0,32);
- display.PrintString(" STATE: ");
- display.PrintNumber(rcv.FLOAT);
- }
- }
- }
- return;
-}
+bool NOT_biSWBL_HELD;
-void AMSScreen1()
-{
- CANMessage Rxmsg;
- ftc rcv;
- char dat[4];
- rcv.FLOAT=0.0;
- printf("AMSScreen1");
- display.ClearScreen();
- display.SelectFont(Arial12,BLACK,ReadData);
- while( !(biSWTL.read() || biSWTR.read() || biSWBL.read()) )
- {
- printf("iN LOOP1");
- if(CAN_Steering_Buffer.rxRead(Rxmsg))
- {
- for(int i=0; i<4; i++)
- rcv.C_FLOAT[i]=Rxmsg.data[i];
- if(Rxmsg.id == BATTERY_VOLTAGE_ID)
- {
- display.GotoXY(0,0);
- display.PrintString(" pv: ");
- sprintf(dat,"%2.2f",rcv.FLOAT);
- display.PrintString(dat);
- }
- if(Rxmsg.id == BATTERY_POWER_ID)
- {
- display.GotoXY(0,16);
- display.PrintString(" pp: ");
- sprintf(dat,"%2.2f",rcv.FLOAT);
- display.PrintString(dat);
- }
- if(Rxmsg.id == BATTERY_CURRENT_ID)
- {
- display.GotoXY(0,32);
- display.PrintString(" pi: ");
- sprintf(dat,"%2.2f",rcv.FLOAT);
- display.PrintString(dat);
- }
-
- //Column 2
- if(Rxmsg.id == BATTERY_MIN_CELLVOLTAGE_ID)
- {
- display.GotoXY(49,0);
- display.PrintString(" min cell V: ");
- sprintf(dat,"%2.2f",rcv.FLOAT);
- display.PrintString(dat);
- }
- if(Rxmsg.id == BATTERY_MAX_CELLVOLTAGE_ID)
- {
- display.GotoXY(49,16);
- display.PrintString(" max cell V: ");
- sprintf(dat,"%2.2f",rcv.FLOAT);
- display.PrintString(dat);
- }
- if(Rxmsg.id == BATTERY_AVG_CELLVOLTAGE_ID)
- {
- display.GotoXY(49,32);
- display.PrintString(" avg cell V: ");
- sprintf(dat,"%2.2f",rcv.FLOAT);
- display.PrintString(dat);
- }
- }
- screen=1;
- }
- return;
-}
+void request_status_change(){
+
+ char drive_status_request;
+ ds_mutex.lock();
+ drive_status_request = !drive_status;
+ ds_mutex.unlock();
+ char * status_string;
-void AMSScreen2()
-{
- CANMessage Rxmsg;
- ftc rcv;
- char dat[4];
- //ftc send;
- rcv.FLOAT=0.0;
- //send.FLOAT=65.6432;
- printf("AMSScreen2\n\r");
- display.ClearScreen();
- display.SelectFont(Arial12,BLACK,ReadData);
- while( !(biSWTL.read() || biSWTR.read() || biSWBL.read()) )
- {
- printf("iN LOOP2");
- if(CAN_Steering_Buffer.rxRead(Rxmsg))
- {
- for(int i=0; i<4; i++)
- rcv.C_FLOAT[i]=Rxmsg.data[i];
- if(Rxmsg.id == BATTERY_MIN_CELLTEMPERATURE_ID)
- {
- display.GotoXY(0,0);
- display.PrintString(" mn cll T: ");
- sprintf(dat,"%2.2f",rcv.FLOAT);
- display.PrintString(dat);
- }
- if(Rxmsg.id == BATTERY_MAX_CELLTEMPERATURE_ID)
- {
- display.GotoXY(0,16);
- display.PrintString(" mx cll T: ");
- sprintf(dat,"%2.2f",rcv.FLOAT);
- display.PrintString(dat);
- }
- if(Rxmsg.id == BATTERY_AVG_CELLTEMPERATURE_ID)
- {
- display.GotoXY(0,32);
- display.PrintString(" avg cell T: ");
- sprintf(dat,"%2.2f",rcv.FLOAT);
- display.PrintString(dat);
- }
-
- //Column 2
- if(Rxmsg.id == AMS_BATTERY_STATE)
- {
- if((rcv.C_FLOAT[0] & 0xC0) == 0xC0)
- {
- display.GotoXY(70,0);
- display.PrintString(" AIRS: ");
- display.PrintString("CLOS");
- }
- else
- {
- display.GotoXY(70,0);
- display.PrintString(" AIRS: ");
- display.PrintString("OPEN");
- }
-
- if((rcv.C_FLOAT[0] & 0x04) == 0x04)
- {
- display.GotoXY(70,16);
- display.PrintString(" Prchrg: ");
- display.PrintString("on");
- }
- else
- {
- display.GotoXY(70,16);
- display.PrintString(" Prchrg: ");
- display.PrintString("off");
- }
- }
- if(Rxmsg.id == AMS_BATTERY_STATE)
- {
- display.GotoXY(70,16);
- display.PrintString(" Prchrg: ");
- display.PrintString("off");
- }
- }
- screen=0;
- }
- return;
-}
-
-void display_speed_data(void const *args) {
- while (true) {
- display.GotoXY(10,16);
- display.SelectFont(Arial_14,BLACK,ReadData);
- char buf[10];
- int a = rand()%100;
- sprintf(buf, "%d", a);
- display.PrintString("Speed: ");
- display.PrintString(buf);
- display.PrintString("mph");
- }
-}
-
-
-void request_status_change()
-{
-
- char drive_status_request = !drive_status;
- char * status_string;
-
if(drive_status_request){
status_string = "ON";
}
else{
status_string = "OFF";
}
-
+
+ CANMessage Txmsg_drive_status_request(0x501,&drive_status_request,1);
for(int i = 0; i < 10; i++){
CAN_Steering_Buffer.txWrite(Txmsg_drive_status_request);
}
@@ -229,69 +26,69 @@
display.SelectFont(Arial12,BLACK,ReadData);
display.GotoXY(26,16);
display.PrintString("DRIVE STATUS REQUEST");
-
+
printf("%s\n\r", status_string);
return;
}
void reset()
{
- CAN_Steering_Buffer.txWriteDirect(Txmsg_reset);
- mbed_reset();
+ reset_body = 1;
+ CANMessage Txmsg_reset(0x502,&reset_body,1);
+ for(int i = 0; i < 10; i++){
+ CAN_Steering_Buffer.txWriteDirect(Txmsg_reset);
+ }
+ NVIC_SystemReset();
display.ClearScreen();
display.SelectFont(Arial12,BLACK,ReadData);
display.GotoXY(16,16);
display.PrintString(" RESET INITIATED");
printf("Reset Initiated\n\r");
-
+
return;
}
-void Powerstream()
-{
- CANMessage Rxmsg;
- float power_ratio;
- ftc rcv;
- rcv.FLOAT=0.0;
- if(CAN_Steering_Buffer.rxRead(Rxmsg))
- {
- if(Rxmsg.id == BATTERY_POWER_ID)
- {
- for(int i=0; i<4; i++){
- rcv.C_FLOAT[i]=Rxmsg.data[i];
- }
- power_ratio=rcv.FLOAT/80000;
- ledstream.write(power_ratio);
- }
- }
-}
-
void Init()
{
- pc.baud(230400);
+ pc.baud(921600);
drive_status = 0;
drive_status_request = 1;
reset_body = 0;
ledstream.write(0);
- call_ledstream.attach(&Powerstream,0.1);
+ NOT_biSWBL_HELD = true;
}
-void update_vars(void const *args) {
+void read_messages(void const *args) {
while (true) {
CANMessage Rxmsg;
- if(CAN_Steering_Buffer.rxRead(Rxmsg)){
- if(Rxmsg.id == PCM_STATE_ID){
- ds_mutex.lock();
- drive_status = Rxmsg.data[0];
- ds_mutex.unlock();
+
+ if(CAN_Steering_Buffer.rxRead(Rxmsg))
+ if(Rxmsg.id == PCM_STATE_ID){
+
+ // Mutex to protex shared variables
+ ds_mutex.lock();
+ drive_status = Rxmsg.data[0];
+ ds_mutex.unlock();
+ }
+
+ if(Rxmsg.id == BATTERY_POWER_ID)
+ {
+ float power_ratio;
+ ftc rcv;
+ rcv.FLOAT=0.0;
+
+ for(int i=0; i<4; i++){
+ rcv.C_FLOAT[i] = Rxmsg.data[i];
}
+ power_ratio=rcv.FLOAT/80000;
+ ledstream.write(power_ratio);
+ }
}
}
}
-int main()
-{
- // Init all
+int main(){
+ // Initialize, set all variables.
Init();
wait(0.1);
@@ -299,23 +96,35 @@
display.GotoXY(10,16);
display.SelectFont(Arial_14,BLACK,ReadData);
display.PrintString("Penn Electric Racing");
+ CAN_Steering_Buffer.mode(NoAck);
- Thread update_thread(update_vars);
-
+ //New thread to read messages.
+ Thread update_thread(read_messages);
+ update_thread.set_priority(osPriorityLow
+
+
wait(1);
// Start to read buttons on main thread
-
while(1)
{
- if(biSWBL.read())
- {
+ if(biSWBL.read() && NOT_biSWBL_HELD){
request_status_change();
+ NOT_biSWBL_HELD = false;
}
- if(biSWBR.read())
- {
+
+ else if(!biSWBL.read()){
+ NOT_biSWBL_HELD = true;
+ }
+
+ else{
+ // ignore BiSWBL.read()
+ }
+
+
+ if(biSWBR.read()){
reset();
}
-
}
}
+
--- a/Steering.h Sat Oct 25 17:24:58 2014 +0000 +++ b/Steering.h Thu Nov 13 23:45:12 2014 +0000 @@ -31,13 +31,11 @@ #define AMS_BATTERY_STATE 0x30E // AIRS 7 and 6 // Precharge 3 Serial pc(USBTX,USBRX); -CANBuffer CAN_Steering_Buffer(CAN1,MEDIUM); -LPCDigitalOut CAN_Silent(p3_26, 0); +CANBuffer CAN_Steering_Buffer(CAN1, MEDIUM, p3_26); -extern "C" void mbed_reset(); KS0108 display(p26, p21, p22, p23, p25, p24, p8, p7, p6, p5, p13, p14, p12, p11); -Ticker call_ledstream; +//Ticker call_ledstream; LPCDigitalOut l1(p1_28,1);// SW2 LPCDigitalOut l2(p1_26,1);// SW4 @@ -108,8 +106,7 @@ char drive_status_request; char reset_body; -CANMessage Txmsg_drive_status_request(0x501,&drive_status_request,1); -CANMessage Txmsg_reset(0x502,&reset_body,1); + Mutex ds_mutex;
--- a/mbed.bld Sat Oct 25 17:24:58 2014 +0000 +++ b/mbed.bld Thu Nov 13 23:45:12 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/031413cf7a89 \ No newline at end of file
