add gametrak values

This commit is contained in:
interfisch 2019-06-11 14:37:08 +02:00
parent 2019f08869
commit 662ea41690
3 changed files with 51 additions and 24 deletions

View File

@ -69,13 +69,13 @@ abstract class Visualization
} }
public float getValue2Normalized() { public float getValue2Normalized() {
return (constrain(this.value2,this.valueMin,this.valueMax)-this.value2Min)/(this.value2Max-this.value2Min); return (constrain(this.value2,this.value2Min,this.value2Max)-this.value2Min)/(this.value2Max-this.value2Min);
} }
public float getValue2MinNormalized() { public float getValue2MinNormalized() {
return (constrain(this.value2MinRecord,this.valueMin,this.valueMax)-this.value2Min)/(this.value2Max-this.value2Min); return (constrain(this.value2MinRecord,this.value2Min,this.value2Max)-this.value2Min)/(this.value2Max-this.value2Min);
} }
public float getValue2MaxNormalized() { public float getValue2MaxNormalized() {
return (constrain(this.value2MaxRecord,this.valueMin,this.valueMax)-this.value2Min)/(this.value2Max-this.value2Min); return (constrain(this.value2MaxRecord,this.value2Min,this.value2Max)-this.value2Min)/(this.value2Max-this.value2Min);
} }
public void setShowMinMax(boolean pshowMinMax){ public void setShowMinMax(boolean pshowMinMax){

View File

@ -6,12 +6,17 @@ Visualization visCurrent;
Visualization visSteer; Visualization visSteer;
Visualization visSpeed; Visualization visSpeed;
Visualization visYaw; Visualization visYaw;
Visualization visGT;
Visualization visGT_Vertical;
int steer=0; int steer=0;
int speed=0; int speed=0;
float voltage = 50; float voltage = 50;
float current = 0.0; float current = 0.0;
float yaw=0; float yaw=0;
int gt_length=0;
int gt_horizontal=0;
int gt_vertical=0;
long lastReceive=0; //last time serial received long lastReceive=0; //last time serial received
long lastDelay=0; long lastDelay=0;
@ -34,7 +39,7 @@ void setup() {
visVoltage.setShowMinMax(true); visVoltage.setShowMinMax(true);
visVoltage.setTitle("Voltage [V]"); visVoltage.setTitle("Voltage [V]");
visCurrent= new Tacho(150+250,150,100,0,100); visCurrent= new Tacho(150+100,150,100,0,100);
visCurrent.setShowMinMax(true); visCurrent.setShowMinMax(true);
visCurrent.setTitle("Current [A]"); visCurrent.setTitle("Current [A]");
@ -44,9 +49,14 @@ void setup() {
visSpeed = new BarV(10+100/2-5,300,10,100,-1000,1000); visSpeed = new BarV(10+100/2-5,300,10,100,-1000,1000);
visSpeed.setTitle("Speed"); visSpeed.setTitle("Speed");
visYaw = new Direction(150+250,300,100,0,360,0,1,0); visYaw = new Direction(150+100,300,100,0,360,0,1,0);
visYaw.setTitle("Yaw"); visYaw.setTitle("Yaw");
visGT = new Direction(150+100+220,300,100,-127/30*180,127/30*180,0,2500,PI/2+PI);
visGT.setTitle("Gametrak");
visGT_Vertical = new BarV(150+100+220+110,300+50,10,100,-127,127);
visGT_Vertical.setTitle("Vertical");
} }
void draw() { void draw() {
@ -58,6 +68,9 @@ void draw() {
visSteer.setValue(steer); visSteer.setValue(steer);
visSpeed.setValue(speed); visSpeed.setValue(speed);
visYaw.setValue(yaw); visYaw.setValue(yaw);
visGT.setValue(-gt_horizontal);
visGT.setValue2(gt_length);
visGT_Vertical.setValue(gt_vertical);
visVoltage.drawVis(); visVoltage.drawVis();
@ -65,6 +78,8 @@ void draw() {
visSteer.drawVis(); visSteer.drawVis();
visSpeed.drawVis(); visSpeed.drawVis();
visYaw.drawVis(); visYaw.drawVis();
visGT.drawVis();
visGT_Vertical.drawVis();
fill(color(0,0,0)); fill(color(0,0,0));
textSize(12); textSize(12);
@ -86,14 +101,17 @@ public void receive()
serialport.readBytes(inBuffer); serialport.readBytes(inBuffer);
if (inBuffer != null && inBuffer.length==16) { if (inBuffer != null && inBuffer.length==16) {
received=true; received=true;
int _address=0;
steer = extract_int16_t(inBuffer,0); steer = extract_int16_t(inBuffer,_address); _address+=2;
speed = extract_int16_t(inBuffer,2); speed = extract_int16_t(inBuffer,_address); _address+=2;
voltage = extract_float(inBuffer,4); voltage = extract_float(inBuffer, _address); _address+=4;
current = extract_float(inBuffer,8); //current = extract_float(inBuffer,_address);_address+=4;
yaw = extract_float(inBuffer,12); 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("yaw="+yaw);
println("voltage="+voltage); //println("gt_horizontal="+gt_horizontal);
} }
@ -104,7 +122,13 @@ public void receive()
} }
} }
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_uint16_t(byte array[], int startbyte) { public int extract_uint16_t(byte array[], int startbyte) {
return ((int)array[startbyte] & 0xff) | ((int)array[startbyte+1] & 0xff)<<8; return ((int)array[startbyte] & 0xff) | ((int)array[startbyte+1] & 0xff)<<8;

View File

@ -33,7 +33,8 @@ abstract class Visualization
public abstract void drawVis(); public abstract void drawVis();
public void setValue(float pv){ public void setValue(float pv){
this.value=constrain(pv,valueMin,valueMax); //this.value=constrain(pv,valueMin,valueMax);
this.value=pv;
if (this.showMinMax){ if (this.showMinMax){
if (Float.isNaN(this.valueMinRecord) || this.value<this.valueMinRecord){ if (Float.isNaN(this.valueMinRecord) || this.value<this.valueMinRecord){
this.valueMinRecord=this.value; this.valueMinRecord=this.value;
@ -45,7 +46,8 @@ abstract class Visualization
} }
public void setValue2(float pv){ public void setValue2(float pv){
this.value2=constrain(pv,valueMin,valueMax); //this.value2=constrain(pv,valueMin,valueMax);
this.value2=pv;
if (this.showMinMax){ if (this.showMinMax){
if (Float.isNaN(this.value2MinRecord) || this.value2<this.value2MinRecord){ if (Float.isNaN(this.value2MinRecord) || this.value2<this.value2MinRecord){
this.value2MinRecord=this.value2; this.value2MinRecord=this.value2;
@ -57,23 +59,23 @@ abstract class Visualization
} }
public float getValueNormalized() { public float getValueNormalized() {
return (this.value-this.valueMin)/(this.valueMax-this.valueMin); return (constrain(this.value,this.valueMin,this.valueMax)-this.valueMin)/(this.valueMax-this.valueMin);
} }
public float getValueMinNormalized() { public float getValueMinNormalized() {
return (this.valueMinRecord-this.valueMin)/(this.valueMax-this.valueMin); return (constrain(this.valueMinRecord,this.valueMin,this.valueMax)-this.valueMin)/(this.valueMax-this.valueMin);
} }
public float getValueMaxNormalized() { public float getValueMaxNormalized() {
return (this.valueMaxRecord-this.valueMin)/(this.valueMax-this.valueMin); return (constrain(this.valueMaxRecord,this.valueMin,this.valueMax)-this.valueMin)/(this.valueMax-this.valueMin);
} }
public float getValue2Normalized() { public float getValue2Normalized() {
return (this.value2-this.value2Min)/(this.value2Max-this.value2Min); return (constrain(this.value2,this.value2Min,this.value2Max)-this.value2Min)/(this.value2Max-this.value2Min);
} }
public float getValue2MinNormalized() { public float getValue2MinNormalized() {
return (this.value2MinRecord-this.value2Min)/(this.value2Max-this.value2Min); return (constrain(this.value2MinRecord,this.value2Min,this.value2Max)-this.value2Min)/(this.value2Max-this.value2Min);
} }
public float getValue2MaxNormalized() { public float getValue2MaxNormalized() {
return (this.value2MaxRecord-this.value2Min)/(this.value2Max-this.value2Min); return (constrain(this.value2MaxRecord,this.value2Min,this.value2Max)-this.value2Min)/(this.value2Max-this.value2Min);
} }
public void setShowMinMax(boolean pshowMinMax){ public void setShowMinMax(boolean pshowMinMax){
@ -278,8 +280,9 @@ public class Direction extends Visualization {
ellipse(super.posOrigin.x, super.posOrigin.y, this.size,this.size); ellipse(super.posOrigin.x, super.posOrigin.y, this.size,this.size);
stroke(super.cmain); stroke(super.cmain);
float angle=map(super.value,super.valueMin,super.valueMax,0,2*PI)+this.angleoffset; float angle=map(super.getValueNormalized(),0,1,0,2*PI)+this.angleoffset;
float _vecsize=this.size*( (super.value2-super.value2Min)/(super.value2Max-super.value2Min)); //float _vecsize=this.size*( (super.value2-super.value2Min)/(super.value2Max-super.value2Min));
float _vecsize=this.size*super.getValue2Normalized();
line(super.posOrigin.x,super.posOrigin.y,super.posOrigin.x+cos(angle)*_vecsize,super.posOrigin.y-sin(angle)*_vecsize); line(super.posOrigin.x,super.posOrigin.y,super.posOrigin.x+cos(angle)*_vecsize,super.posOrigin.y-sin(angle)*_vecsize);
line(super.posOrigin.x+cos(angle-0.1)*_vecsize*0.9,super.posOrigin.y-sin(angle-0.1)*_vecsize*0.9,super.posOrigin.x+cos(angle)*_vecsize,super.posOrigin.y-sin(angle)*_vecsize); //arrow line(super.posOrigin.x+cos(angle-0.1)*_vecsize*0.9,super.posOrigin.y-sin(angle-0.1)*_vecsize*0.9,super.posOrigin.x+cos(angle)*_vecsize,super.posOrigin.y-sin(angle)*_vecsize); //arrow
@ -387,4 +390,4 @@ public class GraphRoll extends Visualization {
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);
} }
} }