graph for current and speed

This commit is contained in:
interfisch 2021-03-21 18:58:51 +01:00
parent 8131ba571e
commit 62f0429935
2 changed files with 156 additions and 19 deletions

View File

@ -29,6 +29,7 @@ abstract class Visualization
int showdecimals=2; int showdecimals=2;
String title=""; String title="";
String valueUnit="";
public abstract void drawVis(); public abstract void drawVis();
@ -105,6 +106,10 @@ abstract class Visualization
this.title=pt; this.title=pt;
} }
public void setValueUnit(String pt) {
this.valueUnit=pt;
}
public void setshowdecimals(int pd) { public void setshowdecimals(int pd) {
this.showdecimals=pd; this.showdecimals=pd;
} }
@ -151,10 +156,10 @@ public class BarV extends Visualization {
//text //text
fill(super.ctext); 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.valueMin)+valueUnit,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.valueMax)+valueUnit,super.posOrigin.x+this.size.x+1,super.posOrigin.y-this.size.y+super.textsize/2);
textAlign(LEFT); 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 text(super.getFormattedValue(super.value)+valueUnit,super.posOrigin.x+this.size.x+1,super.posOrigin.y+super.textsize/2-this.size.y/2); //display value
//Title //Title
textAlign(CENTER); textAlign(CENTER);
@ -203,6 +208,9 @@ public class BarV_cmd extends Visualization {
//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.valueMax),super.posOrigin.x+this.size.x+1,super.posOrigin.y-this.size.y+super.textsize/2);
textAlign(RIGHT); textAlign(RIGHT);
text(super.getFormattedValue(super.value),super.posOrigin.x+this.size.x/2+super.textWidthScale*3,super.posOrigin.y+super.textsize); //display value text(super.getFormattedValue(super.value),super.posOrigin.x+this.size.x/2+super.textWidthScale*3,super.posOrigin.y+super.textsize); //display value
textAlign(LEFT);
text(valueUnit,super.posOrigin.x+this.size.x/2+super.textWidthScale*3,super.posOrigin.y+super.textsize); //display unit on the right without disturbing alignment
//Title //Title
textAlign(LEFT); textAlign(LEFT);
@ -245,9 +253,9 @@ public class BarH extends Visualization {
//text //text
fill(super.ctext); 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.valueMin)+valueUnit,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.valueMax)+valueUnit,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); text(super.getFormattedValue(super.value)+valueUnit,super.posOrigin.x+this.size.x/2-super.getFormattedValue(super.value).length()*super.textWidthScale,super.posOrigin.y-this.size.y-1);
//Title //Title
@ -294,7 +302,7 @@ public class BarH_cmd extends Visualization {
fill(super.ctext); 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.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.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); text(super.getFormattedValue(super.value)+valueUnit,super.posOrigin.x+this.size.x/2-super.getFormattedValue(super.value).length()*super.textWidthScale,super.posOrigin.y-this.size.y-1);
//Title //Title
@ -344,7 +352,7 @@ public class Tacho extends Visualization {
} }
//text //text
text(super.getFormattedValue(super.value),super.posOrigin.x-super.getFormattedValue(super.value).length()*super.textWidthScale,super.posOrigin.y+super.textsize/2-this.size*0.3); text(super.getFormattedValue(super.value)+valueUnit,super.posOrigin.x-super.getFormattedValue(super.value).length()*super.textWidthScale,super.posOrigin.y+super.textsize/2-this.size*0.3);
//Title //Title
text(super.title, super.posOrigin.x-super.title.length()*super.textWidthScale, super.posOrigin.y+super.textsize*1.5); text(super.title, super.posOrigin.x-super.title.length()*super.textWidthScale, super.posOrigin.y+super.textsize*1.5);
@ -414,9 +422,9 @@ public class Direction extends Visualization {
//text //text
fill(super.ctext); fill(super.ctext);
text(super.getFormattedValue(super.value),super.posOrigin.x-super.getFormattedValue(super.value).length()*super.textWidthScale,super.posOrigin.y+super.textsize*1.5*1); text(super.getFormattedValue(super.value)+valueUnit,super.posOrigin.x-super.getFormattedValue(super.value).length()*super.textWidthScale,super.posOrigin.y+super.textsize*1.5*1);
if (super.value2<super.value2Max){ //display only if in use if (super.value2<super.value2Max){ //display only if in use
text("l="+super.getFormattedValue(super.value2),super.posOrigin.x-("l="+super.getFormattedValue(super.value2)).length()*super.textWidthScale,super.posOrigin.y+super.textsize*1.5*2); text("l="+super.getFormattedValue(super.value2)+valueUnit,super.posOrigin.x-("l="+super.getFormattedValue(super.value2)).length()*super.textWidthScale,super.posOrigin.y+super.textsize*1.5*2);
} }
//Title //Title
@ -476,6 +484,8 @@ public class GraphRoll extends Visualization {
stroke(super.cborder); stroke(super.cborder);
noFill(); noFill();
rect(super.posOrigin.x,super.posOrigin.y,super.posOrigin.x+this.size.x,super.posOrigin.y-this.size.y); rect(super.posOrigin.x,super.posOrigin.y,super.posOrigin.x+this.size.x,super.posOrigin.y-this.size.y);
int zeroy=(int)map(0,super.valueMin,super.valueMax,0,this.size.y);
line(super.posOrigin.x,super.posOrigin.y-zeroy,super.posOrigin.x+this.size.x,super.posOrigin.y-zeroy);
noFill(); noFill();
int _cpos=this.arraypos; int _cpos=this.arraypos;
@ -509,9 +519,109 @@ public class GraphRoll extends Visualization {
//text //text
fill(super.ctext); fill(super.ctext);
text(super.getFormattedValue(super.value), super.posOrigin.x+this.size.x-50, super.posOrigin.y+super.textsize*1.5); text(super.getFormattedValue(super.value)+valueUnit, super.posOrigin.x+this.size.x-50, super.posOrigin.y+super.textsize*1.5);
text(super.getFormattedValue(super.valueMin), super.posOrigin.x+this.size.x+1, super.posOrigin.y+super.textsize*0.5-1); text(super.getFormattedValue(super.valueMin)+valueUnit, super.posOrigin.x+this.size.x+1, super.posOrigin.y+super.textsize*0.5-1);
text(super.getFormattedValue(super.valueMax), super.posOrigin.x+this.size.x+1, super.posOrigin.y-this.size.y+super.textsize*0.5-1); text(super.getFormattedValue(super.valueMax)+valueUnit, super.posOrigin.x+this.size.x+1, super.posOrigin.y-this.size.y+super.textsize*0.5-1);
//Title
text(super.title, super.posOrigin.x, super.posOrigin.y+super.textsize*1.5);
}
}
public class GraphRoll_minimal extends Visualization {
PVector size;
float[] valuearray;
float[] valueMinarray;
float[] valueMaxarray;
int arraypos;
int recordevery=1; //minimum value =1, the higher the slower
int recordevery_counter=0;
public GraphRoll_minimal(int px, int py, int psx, int psy,float pvmin, float pvmax,int precordevery) {
super.valueMin=pvmin;
super.valueMax=pvmax;
super.posOrigin= new PVector(px,py); //center
this.size = new PVector(psx,psy);
this.recordevery= precordevery;
this.valuearray = new float[psx]; //array size equals window width
this.arraypos=0; //points to position to write to next (current value is at arraypos-1)
this.valueMinarray = new float[psx];
this.valueMaxarray = new float[psx];
}
public void drawVis() {
//update history
this.recordevery_counter++;
if (this.recordevery_counter>=this.recordevery){
this.valuearray[this.arraypos]=super.getValueNormalized();
this.arraypos++;
this.arraypos%=this.valuearray.length;
this.recordevery_counter=0;
if (super.showMinMax) {
this.valueMinarray[this.arraypos]=super.getValueMinNormalized();
this.valueMaxarray[this.arraypos]=super.getValueMaxNormalized();
super.valueMinRecord=Float.NaN;
super.valueMaxRecord=Float.NaN;
}
}
rectMode(CORNERS);
textSize(super.textsize);
stroke(super.cborder);
noFill();
rect(super.posOrigin.x,super.posOrigin.y,super.posOrigin.x+this.size.x,super.posOrigin.y-this.size.y);
int zeroy=(int)map(0,super.valueMin,super.valueMax,0,this.size.y);
int dotlength=10;
float dotlengthpercentage=0.2; //0 to 1. the lower the less dot length
for(int _xdot=(int)super.posOrigin.x; _xdot+dotlength<=super.posOrigin.x+this.size.x; _xdot+=dotlength) {
//line(super.posOrigin.x,super.posOrigin.y-zeroy,super.posOrigin.x+this.size.x,super.posOrigin.y-zeroy); //zero line
line(_xdot,super.posOrigin.y-zeroy,_xdot+dotlength*dotlengthpercentage,super.posOrigin.y-zeroy); //zero line
}
noFill();
int _cpos=this.arraypos;
int _x=0; //position of _ya
while (_cpos!=((this.arraypos-1+this.valuearray.length)%this.valuearray.length)) { //go trough all values starting at oldest value
float _ya=this.valuearray[_cpos];
float _yb=this.valuearray[(_cpos+1)%this.valuearray.length];
//float _yaMin=this.valueMinarray[_cpos];
float _ybMin=this.valueMinarray[(_cpos+1)%this.valuearray.length];
float _ybMax=this.valueMaxarray[(_cpos+1)%this.valuearray.length];
if (super.showMinMax) {
stroke(super.cmin);
//line(super.posOrigin.x+_x,super.posOrigin.y-_yaMin*this.size.y, super.posOrigin.x+_x+1,super.posOrigin.y-_ybMin*this.size.y);
line(super.posOrigin.x+_x+1,super.posOrigin.y-_ybMin*this.size.y, super.posOrigin.x+_x+1,super.posOrigin.y-_yb*this.size.y);
stroke(super.cmax);
line(super.posOrigin.x+_x+1,super.posOrigin.y-_yb*this.size.y, super.posOrigin.x+_x+1,super.posOrigin.y-_ybMax*this.size.y);
}
stroke(super.cmain);
line(super.posOrigin.x+_x,super.posOrigin.y-_ya*this.size.y, super.posOrigin.x+_x+1,super.posOrigin.y-_yb*this.size.y);
_x++;
_cpos++;
_cpos%=this.valuearray.length;
}
//text
fill(super.ctext);
text(super.getFormattedValue(super.value)+valueUnit, super.posOrigin.x+this.size.x+1, super.posOrigin.y-this.valuearray[(_cpos)%this.valuearray.length]*this.size.y);
//text(super.getFormattedValue(super.valueMin), super.posOrigin.x+this.size.x+1, super.posOrigin.y+super.textsize*0.5-1);
//text(super.getFormattedValue(super.valueMax), super.posOrigin.x+this.size.x+1, super.posOrigin.y-this.size.y+super.textsize*0.5-1);
//Title //Title
text(super.title, super.posOrigin.x, super.posOrigin.y+super.textsize*1.5); text(super.title, super.posOrigin.x, super.posOrigin.y+super.textsize*1.5);
} }

View File

@ -24,6 +24,9 @@ Visualization vis_currentAll;
//vis_c means calculated value, not raw value from log //vis_c means calculated value, not raw value from log
Visualization vis_c_speed_mean; Visualization vis_c_speed_mean;
Visualization vis_graph_currentAll;
Visualization vis_graph_speed_mean;
long lastTimeData=0; //last time data received long lastTimeData=0; //last time data received
@ -53,6 +56,8 @@ float currentAll;
int throttle; int throttle;
int brake; int brake;
color bg=color(0);
void setup() { void setup() {
size(1920, 1080); size(1920, 1080);
frameRate(100); frameRate(100);
@ -72,7 +77,7 @@ void setup() {
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 = 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_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 = 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_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 = 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);
@ -85,12 +90,13 @@ void setup() {
// Speed // Speed
color c_speed=color(50,50,255); 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 = 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_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 = 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_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 = 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.setValueUnit("rpm");
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 = 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);
@ -107,6 +113,7 @@ void setup() {
vis_current_FrontR.setTitle("current"); 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 = 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.setValueUnit("A");
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 = 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);
@ -130,12 +137,28 @@ void setup() {
//Speed mean //Speed mean
vis_c_speed_mean = new Tacho(500,500,100,-100,600); vis_c_speed_mean = new Tacho(width/2-150,height-150,100,-100,600);
vis_c_speed_mean.setTitle("Speed"); vis_c_speed_mean.setTitle("Speed");
vis_c_speed_mean.setValueUnit("rpm");
//Current //Current
vis_currentAll = new Tacho(750,500,100,-1,10); vis_currentAll = new Tacho(width/2+150,height-150,100,-1,10);
vis_currentAll.setTitle("minCurrent"); vis_currentAll.setTitle("minCurrent");
vis_currentAll.setValueUnit("A");
//Graph
vis_graph_speed_mean = new GraphRoll_minimal(700, 250, 400,200,-100,600,1);
vis_graph_speed_mean.setcborder(c_speed);
vis_graph_speed_mean.setcmain(c_speed);
vis_graph_speed_mean.setValueUnit("rpm");
vis_graph_currentAll = new GraphRoll_minimal(700, 250, 400,200,-1,10,1);
vis_graph_currentAll.setcborder(c_current);
vis_graph_currentAll.setcmain(c_current);
vis_graph_currentAll.setValueUnit("A");
@ -179,7 +202,7 @@ void draw() {
background(0,0,0); background(bg);
vis_cmd_FrontL.setValue(cmd_FrontL); vis_cmd_FrontL.drawVis(); vis_cmd_FrontL.setValue(cmd_FrontL); vis_cmd_FrontL.drawVis();
vis_cmd_FrontR.setValue(cmd_FrontR); vis_cmd_FrontR.drawVis(); vis_cmd_FrontR.setValue(cmd_FrontR); vis_cmd_FrontR.drawVis();
@ -199,11 +222,15 @@ void draw() {
vis_throttle.setValue(throttle); vis_throttle.drawVis(); vis_throttle.setValue(throttle); vis_throttle.drawVis();
vis_brake.setValue(-brake); vis_brake.drawVis(); vis_brake.setValue(-brake); vis_brake.drawVis();
float speed_mean=(speed_FrontL+speed_FrontR+speed_RearL+speed_RearR)/4.0; 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_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(); //TODO: remove negative sign
vis_graph_speed_mean.setValue(speed_mean); vis_graph_speed_mean.drawVis();
vis_graph_currentAll.setValue(-currentAll); vis_graph_currentAll.drawVis();
//Temperature //Temperature
PVector pos_temperature = new PVector(220,12); PVector pos_temperature = new PVector(220,12);