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() {
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() {
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() {
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){

View File

@ -6,12 +6,17 @@ Visualization visCurrent;
Visualization visSteer;
Visualization visSpeed;
Visualization visYaw;
Visualization visGT;
Visualization visGT_Vertical;
int steer=0;
int speed=0;
float voltage = 50;
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
long lastDelay=0;
@ -34,7 +39,7 @@ void setup() {
visVoltage.setShowMinMax(true);
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.setTitle("Current [A]");
@ -44,9 +49,14 @@ void setup() {
visSpeed = new BarV(10+100/2-5,300,10,100,-1000,1000);
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");
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() {
@ -58,6 +68,9 @@ void draw() {
visSteer.setValue(steer);
visSpeed.setValue(speed);
visYaw.setValue(yaw);
visGT.setValue(-gt_horizontal);
visGT.setValue2(gt_length);
visGT_Vertical.setValue(gt_vertical);
visVoltage.drawVis();
@ -65,6 +78,8 @@ void draw() {
visSteer.drawVis();
visSpeed.drawVis();
visYaw.drawVis();
visGT.drawVis();
visGT_Vertical.drawVis();
fill(color(0,0,0));
textSize(12);
@ -86,14 +101,17 @@ public void receive()
serialport.readBytes(inBuffer);
if (inBuffer != null && inBuffer.length==16) {
received=true;
steer = extract_int16_t(inBuffer,0);
speed = extract_int16_t(inBuffer,2);
voltage = extract_float(inBuffer,4);
current = extract_float(inBuffer,8);
yaw = extract_float(inBuffer,12);
int _address=0;
steer = extract_int16_t(inBuffer,_address); _address+=2;
speed = extract_int16_t(inBuffer,_address); _address+=2;
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("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) {
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 void setValue(float pv){
this.value=constrain(pv,valueMin,valueMax);
//this.value=constrain(pv,valueMin,valueMax);
this.value=pv;
if (this.showMinMax){
if (Float.isNaN(this.valueMinRecord) || this.value<this.valueMinRecord){
this.valueMinRecord=this.value;
@ -45,7 +46,8 @@ abstract class Visualization
}
public void setValue2(float pv){
this.value2=constrain(pv,valueMin,valueMax);
//this.value2=constrain(pv,valueMin,valueMax);
this.value2=pv;
if (this.showMinMax){
if (Float.isNaN(this.value2MinRecord) || this.value2<this.value2MinRecord){
this.value2MinRecord=this.value2;
@ -57,23 +59,23 @@ abstract class Visualization
}
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() {
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() {
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() {
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() {
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() {
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){
@ -278,8 +280,9 @@ public class Direction extends Visualization {
ellipse(super.posOrigin.x, super.posOrigin.y, this.size,this.size);
stroke(super.cmain);
float angle=map(super.value,super.valueMin,super.valueMax,0,2*PI)+this.angleoffset;
float _vecsize=this.size*( (super.value2-super.value2Min)/(super.value2Max-super.value2Min));
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.getValue2Normalized();
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
@ -387,4 +390,4 @@ public class GraphRoll extends Visualization {
text(super.title, super.posOrigin.x, super.posOrigin.y+super.textsize*1.5);
}
}