add gametrak values

This commit is contained in:
interfisch 2019-06-11 14:37:08 +02:00
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;