fix serial data display

This commit is contained in:
interfisch 2021-03-26 17:02:23 +01:00
parent 994571b60e
commit 8c42a7ffd0
1 changed files with 42 additions and 34 deletions

View File

@ -45,6 +45,8 @@ Table logdata;
int nextID=0; //next row number to be displayed
long nextTime=0; //time of nextID row
int dataErrorCount=0;
//Data from log
int cmd_FrontL;
int cmd_FrontR;
@ -193,35 +195,37 @@ void draw() {
if (useSerial) {
while (serial.available() > 0) {
println("readUntilLoop");
serialString = serial.readStringUntil(serial_endchar);
println("read:"+serialString);
//println("read:"+serialString);
if (serialString != null) {
println(serialString);
lastTimeData=nextTime;
nextTime=loopmillis;
String[] list = split(serialString, ',');
cmd_FrontL=parseInt(list[0]);
cmd_FrontR=parseInt(list[1]);
cmd_RearL=parseInt(list[2]);
cmd_RearR=parseInt(list[3]);
current_FrontL=parseFloat(list[4]);
current_FrontR=parseFloat(list[5]);
current_RearL=parseFloat(list[6]);
current_RearR=parseFloat(list[7]);
speed_FrontL=parseInt(list[8]);
speed_FrontR=parseInt(list[9]);
speed_RearL=parseInt(list[10]);
speed_RearR=parseInt(list[11]);
temp_Front=parseFloat(list[12]);
temp_Rear=parseFloat(list[13]);
vbat_Front=parseFloat(list[14]);
vbat_Rear=parseFloat(list[15]);
currentAll=parseFloat(list[16]);
throttle=parseInt(list[17]);
brake=parseInt(list[18]);
if (list.length==20) {
lastTimeData=nextTime;
nextTime=int(parseFloat(list[0])*1000);
cmd_FrontL=parseInt(list[1]);
cmd_FrontR=parseInt(list[2]);
cmd_RearL=parseInt(list[3]);
cmd_RearR=parseInt(list[4]);
current_FrontL=parseFloat(list[5]);
current_FrontR=parseFloat(list[6]);
current_RearL=parseFloat(list[7]);
current_RearR=parseFloat(list[8]);
speed_FrontL=parseInt(list[9]);
speed_FrontR=parseInt(list[10]);
speed_RearL=parseInt(list[11]);
speed_RearR=parseInt(list[12]);
temp_Front=parseFloat(list[13]);
temp_Rear=parseFloat(list[14]);
vbat_Front=parseFloat(list[15]);
vbat_Rear=parseFloat(list[16]);
currentAll=parseFloat(list[17]);
throttle=parseInt(list[18]);
brake=parseInt(list[19]);
}else{ //data missing or too much
dataErrorCount++;
}
}
}
@ -275,10 +279,10 @@ void draw() {
vis_speed_RearL.setValue(speed_RearL); vis_speed_RearL.drawVis();
vis_speed_RearR.setValue(speed_RearR); vis_speed_RearR.drawVis();
vis_current_FrontL.setValue(-current_FrontL); vis_current_FrontL.drawVis(); //TODO: remove negative sign
vis_current_FrontR.setValue(-current_FrontR); vis_current_FrontR.drawVis(); //TODO: remove negative sign
vis_current_RearL.setValue(-current_RearL); vis_current_RearL.drawVis(); //TODO: remove negative sign
vis_current_RearR.setValue(-current_RearR); vis_current_RearR.drawVis(); //TODO: remove negative sign
vis_current_FrontL.setValue(current_FrontL); vis_current_FrontL.drawVis();
vis_current_FrontR.setValue(current_FrontR); vis_current_FrontR.drawVis();
vis_current_RearL.setValue(current_RearL); vis_current_RearL.drawVis();
vis_current_RearR.setValue(current_RearR); vis_current_RearR.drawVis();
vis_throttle.setValue(throttle); vis_throttle.drawVis();
vis_brake.setValue(-brake); vis_brake.drawVis();
@ -286,10 +290,10 @@ void draw() {
int speed_mean=int((speed_FrontL+speed_FrontR+speed_RearL+speed_RearR)/4.0);
vis_c_speed_mean.setValue(speed_mean); vis_c_speed_mean.drawVis();
vis_currentAll.setValue(-currentAll); vis_currentAll.drawVis(); //TODO: remove negative sign
vis_currentAll.setValue(currentAll); vis_currentAll.drawVis();
vis_graph_speed_mean.setValue(speed_mean); vis_graph_speed_mean.drawVis();
vis_graph_currentAll.setValue(-currentAll); vis_graph_currentAll.drawVis();
vis_graph_currentAll.setValue(currentAll); vis_graph_currentAll.drawVis();
@ -304,19 +308,23 @@ void draw() {
PVector pos_voltage = new PVector(pos_temperature.x+150,12);
colorMode(HSB, 360, 100, 100);
fill(color(map(vbat_Front,12*3,12*4.2,0,120),50,100));
text("vbat_Front="+(vbat_Front/100.0)+"V", pos_voltage.x,pos_voltage.y); //TODO: remove /100
text("vbat_Front="+(vbat_Front)+"V", pos_voltage.x,pos_voltage.y);
fill(color(map(vbat_Rear,12*3,12*4.2,0,120),50,100));
text("vbat_Rear="+(vbat_Rear/100.0)+"V", pos_voltage.x,pos_voltage.y+12); //TODO: remove /100
text("vbat_Rear="+(vbat_Rear)+"V", pos_voltage.x,pos_voltage.y+12);
colorMode(RGB, 255, 255, 255);
fill(color(200,200,200));
textAlign(LEFT);
textSize(12);
textSize(vis_textsize);
text("d="+(nextTime-lastTimeData)+"ms", 5+70,12);
if (!useSerial && loopmillis-lastTimeData>(nextTime-lastTimeData)*10) { //deviation too high when reading from file
text("ff="+(loopmillis-lastTimeData)+"ms", 5+70+70,12); //show warning
}
text("t="+(loopmillis/1000.0)+"s", 5,12);
text(""+(dataErrorCount)+" errors", 5,12+vis_textsize);
}