Merge branch 'master' of https://repos.ctdo.de/interfisch/bobbycar
This commit is contained in:
commit
b10c20d8cd
|
@ -0,0 +1,8 @@
|
||||||
|
# Bobbycar OSD
|
||||||
|
|
||||||
|
This processing software can display log information from the bobbycar in realime.
|
||||||
|
|
||||||
|
It is used alongside the controller_teensy firmware.
|
||||||
|
Log information is constantly printed out on one serial interface and can be written either to an sd card or transmitted via rf or bluetooth.
|
||||||
|
|
||||||
|
![screenshot](Screenshot.png "Screenshot")
|
Binary file not shown.
After Width: | Height: | Size: 42 KiB |
|
@ -17,18 +17,19 @@ abstract class Visualization
|
||||||
boolean showMinMax=false;
|
boolean showMinMax=false;
|
||||||
|
|
||||||
//default colors (not all used by every implementation)
|
//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 cscale = color(100,100,100);
|
||||||
color cborder = color(204,104,0);
|
color cborder = color(200,200,200);
|
||||||
color cmin = color(0,150,0);
|
color cmin = color(0,150,0);
|
||||||
color cmax = color(150,0,0);
|
color cmax = color(150,0,0);
|
||||||
color ctext = color(0,0,0);
|
color ctext = color(255,255,255);
|
||||||
|
|
||||||
int textsize=12;
|
int textsize=12;
|
||||||
float textWidthScale=1.0/2*this.textsize/2; //*text.length()*
|
float textWidthScale=1.0/2*this.textsize/2; //*text.length()*
|
||||||
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,16 +156,72 @@ 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);
|
||||||
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)+valueUnit,super.posOrigin.x+this.size.x+1,super.posOrigin.y+super.textsize/2-this.size.y/2); //display value
|
||||||
|
|
||||||
//Title
|
//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
|
||||||
|
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
|
||||||
|
textAlign(LEFT);
|
||||||
|
text(super.title, super.posOrigin.x, super.posOrigin.y-this.size.y-1);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class BarH extends Visualization {
|
public class BarH extends Visualization {
|
||||||
PVector size = new PVector(10,100);
|
PVector size = new PVector(10,100);
|
||||||
|
|
||||||
|
@ -192,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
|
||||||
|
@ -203,6 +264,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)+valueUnit,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 {
|
public class Tacho extends Visualization {
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
|
@ -244,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);
|
||||||
|
@ -314,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
|
||||||
|
@ -376,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;
|
||||||
|
@ -409,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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,164 +1,261 @@
|
||||||
import processing.serial.*;
|
|
||||||
|
|
||||||
Serial serialport;
|
int vis_textsize=12; //copy from Visualization class
|
||||||
Visualization visVoltage;
|
|
||||||
Visualization visCurrent;
|
|
||||||
Visualization visSpeedl;
|
|
||||||
Visualization visSpeedr;
|
|
||||||
Visualization visYaw;
|
|
||||||
Visualization visGT;
|
|
||||||
Visualization visGT_Vertical;
|
|
||||||
|
|
||||||
int speedl=0;
|
Visualization vis_cmd_FrontL;
|
||||||
int speedr=0;
|
Visualization vis_cmd_FrontR;
|
||||||
int booleanvalues=0;
|
Visualization vis_cmd_RearL;
|
||||||
float voltage = 50;
|
Visualization vis_cmd_RearR;
|
||||||
float current = 0.0;
|
|
||||||
float yaw=0;
|
|
||||||
int gt_length=0;
|
|
||||||
int gt_horizontal=0;
|
|
||||||
int gt_vertical=0;
|
|
||||||
|
|
||||||
long lastReceive=0; //last time serial received
|
Visualization vis_current_FrontL;
|
||||||
long lastDelay=0;
|
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;
|
||||||
|
|
||||||
|
Visualization vis_throttle;
|
||||||
|
Visualization vis_brake;
|
||||||
|
|
||||||
|
Visualization vis_currentAll;
|
||||||
|
|
||||||
|
//vis_c means calculated value, not raw value from log
|
||||||
|
Visualization vis_c_speed_mean;
|
||||||
|
|
||||||
|
Visualization vis_graph_currentAll;
|
||||||
|
Visualization vis_graph_speed_mean;
|
||||||
|
|
||||||
|
|
||||||
|
long lastTimeData=0; //last time data received
|
||||||
|
|
||||||
|
|
||||||
|
Table logdata;
|
||||||
|
int nextID=0; //next row number to be displayed
|
||||||
|
long nextTime=0; //time of nextID row
|
||||||
|
|
||||||
|
//Data from log
|
||||||
|
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;
|
||||||
|
|
||||||
|
color bg=color(0);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
size(640, 450);
|
size(1920, 1080);
|
||||||
frameRate(100);
|
frameRate(100);
|
||||||
|
|
||||||
printArray(Serial.list());
|
logdata = loadTable("LOG00008_rumfahren_neu.TXT", "header, csv");
|
||||||
serialport = new Serial(this, Serial.list()[32], 115200);
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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_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_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_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_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.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_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_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.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_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");
|
||||||
|
|
||||||
|
|
||||||
visVoltage = new BarV(50,150,10,100,10*3.3,12*4.2);
|
//Speed mean
|
||||||
visVoltage.setcmain(color(100,100,100));
|
vis_c_speed_mean = new Tacho(width/2-150,height-150,100,-100,600);
|
||||||
//vis = new BarH(150,150,100,10,0,100);
|
vis_c_speed_mean.setTitle("Speed");
|
||||||
//visVoltage = new Tacho(150,150,100,0,100);
|
vis_c_speed_mean.setValueUnit("rpm");
|
||||||
//vis = new Direction(150,150,100,0,100,0,1,0);
|
|
||||||
|
|
||||||
visVoltage.setShowMinMax(true);
|
//Current
|
||||||
visVoltage.setTitle("Voltage [V]");
|
vis_currentAll = new Tacho(width/2+150,height-150,100,-1,10);
|
||||||
|
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");
|
||||||
|
|
||||||
visCurrent= new Tacho(150+100,150,100,0,100);
|
|
||||||
visCurrent.setShowMinMax(true);
|
|
||||||
visCurrent.setTitle("Current [A]");
|
|
||||||
|
|
||||||
visSpeedl = new BarV(20+80,120,10,100,-1000,1000);
|
|
||||||
visSpeedl.setTitle("SpeedL");
|
|
||||||
|
|
||||||
visSpeedr = new BarV(20,120,10,100,-1000,1000);
|
|
||||||
visSpeedr.setTitle("SpeedR");
|
|
||||||
|
|
||||||
visYaw = new Direction(150+100,120,100,0,360,0,1,0);
|
|
||||||
visYaw.setTitle("Yaw");
|
|
||||||
|
|
||||||
visGT = new Direction(150+100+220,120,100,-127/30*180,127/30*180,0,2500,PI/2+PI);
|
|
||||||
visGT.setTitle("Gametrak");
|
|
||||||
visGT_Vertical = new BarV(150+100+220+110,120+50,10,100,-127,127);
|
|
||||||
visGT_Vertical.setTitle("Vertical");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw() {
|
void draw() {
|
||||||
receive();
|
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
|
||||||
|
|
||||||
background(255);
|
cmd_FrontL=row.getInt("cmd_FrontL");
|
||||||
visVoltage.setValue(voltage);
|
cmd_FrontR=row.getInt("cmd_FrontR");
|
||||||
visCurrent.setValue(current);
|
cmd_RearL=row.getInt("cmd_RearL");
|
||||||
visSpeedl.setValue(speedl);
|
cmd_RearR=row.getInt("cmd_RearR");
|
||||||
visSpeedr.setValue(speedr);
|
current_FrontL=row.getFloat("current_FrontL");
|
||||||
visYaw.setValue(yaw);
|
current_FrontR=row.getFloat("current_FrontR");
|
||||||
visGT.setValue(-gt_horizontal);
|
current_RearL=row.getFloat("current_RearL");
|
||||||
visGT.setValue2(gt_length);
|
current_RearR=row.getFloat("current_RearR");
|
||||||
visGT_Vertical.setValue(gt_vertical);
|
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");
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//visVoltage.drawVis();
|
|
||||||
//visCurrent.drawVis();
|
|
||||||
visSpeedl.drawVis();
|
|
||||||
visSpeedr.drawVis();
|
|
||||||
visYaw.drawVis();
|
|
||||||
visGT.drawVis();
|
|
||||||
visGT_Vertical.drawVis();
|
|
||||||
|
|
||||||
fill(color(0,0,0));
|
|
||||||
|
background(bg);
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
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(); //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();
|
||||||
|
|
||||||
|
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_graph_speed_mean.setValue(speed_mean); vis_graph_speed_mean.drawVis();
|
||||||
|
vis_graph_currentAll.setValue(-currentAll); vis_graph_currentAll.drawVis();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//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);
|
textSize(12);
|
||||||
long _delay=lastDelay;
|
text("d="+(nextTime-lastTimeData)+"ms", 5+70,12);
|
||||||
if (millis()-lastReceive>1000){ //show counting up if update too long ago
|
if (loopmillis-lastTimeData>(nextTime-lastTimeData)*10) { //deviation too high
|
||||||
_delay=millis()-lastReceive;
|
text("ff="+(loopmillis-lastTimeData)+"ms", 5+70+70,12); //show warning
|
||||||
}
|
}
|
||||||
text("Delay="+(_delay), 5,12);
|
|
||||||
}
|
text("t="+(loopmillis/1000.0)+"s", 5,12);
|
||||||
|
|
||||||
|
|
||||||
public void receive()
|
|
||||||
{
|
|
||||||
boolean received=false;
|
|
||||||
byte[] inBuffer = new byte[17];
|
|
||||||
while(serialport.available()>0) {
|
|
||||||
|
|
||||||
inBuffer = serialport.readBytes();
|
|
||||||
serialport.readBytes(inBuffer);
|
|
||||||
if (inBuffer != null && inBuffer.length==17) {
|
|
||||||
received=true;
|
|
||||||
int _address=0;
|
|
||||||
speedl = extract_int16_t(inBuffer,_address); _address+=2;
|
|
||||||
speedr = extract_int16_t(inBuffer,_address); _address+=2;
|
|
||||||
booleanvalues = extract_uint8_t(inBuffer,_address); _address+=1;
|
|
||||||
voltage = extract_float(inBuffer, _address); _address+=4;
|
|
||||||
//current = extract_float(inBuffer,_address);_address+=4;
|
|
||||||
yaw = extract_float(inBuffer,_address);_address+=4;
|
|
||||||
gt_length = extract_uint16_t(inBuffer,_address); _address+=2;
|
|
||||||
gt_horizontal = extract_int8_t(inBuffer,_address); _address+=1;
|
|
||||||
gt_vertical = extract_int8_t(inBuffer,_address); _address+=1;
|
|
||||||
//println("yaw="+yaw);
|
|
||||||
//println("gt_horizontal="+gt_horizontal);
|
|
||||||
|
|
||||||
boolean motorenabled=boolean(booleanvalues & (1<<0)>>0); //check bit 0
|
|
||||||
int controlmode=(booleanvalues & (3<<1))>>1; //check bit 1 and 2
|
|
||||||
|
|
||||||
println("motorenabled="+motorenabled+" controlmode="+controlmode);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if (received){
|
|
||||||
lastDelay=millis()-lastReceive;
|
|
||||||
lastReceive=millis();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int extract_int8_t(byte array[], int startbyte) {
|
|
||||||
if ( ((int)array[startbyte] & 0x80) == 0x00 ) { //2's complement, not negative
|
|
||||||
return ((int)array[startbyte] & 0xff);
|
|
||||||
}else{
|
|
||||||
return -128 + ( (int)array[startbyte] & 0x7f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int extract_uint8_t(byte array[], int startbyte) {
|
|
||||||
return ((int)array[startbyte] & 0xff);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int extract_uint16_t(byte array[], int startbyte) {
|
|
||||||
return ((int)array[startbyte] & 0xff) | ((int)array[startbyte+1] & 0xff)<<8;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int extract_int16_t(byte array[], int startbyte) {
|
|
||||||
if ( ((int)array[startbyte+1] & 0x80) == 0x00 ) { //2's complement, not negative
|
|
||||||
return ( ((int)array[startbyte] & 0xff) | ((int)array[startbyte+1] & 0x7f)<<8 );
|
|
||||||
}else{ //value is negative
|
|
||||||
return -32768 + ( ((int)array[startbyte] & 0xff) | ((int)array[startbyte+1] & 0x7f)<<8 );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public float extract_float(byte array[], int startbyte) {
|
|
||||||
int MASK = 0xff;
|
|
||||||
int bits = 0;
|
|
||||||
int i = startbyte+3; //+3 because goes backwards and has 4 bytes
|
|
||||||
for (int shifter = 3; shifter >= 0; shifter--) {
|
|
||||||
bits |= ((int) array[i] & MASK) << (shifter * 8);
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
return Float.intBitsToFloat(bits);
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue