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: SPI_TFTx2_ILI9341 TFT_fonts TOUCH_TFTx2_ILI9341 mbed
Fork of CANary_corrupt by
Revision 149:e9739523109f, committed 2013-09-25
- Comitter:
- TickTock
- Date:
- Wed Sep 25 03:33:18 2013 +0000
- Parent:
- 148:6e3b9135fad2
- Child:
- 150:ef46ce63345c
- Commit message:
- Compensated DTE with air drag of current ambient temperature.
Changed in this revision
--- a/displayModes.cpp Thu Sep 12 14:42:22 2013 +0000
+++ b/displayModes.cpp Wed Sep 25 03:33:18 2013 +0000
@@ -7,7 +7,7 @@
void mainDisplay (bool force, bool showButtons){
unsigned short gids, SOC_x10, packV_x2, tireP;
float useable_kWh,dte;
- unsigned char aTemp;
+ //unsigned char aTemp;
static unsigned short lgids=0, lSOC=0, lpackV_x2=0, ltireP=0;
static unsigned char laTemp=0;
static float lmaxTemp=0, lkW=0, laccV=0, lmpkWh=0;
@@ -20,12 +20,7 @@
SOC_x10 = (msg.data[0]<<2)+(msg.data[1]>>6);
msg = lastMsg[indexLastMsg[0x1db]]; //Get pack volts
packV_x2 = (msg.data[2]<<2)+(msg.data[3]>>6);
- msg = lastMsg[indexLastMsg[0x54c]]; //Get ambient
- aTemp = msg.data[6]-56;
- //msg = lastMsg[indexLastMsg[0x79a]]; //Get ambient and cabin temperature
- //aTemp = msg.data[5]-41; // Need to add convertsion to C if metric
- //c1Temp = msg.data[4]-41;
- //c2Temp = msg.data[6]-41;
+
msg = lastMsg[indexLastMsg[0x385]]; //Get tire pressure
tireP = msg.data[2]+msg.data[3]+msg.data[4]+msg.data[5];
@@ -46,7 +41,7 @@
printf("%4.1f kWh \n",useable_kWh);
// Display DTE
- dte=convertDistance(minTripEff*useable_kWh);
+ dte=convertDistance(minTripEff*nomDrag/airDrag(ambient_F)*useable_kWh);
tt.foreground(Green);
tt.locate(20,80);
if(dte>=9.5){
@@ -57,7 +52,8 @@
tt.set_font((unsigned char*) SCProSB31x55);
tt.foreground(Yellow);
- dte=convertDistance(mpkWh[dtePeriod]*useable_kWh);
+ //Totest:convert from 25C to current ambient temperature
+ dte=convertDistance(mpkWh[dtePeriod]);
if(dte>199){
dte=199;
}
@@ -76,7 +72,7 @@
tt.locate(195,106);
printf("%s\n",distanceUnit()); //LM - add metric conversion
- dte=convertDistance(maxTripEff*useable_kWh);
+ dte=convertDistance(maxTripEff*nomDrag/airDrag(ambient_F)*useable_kWh);
tt.foreground(Orange);
if(dte>=99.5){
tt.locate(255,80);
@@ -121,11 +117,11 @@
lpackV_x2=packV_x2;
ltireP=0;//Force tire pressure redraw, too
}
- if(force||aTemp!=laTemp){
+ if(force||ambient_F!=laTemp){
tt.foreground(Cyan);
tt.locate(20,146);
- printf("%2.0f%s\n",convertF(aTemp),temperatureUnit());
- laTemp=aTemp;
+ printf("%2.0f%s\n",convertF(ambient_F),temperatureUnit());
+ laTemp=ambient_F;
}
if(force||maxTemp!=lmaxTemp){
tt.foreground(Cyan);
@@ -1139,6 +1135,7 @@
tt.set_font((unsigned char*) SCProSB31x55);
tt.foreground(Green);
if (showMiles){
+ //Totest:convert from 25C to current ambient temperature
float miles = mpkWh[dtePeriod]*((float)(gids-5)*.075);
miles = convertDistance(miles); // LM - Metric support
// Right justify
@@ -1155,9 +1152,11 @@
tt.foreground(Cyan);
tt.set_font((unsigned char*) Arial24x23);
tt.locate(198,70);
+ //Totest:convert from 25C to current ambient temperature
printf("%3.1f \n",mpkWh[dtePeriod]);
} else {
tt.locate(200,10);
+ //Totest:convert from 25C to current ambient temperature
printf("%3.1f \n",mpkWh[dtePeriod]);
tt.foreground(Cyan);
tt.set_font((unsigned char*) Arial24x23);
@@ -1272,7 +1271,8 @@
}
if(pointerSep>maxPS){maxPS=pointerSep;}
tt.locate(10,10);
- printf("%3d sep %3d max\n",pointerSep,maxPS);
+ //printf("%3d sep %3d max\n",pointerSep,maxPS);
+ printf("%f %4.3f \n", ambient_F, airDrag(ambient_F));
tt.locate(10,40);
printf("%4.2fV %4.2fV \n",accV,accV2);
for (i=0; i<4; i++){
@@ -1498,7 +1498,7 @@
float convertC(float input)
{
if (!metric) {
- //convert!
+ //convert C to F!
float output = input *1.8f;
output += 32.0f;
return output;
@@ -1509,7 +1509,7 @@
float convertF(float input)
{
if (metric) {
- //convert!
+ //convert F to C!
float output = input -32.0f;
output /= 1.8f;
return output;
@@ -1535,3 +1535,4 @@
return "C";
return "F";
}
+
--- a/displayModes.h Thu Sep 12 14:42:22 2013 +0000
+++ b/displayModes.h Wed Sep 25 03:33:18 2013 +0000
@@ -63,6 +63,8 @@
extern bool brakeMon;
extern float curEff;
extern unsigned short uMsgId[8];
+extern float ambient_F;
+extern float nomDrag;
extern "C" {
void printLast (bool force, bool showButtons);
@@ -82,6 +84,7 @@
float convertDistance(float input); // LM - Metric
float convertC(float input); // LM - Metric
float convertF(float input); // LM - Metric
+ float airDrag(float F);
char* distanceUnit(); // LM - Metric
char* temperatureUnit(); // LM - Metric
}
\ No newline at end of file
--- a/main.cpp Thu Sep 12 14:42:22 2013 +0000
+++ b/main.cpp Wed Sep 25 03:33:18 2013 +0000
@@ -5,20 +5,18 @@
// * Add 50% charge option
// * Add coasting regen to regen/braking display
// * Change semilog efficiency graph to linear with 10 minute values
-// * Add additional 79b bank readouts
// * Subtract accessory power from efficiency history (add back in when displaying)
-// * Add trip history display
// * Add in-device config editor
-// * Add temperature to efficiency lookup table
-// * Add debug screen
+// * Normalize efficiency to 25C relative to ambient. Display efficiency at current temp.
+// * Change pack volt color when CVLI fails
+// * Add per-charge efficiency meter; add to triplop.txt
+// * Add tire pressure cal (40psi for me = FR 38, RR 38.2, FL 37.8, RL 38 - maybe 2psi error on my tire gauge?)
+// * Add heater activation warning message
+// * Add trip efficiency reset
-// rev148
-// No longer save config after firmware update
-// Added config health check after read
-// Added debugScreen
-// Switched friction monitor to msgId:292 so MY2013 will work
-// Added ambient to main display
-// Added Resr to trip log
+
+// rev149
+// Added temperature compensation for efficiency/DTE computation
#include "mbed.h"
#include "CAN.h"
@@ -29,7 +27,7 @@
#include "utility.h"
#include "displayModes.h"
#include "TOUCH_TFTx2.h"
-char revStr[7] = "148"; // gg - revision string, max 6 characters
+char revStr[7] = "149"; // gg - revision string, max 6 characters
FATFS USBdrive;
LocalFileSystem local("local");
@@ -135,6 +133,7 @@
float mph[39]={0};
float kW[39]={0};
float mpkWh[39]={0};
+float ambient_F;
float unloadedV_x2,Resr,curRmax,curRmin,redRmax,redRmin,incRmax,incRmin;
signed short Imax, Imin;
// Logarithmic division scale (roughly - snapped to common units of time)
@@ -158,6 +157,7 @@
bool moving=false;
unsigned short chirpInt;
unsigned short uMsgId[8] = {0x5103, 0x50a3, 0x54a4, 0x54b4, 0x54c0, 0x55b4, 0x0000, 0x0000}; // messages to display on debug screen msgId:byte
+float nomDrag;
int main() {
char sTemp[40];
@@ -205,7 +205,9 @@
printMsg(sTemp); // revision
//read efficiency history data
- hfile = fopen("/local/ehist.cny", "r");
+ if(!tt.is_touched()){ //skip if screen touched (reset efficiency)
+ hfile = fopen("/local/ehist.cny", "r");
+ }
if (hfile!=NULL){ // found a efficiency history file
for(i=0;i<39;i++){
if(!feof(hfile)){
@@ -227,6 +229,8 @@
mpkWh[i]=4;
}
}
+
+ nomDrag = airDrag(77); // Compute drag coefficient for 25C
// Read config file
readConfig();
@@ -709,6 +713,7 @@
if(tick){ // Executes once a second
tick=false;
+ ambient_F = lastMsg[indexLastMsg[0x54c]].data[6]-56;
curEff = miles_trip[0]/kWh_trip[0];
headlights = (lastMsg[indexLastMsg[0x358]].data[1]&0x80)?true:false; // headlight/turn signal indicator
if(accOn&&indexLastMsg[0x355]>0){
@@ -805,7 +810,7 @@
if(numWsamples>0){ // Avoid div0
mpkWh[0]=mph[0];
- kW[0]=((float) mWs_x4)/numWsamples/4e3;
+ kW[0]=((float) mWs_x4)/numWsamples/4e3;
mpkWh[0]/=kW[0];
if (mpkWh[0]<0) {
mpkWh[0]=99;// negative means inf.
@@ -814,6 +819,8 @@
kW[0]=0;
mpkWh[0]=0;
}
+ // TOTest: Normalize kW[0] to 25C (after computing mpkWh[0])
+ kW[0]=kW[0]/airDrag(ambient_F)*nomDrag;
numWsamples=0;
if (!charging){
--- a/utility.cpp Thu Sep 12 14:42:22 2013 +0000
+++ b/utility.cpp Wed Sep 25 03:33:18 2013 +0000
@@ -517,7 +517,7 @@
char buffer[bufSize];
cfile = fopen("/local/config.txt", "w");
- fprintf(cfile,"format 7\r\n");
+ fprintf(cfile,"format 8\r\n");
fprintf(cfile,"x0_off %d\r\n",tt.x0_off);
fprintf(cfile,"y0_off %d\r\n",tt.y0_off);
fprintf(cfile,"x0_pp %d\r\n",tt.x0_pp);
@@ -547,7 +547,10 @@
fprintf(cfile,"showHealth %d\r\n",(showHealth?1:0));
fprintf(cfile,"brakeMon %d\r\n",(brakeMon?1:0));
fprintf(cfile,"brkMonRate %d\r\n", brkMonRate );
- fprintf(cfile,"brkMonThr %d\r\n", brkMonThr );
+ fprintf(cfile,"brkMonThr %d\r\n", brkMonThr );
+ for(char i=0;i<8;i++){
+ fprintf(cfile,"usrMsgId %4x\r\n", i, uMsgId[i] );
+ }
fclose(cfile);
// Make copy of CONFIG.TXT
@@ -631,8 +634,13 @@
fscanf(cfile, "brkMonRate %d\r\n", &brkMonRate );
fscanf(cfile, "brkMonThr %d\r\n", &brkMonThr );
}
+ if(ff>7){
+ for(char i=0;i<8;i++){
+ fscanf(cfile, "usrMsgId %4x\r\n", &uMsgId[i] );
+ }
+ }
fclose(cfile);
- if((ff>7)||(ff<1)||(ledHi<0.1)||(scale12V<10)||(tt.x_mid<16000)||(ledHi>1)||(ledLo>1)||(dMode[0]>maxScreens)||(dMode[1]>maxScreens)){ //Sanity check a few things
+ if((ff>8)||(ff<1)||(ledHi<0.1)||(scale12V<10)||(tt.x_mid<16000)||(ledHi>1)||(ledLo>1)||(dMode[0]>maxScreens)||(dMode[1]>maxScreens)){ //Sanity check a few things
//Something wrong. Load defaults
printf("Invalid config file. Loading defaults.\n");
wait(3);
@@ -661,7 +669,16 @@
brakeMon=true;
brkMonRate=400000;
brkMonThr=4000;
+ uMsgId[0]=0x5103;
+ uMsgId[1]=0x50a3;
+ uMsgId[2]=0x54a4;
+ uMsgId[3]=0x54b4;
+ uMsgId[4]=0x54c0;
+ uMsgId[5]=0x55b4;
+ uMsgId[6]=0x0000;
+ uMsgId[7]=0x0000;
}
+
if(ff<7){//If not latest format, save as latest format
saveConfig();
printMsg("Config file format updated.\n"); // config forat updates
@@ -981,6 +998,20 @@
}
}
+float airDrag(float F)
+{
+ float drag_F[16] = {1.47,1.39,1.363,1.337,1.312,1.288,1.265,1.243,1.221,1.2,1.18,1.161,1.142,1.124,1.106,1.034};
+ float temp_F[16] = {-31,-4,5,14,23,32,41,50,59,68,77,86,95,104,113,149};
+ char ii=0;
+ float drag;
+ while(ambient_F<=temp_F[++ii]) { } // Find section in table
+ drag=(ambient_F-temp_F[ii]);
+ drag/=(temp_F[ii-1]-temp_F[ii]);
+ drag*=(drag_F[ii-1]-drag_F[ii]);
+ drag+=drag_F[ii];
+ return drag;
+}
+
//Sample CONFIG.TXT
/*
format 7
@@ -1008,4 +1039,4 @@
brakeMon 1
brkMonRate 400000
brkMonThr 4000
-*/
\ No newline at end of file
+*/
--- a/utility.h Thu Sep 12 14:42:22 2013 +0000
+++ b/utility.h Wed Sep 25 03:33:18 2013 +0000
@@ -76,6 +76,8 @@
extern bool brakeMon;
extern Ticker geiger;
extern unsigned short chirpInt;
+extern unsigned short uMsgId[8];
+extern float ambient_F;
extern "C" {
void mbed_reset();
@@ -104,6 +106,7 @@
void updateFirmware(); // LM - Update firmware off USB
bool detectUSB();
void chirp();
+ float airDrag(float);
}
//LEAF OBD
