implement all current available values as display

This commit is contained in:
interfisch 2021-03-21 18:21:05 +01:00
parent 29a15054a9
commit 8131ba571e
2 changed files with 109 additions and 16 deletions

View File

@ -256,6 +256,53 @@ public class BarH extends Visualization {
}
}
public class BarH_cmd extends Visualization {
PVector size = new PVector(10,100);
public BarH_cmd(int px, int py, int pw, int ph,float pvmin, float pvmax) {
super.valueMin=pvmin;
super.valueMax=pvmax;
super.posOrigin= new PVector(px,py); //lower left corner
this.size = new PVector(pw,ph); //to the right and up
}
public void drawVis() {
rectMode(CORNERS);
textSize(super.textsize);
int zerox=(int)map(0,super.valueMin,super.valueMax,0,this.size.x);
fill(super.cmain); noStroke();
rect(super.posOrigin.x+zerox,super.posOrigin.y,super.posOrigin.x+( this.size.x*super.getValueNormalized()),super.posOrigin.y- this.size.y );
if (!Float.isNaN(super.valueMinRecord)){
stroke(super.cmin);
line(super.posOrigin.x+( this.size.x*super.getValueMinNormalized()),super.posOrigin.y,super.posOrigin.x+( this.size.x*super.getValueMinNormalized()),super.posOrigin.y- this.size.y );
}
if (!Float.isNaN(super.valueMaxRecord)){
stroke(super.cmax);
line(super.posOrigin.x+( this.size.x*super.getValueMaxNormalized()),super.posOrigin.y,super.posOrigin.x+( this.size.x*super.getValueMaxNormalized()),super.posOrigin.y- this.size.y );
}
noFill(); stroke(super.cborder);
rect(super.posOrigin.x,super.posOrigin.y,super.posOrigin.x+this.size.x,super.posOrigin.y- this.size.y );
//text
fill(super.ctext);
//text(super.getFormattedValue(super.valueMin),super.posOrigin.x-super.getFormattedValue(super.valueMin).length()*super.textWidthScale,super.posOrigin.y-this.size.y-1);
//text(super.getFormattedValue(super.valueMax),super.posOrigin.x+this.size.x-super.getFormattedValue(super.valueMax).length()*super.textWidthScale,super.posOrigin.y-this.size.y-1);
text(super.getFormattedValue(super.value),super.posOrigin.x+this.size.x/2-super.getFormattedValue(super.value).length()*super.textWidthScale,super.posOrigin.y-this.size.y-1);
//Title
text(super.title, super.posOrigin.x+this.size.x/2-super.title.length()*super.textWidthScale,super.posOrigin.y+this.textsize+1);
}
}
public class Tacho extends Visualization {
int size;

View File

@ -16,6 +16,14 @@ Visualization vis_speed_FrontR;
Visualization vis_speed_RearL;
Visualization vis_speed_RearR;
Visualization vis_throttle;
Visualization vis_brake;
Visualization vis_currentAll;
//vis_c means calculated value, not raw value from log
Visualization vis_c_speed_mean;
long lastTimeData=0; //last time data received
@ -57,19 +65,18 @@ void setup() {
PVector size_vis_cmd = new PVector(10,100);
PVector dist_vis_cmd = new PVector(80,150);
colorMode(RGB, 255, 255, 255);
//cmd
color c_cmd=color(255,50,0);
vis_cmd_FrontL = new BarV_cmd((int)pos_vis_cmd.x,(int)pos_vis_cmd.y,(int)size_vis_cmd.x,(int)size_vis_cmd.y,-1000,1000);
vis_cmd_FrontL.setTitle("");
vis_cmd_FrontR = new BarV_cmd((int)(pos_vis_cmd.x+dist_vis_cmd.x),(int)pos_vis_cmd.y,(int)size_vis_cmd.x,(int)size_vis_cmd.y,-1000,1000);
vis_cmd_FrontR.setTitle("cmd");
vis_cmd_RearL = new BarV_cmd((int)pos_vis_cmd.x,(int)(pos_vis_cmd.y+dist_vis_cmd.y),(int)size_vis_cmd.x,(int)size_vis_cmd.y,-1000,1000);
vis_cmd_RearL.setTitle("");
vis_cmd_RearR = new BarV_cmd((int)(pos_vis_cmd.x+dist_vis_cmd.x),(int)(pos_vis_cmd.y+dist_vis_cmd.y),(int)size_vis_cmd.x,(int)size_vis_cmd.y,-1000,1000);
vis_cmd_RearR.setTitle("");
vis_cmd_FrontL.setcmain(c_cmd);
vis_cmd_FrontR.setcmain(c_cmd);
@ -79,16 +86,13 @@ void setup() {
// Speed
color c_speed=color(50,50,255);
vis_speed_FrontL = new BarV_cmd((int)(pos_vis_cmd.x-size_vis_cmd.x*2),(int)pos_vis_cmd.y+vis_textsize,(int)size_vis_cmd.x,(int)size_vis_cmd.y,-100,600);
vis_speed_FrontL.setTitle("");
vis_speed_FrontR = new BarV_cmd((int)(pos_vis_cmd.x+dist_vis_cmd.x+size_vis_cmd.x*2),(int)pos_vis_cmd.y+vis_textsize,(int)size_vis_cmd.x,(int)size_vis_cmd.y,-100,600);
vis_speed_FrontR.setTitle("speed");
vis_speed_RearL = new BarV_cmd((int)(pos_vis_cmd.x-size_vis_cmd.x*2),(int)(pos_vis_cmd.y+vis_textsize+dist_vis_cmd.y),(int)size_vis_cmd.x,(int)size_vis_cmd.y,-100,600);
vis_speed_RearL.setTitle("");
vis_speed_RearR = new BarV_cmd((int)(pos_vis_cmd.x+dist_vis_cmd.x+size_vis_cmd.x*2),(int)(pos_vis_cmd.y+vis_textsize+dist_vis_cmd.y),(int)size_vis_cmd.x,(int)size_vis_cmd.y,-100,600);
vis_speed_RearR.setTitle("");
vis_speed_FrontL.setcmain(c_speed);
vis_speed_FrontR.setcmain(c_speed);
@ -98,22 +102,41 @@ void setup() {
// Current
color c_current=color(255,200,50);
vis_current_FrontL = new BarV_cmd((int)(pos_vis_cmd.x-size_vis_cmd.x*2*2),(int)pos_vis_cmd.y+vis_textsize*2,(int)size_vis_cmd.x,(int)size_vis_cmd.y,-1,10);
vis_current_FrontL.setTitle("");
vis_current_FrontR = new BarV_cmd((int)(pos_vis_cmd.x+dist_vis_cmd.x+size_vis_cmd.x*2*2),(int)pos_vis_cmd.y+vis_textsize*2,(int)size_vis_cmd.x,(int)size_vis_cmd.y,-1,10);
vis_current_FrontR.setTitle("current");
vis_current_RearL = new BarV_cmd((int)(pos_vis_cmd.x-size_vis_cmd.x*2*2),(int)(pos_vis_cmd.y+vis_textsize*2+dist_vis_cmd.y),(int)size_vis_cmd.x,(int)size_vis_cmd.y,-1,10);
vis_current_RearL.setTitle("");
vis_current_RearR = new BarV_cmd((int)(pos_vis_cmd.x+dist_vis_cmd.x+size_vis_cmd.x*2*2),(int)(pos_vis_cmd.y+vis_textsize*2+dist_vis_cmd.y),(int)size_vis_cmd.x,(int)size_vis_cmd.y,-1,10);
vis_current_RearR.setTitle("");
vis_current_FrontL.setcmain(c_current);
vis_current_FrontR.setcmain(c_current);
vis_current_RearL.setcmain(c_current);
vis_current_RearR.setcmain(c_current);
//Inputs
PVector pos_vis_inputs = new PVector(width/2,height-50); //will be center for x
PVector size_vis_inputs = new PVector(200,40);
color c_throttle=color(255,150,50);
vis_throttle = new BarH_cmd((int)pos_vis_inputs.x,(int)pos_vis_inputs.y,(int)size_vis_inputs.x,(int)size_vis_inputs.y,0,1000);
vis_throttle.setcmain(c_throttle);
vis_throttle.setTitle("Throttle");
color c_brake=color(200,200,50);
vis_brake = new BarH_cmd((int)(pos_vis_inputs.x-size_vis_inputs.x),(int)pos_vis_inputs.y,(int)size_vis_inputs.x,(int)size_vis_inputs.y,-1000,0);
vis_brake.setcmain(c_brake);
vis_brake.setTitle("Brake");
//Speed mean
vis_c_speed_mean = new Tacho(500,500,100,-100,600);
vis_c_speed_mean.setTitle("Speed");
//Current
vis_currentAll = new Tacho(750,500,100,-1,10);
vis_currentAll.setTitle("minCurrent");
}
@ -168,20 +191,43 @@ 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();
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_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_throttle.setValue(throttle); vis_throttle.drawVis();
vis_brake.setValue(-brake); vis_brake.drawVis();
float speed_mean=(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
//Temperature
PVector pos_temperature = new PVector(220,12);
colorMode(HSB, 360, 100, 100);
fill(color(map(temp_Front,16,50,180,360),50,100));
text("temp_Front="+(temp_Front)+"°C", pos_temperature.x,pos_temperature.y);
fill(color(map(temp_Rear,16,50,180,360),50,100));
text("temp_Rear="+(temp_Rear)+"°C", pos_temperature.x,pos_temperature.y+12);
//Voltage
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
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
colorMode(RGB, 255, 255, 255);
fill(color(200,200,200));
textAlign(LEFT);
textSize(12);
text("d="+(nextTime-lastTimeData)+"ms", 5+70,12);
if (loopmillis-lastTimeData>(nextTime-lastTimeData)*10) { //
text("ff="+(loopmillis-lastTimeData)+"ms", 5+70+70,12);
if (loopmillis-lastTimeData>(nextTime-lastTimeData)*10) { //deviation too high
text("ff="+(loopmillis-lastTimeData)+"ms", 5+70+70,12); //show warning
}
text("t="+(loopmillis/1000.0)+"s", 5,12);