implement cmd, speed and current for all four wheels
This commit is contained in:
parent
834a2ff757
commit
29a15054a9
|
@ -17,12 +17,12 @@ abstract class Visualization
|
|||
boolean showMinMax=false;
|
||||
|
||||
//default colors (not all used by every implementation)
|
||||
color cmain = color(0,0,0);
|
||||
color cmain = color(255,255,255);
|
||||
color cscale = color(100,100,100);
|
||||
color cborder = color(204,104,0);
|
||||
color cborder = color(200,200,200);
|
||||
color cmin = color(0,150,0);
|
||||
color cmax = color(150,0,0);
|
||||
color ctext = color(0,0,0);
|
||||
color ctext = color(255,255,255);
|
||||
|
||||
int textsize=12;
|
||||
float textWidthScale=1.0/2*this.textsize/2; //*text.length()*
|
||||
|
@ -153,14 +153,67 @@ public class BarV extends Visualization {
|
|||
fill(super.ctext);
|
||||
text(super.getFormattedValue(super.valueMin),super.posOrigin.x+this.size.x+1,super.posOrigin.y+super.textsize/2);
|
||||
text(super.getFormattedValue(super.valueMax),super.posOrigin.x+this.size.x+1,super.posOrigin.y-this.size.y+super.textsize/2);
|
||||
text(super.getFormattedValue(super.value),super.posOrigin.x+this.size.x+1,super.posOrigin.y-this.size.y/2+super.textsize/2);
|
||||
textAlign(LEFT);
|
||||
text(super.getFormattedValue(super.value),super.posOrigin.x+this.size.x+1,super.posOrigin.y+super.textsize/2-this.size.y/2); //display value
|
||||
|
||||
//Title
|
||||
text(super.title, super.posOrigin.x-super.title.length()*super.textWidthScale, super.posOrigin.y+super.textsize*1.5);
|
||||
textAlign(CENTER);
|
||||
text(super.title, super.posOrigin.x+this.size.x/2, super.posOrigin.y-this.size.y-1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class BarV_cmd extends Visualization {
|
||||
PVector size = new PVector(10,100);
|
||||
|
||||
public BarV_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);
|
||||
|
||||
fill(super.cmain); noStroke();
|
||||
int zeroy=(int)map(0,super.valueMin,super.valueMax,0,this.size.y);
|
||||
rect(super.posOrigin.x,super.posOrigin.y-zeroy,super.posOrigin.x+this.size.x,super.posOrigin.y-( this.size.y*super.getValueNormalized()) );
|
||||
|
||||
|
||||
if (!Float.isNaN(super.valueMinRecord)){
|
||||
stroke(super.cmin);
|
||||
line(super.posOrigin.x,super.posOrigin.y-( this.size.y*super.getValueMinNormalized()) ,super.posOrigin.x+this.size.x,super.posOrigin.y-( this.size.y*super.getValueMinNormalized()) );
|
||||
}
|
||||
if (!Float.isNaN(super.valueMaxRecord)){
|
||||
stroke(super.cmax);
|
||||
line(super.posOrigin.x, super.posOrigin.y-( this.size.y*super.getValueMaxNormalized()), super.posOrigin.x+this.size.x,super.posOrigin.y-( this.size.y*super.getValueMaxNormalized()) );
|
||||
}
|
||||
|
||||
noFill(); stroke(this.cborder);
|
||||
rect(super.posOrigin.x,super.posOrigin.y,super.posOrigin.x+this.size.x,super.posOrigin.y- this.size.y );
|
||||
line(super.posOrigin.x,super.posOrigin.y-zeroy,super.posOrigin.x+this.size.x,super.posOrigin.y-zeroy); //zero line
|
||||
|
||||
//text
|
||||
fill(super.ctext);
|
||||
//text(super.getFormattedValue(super.valueMin),super.posOrigin.x+this.size.x+1,super.posOrigin.y+super.textsize/2);
|
||||
//text(super.getFormattedValue(super.valueMax),super.posOrigin.x+this.size.x+1,super.posOrigin.y-this.size.y+super.textsize/2);
|
||||
textAlign(RIGHT);
|
||||
text(super.getFormattedValue(super.value),super.posOrigin.x+this.size.x/2+super.textWidthScale*3,super.posOrigin.y+super.textsize); //display value
|
||||
|
||||
//Title
|
||||
textAlign(LEFT);
|
||||
text(super.title, super.posOrigin.x, super.posOrigin.y-this.size.y-1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public class BarH extends Visualization {
|
||||
PVector size = new PVector(10,100);
|
||||
|
||||
|
|
|
@ -1,5 +1,20 @@
|
|||
|
||||
Visualization visThrottle;
|
||||
int vis_textsize=12; //copy from Visualization class
|
||||
|
||||
Visualization vis_cmd_FrontL;
|
||||
Visualization vis_cmd_FrontR;
|
||||
Visualization vis_cmd_RearL;
|
||||
Visualization vis_cmd_RearR;
|
||||
|
||||
Visualization vis_current_FrontL;
|
||||
Visualization vis_current_FrontR;
|
||||
Visualization vis_current_RearL;
|
||||
Visualization vis_current_RearR;
|
||||
|
||||
Visualization vis_speed_FrontL;
|
||||
Visualization vis_speed_FrontR;
|
||||
Visualization vis_speed_RearL;
|
||||
Visualization vis_speed_RearR;
|
||||
|
||||
|
||||
long lastTimeData=0; //last time data received
|
||||
|
@ -10,7 +25,25 @@ int nextID=0; //next row number to be displayed
|
|||
long nextTime=0; //time of nextID row
|
||||
|
||||
//Data from log
|
||||
int throttle=0;
|
||||
int cmd_FrontL;
|
||||
int cmd_FrontR;
|
||||
int cmd_RearL;
|
||||
int cmd_RearR;
|
||||
float current_FrontL;
|
||||
float current_FrontR;
|
||||
float current_RearL;
|
||||
float current_RearR;
|
||||
int speed_FrontL;
|
||||
int speed_FrontR;
|
||||
int speed_RearL;
|
||||
int speed_RearR;
|
||||
float temp_Front;
|
||||
float temp_Rear;
|
||||
float vbat_Front;
|
||||
float vbat_Rear;
|
||||
float currentAll;
|
||||
int throttle;
|
||||
int brake;
|
||||
|
||||
void setup() {
|
||||
size(1920, 1080);
|
||||
|
@ -18,22 +51,104 @@ void setup() {
|
|||
|
||||
logdata = loadTable("LOG00008_rumfahren_neu.TXT", "header, csv");
|
||||
|
||||
println("loaded "+logdata.getRowCount()+" lines. Times: "+logdata.getRow(0).getFloat("time")+"s to "+logdata.getRow(logdata.getRowCount()-1).getFloat("time")+"s");
|
||||
|
||||
PVector pos_vis_cmd = new PVector(100,150);
|
||||
PVector size_vis_cmd = new PVector(10,100);
|
||||
PVector dist_vis_cmd = new PVector(80,150);
|
||||
|
||||
//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);
|
||||
vis_cmd_RearL.setcmain(c_cmd);
|
||||
vis_cmd_RearR.setcmain(c_cmd);
|
||||
|
||||
// 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);
|
||||
vis_speed_RearL.setcmain(c_speed);
|
||||
vis_speed_RearR.setcmain(c_speed);
|
||||
|
||||
// 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);
|
||||
|
||||
|
||||
visThrottle = new BarV(20+80,120,10,100,-1000,1000);
|
||||
visThrottle.setTitle("Throttle");
|
||||
|
||||
}
|
||||
|
||||
void draw() {
|
||||
if (millis()>=nextTime){
|
||||
long loopmillis=millis()+25000;
|
||||
if (loopmillis>=nextTime){
|
||||
TableRow row = logdata.getRow(nextID);
|
||||
lastTimeData=nextTime;
|
||||
nextTime=(long)(row.getFloat("time")*1000); //get time and convert from seconds to ms
|
||||
|
||||
cmd_FrontL=row.getInt("cmd_FrontL");
|
||||
cmd_FrontR=row.getInt("cmd_FrontR");
|
||||
cmd_RearL=row.getInt("cmd_RearL");
|
||||
cmd_RearR=row.getInt("cmd_RearR");
|
||||
current_FrontL=row.getFloat("current_FrontL");
|
||||
current_FrontR=row.getFloat("current_FrontR");
|
||||
current_RearL=row.getFloat("current_RearL");
|
||||
current_RearR=row.getFloat("current_RearR");
|
||||
speed_FrontL=row.getInt("speed_FrontL");
|
||||
speed_FrontR=row.getInt("speed_FrontR");
|
||||
speed_RearL=row.getInt("speed_RearL");
|
||||
speed_RearR=row.getInt("speed_RearR");
|
||||
temp_Front=row.getFloat("temp_Front");
|
||||
temp_Rear=row.getFloat("temp_Rear");
|
||||
vbat_Front=row.getFloat("vbat_Front");
|
||||
vbat_Rear=row.getFloat("vbat_Rear");
|
||||
currentAll=row.getFloat("currentAll");
|
||||
throttle=row.getInt("throttle");
|
||||
println(nextTime + " throttle:"+throttle);
|
||||
brake=row.getInt("brake");
|
||||
|
||||
if (loopmillis-nextTime>1000) {//too much behind
|
||||
long _timestep=nextTime-lastTimeData; //approximated time step
|
||||
nextID+=(loopmillis-nextTime)/_timestep* 0.9; //fast forward estimated time steps
|
||||
}
|
||||
nextID++;
|
||||
nextID=nextID%logdata.getRowCount();
|
||||
}
|
||||
|
@ -41,14 +156,33 @@ void draw() {
|
|||
|
||||
|
||||
|
||||
background(255);
|
||||
visThrottle.setValue(throttle);
|
||||
background(0,0,0);
|
||||
|
||||
visThrottle.drawVis();
|
||||
vis_cmd_FrontL.setValue(cmd_FrontL); vis_cmd_FrontL.drawVis();
|
||||
vis_cmd_FrontR.setValue(cmd_FrontR); vis_cmd_FrontR.drawVis();
|
||||
vis_cmd_RearL.setValue(cmd_RearL); vis_cmd_RearL.drawVis();
|
||||
vis_cmd_RearR.setValue(cmd_RearR); vis_cmd_RearR.drawVis();
|
||||
|
||||
fill(color(0,0,0));
|
||||
vis_speed_FrontL.setValue(speed_FrontL); vis_speed_FrontL.drawVis();
|
||||
vis_speed_FrontR.setValue(speed_FrontR); vis_speed_FrontR.drawVis();
|
||||
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();
|
||||
|
||||
|
||||
|
||||
|
||||
fill(color(200,200,200));
|
||||
textAlign(LEFT);
|
||||
textSize(12);
|
||||
text("d="+(nextTime-lastTimeData)+"ms", 5,12*2);
|
||||
|
||||
text("t="+(millis()/1000.0)+"s", 5,12);
|
||||
text("d="+(nextTime-lastTimeData)+"ms", 5+70,12);
|
||||
if (loopmillis-lastTimeData>(nextTime-lastTimeData)*10) { //
|
||||
text("ff="+(loopmillis-lastTimeData)+"ms", 5+70+70,12);
|
||||
}
|
||||
|
||||
text("t="+(loopmillis/1000.0)+"s", 5,12);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue