2019-06-09 21:23:02 +00:00
|
|
|
import processing.serial.*;
|
|
|
|
|
|
|
|
Serial serialport;
|
|
|
|
Visualization visVoltage;
|
|
|
|
Visualization visCurrent;
|
2019-06-10 20:25:13 +00:00
|
|
|
Visualization visSteer;
|
|
|
|
Visualization visSpeed;
|
|
|
|
Visualization visYaw;
|
2019-06-11 12:37:08 +00:00
|
|
|
Visualization visGT;
|
|
|
|
Visualization visGT_Vertical;
|
2019-06-09 21:23:02 +00:00
|
|
|
|
2019-06-10 20:25:13 +00:00
|
|
|
int steer=0;
|
|
|
|
int speed=0;
|
2019-06-09 21:23:02 +00:00
|
|
|
float voltage = 50;
|
|
|
|
float current = 0.0;
|
2019-06-10 20:25:13 +00:00
|
|
|
float yaw=0;
|
2019-06-11 12:37:08 +00:00
|
|
|
int gt_length=0;
|
|
|
|
int gt_horizontal=0;
|
|
|
|
int gt_vertical=0;
|
2019-06-09 21:23:02 +00:00
|
|
|
|
|
|
|
long lastReceive=0; //last time serial received
|
|
|
|
long lastDelay=0;
|
|
|
|
|
|
|
|
|
|
|
|
void setup() {
|
2019-06-10 20:25:13 +00:00
|
|
|
size(640, 450);
|
2019-06-09 21:23:57 +00:00
|
|
|
frameRate(100);
|
2019-06-09 21:23:02 +00:00
|
|
|
|
|
|
|
printArray(Serial.list());
|
2019-06-10 20:25:13 +00:00
|
|
|
serialport = new Serial(this, Serial.list()[32], 57600);
|
2019-06-09 21:23:02 +00:00
|
|
|
|
|
|
|
|
2019-06-09 21:23:57 +00:00
|
|
|
visVoltage = new BarV(50,150,10,100,10*3.3,12*4.2);
|
|
|
|
visVoltage.setcmain(color(100,100,100));
|
2019-06-09 21:23:02 +00:00
|
|
|
//vis = new BarH(150,150,100,10,0,100);
|
2019-06-09 21:23:57 +00:00
|
|
|
//visVoltage = new Tacho(150,150,100,0,100);
|
2019-06-10 20:25:13 +00:00
|
|
|
//vis = new Direction(150,150,100,0,100,0,1,0);
|
2019-06-09 21:23:02 +00:00
|
|
|
|
|
|
|
visVoltage.setShowMinMax(true);
|
|
|
|
visVoltage.setTitle("Voltage [V]");
|
|
|
|
|
2019-06-11 12:37:08 +00:00
|
|
|
visCurrent= new Tacho(150+100,150,100,0,100);
|
2019-06-09 21:23:02 +00:00
|
|
|
visCurrent.setShowMinMax(true);
|
|
|
|
visCurrent.setTitle("Current [A]");
|
|
|
|
|
2019-06-10 20:25:13 +00:00
|
|
|
visSteer = new BarH(10,340,100,10,-1000,1000);
|
|
|
|
visSteer.setTitle("Steer");
|
|
|
|
|
|
|
|
visSpeed = new BarV(10+100/2-5,300,10,100,-1000,1000);
|
|
|
|
visSpeed.setTitle("Speed");
|
|
|
|
|
2019-06-11 12:37:08 +00:00
|
|
|
visYaw = new Direction(150+100,300,100,0,360,0,1,0);
|
2019-06-10 20:25:13 +00:00
|
|
|
visYaw.setTitle("Yaw");
|
|
|
|
|
2019-06-11 12:37:08 +00:00
|
|
|
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");
|
|
|
|
|
2019-06-09 21:23:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void draw() {
|
|
|
|
receive();
|
|
|
|
|
|
|
|
background(255);
|
|
|
|
visVoltage.setValue(voltage);
|
|
|
|
visCurrent.setValue(current);
|
2019-06-10 20:25:13 +00:00
|
|
|
visSteer.setValue(steer);
|
|
|
|
visSpeed.setValue(speed);
|
|
|
|
visYaw.setValue(yaw);
|
2019-06-11 12:37:08 +00:00
|
|
|
visGT.setValue(-gt_horizontal);
|
|
|
|
visGT.setValue2(gt_length);
|
|
|
|
visGT_Vertical.setValue(gt_vertical);
|
2019-06-09 21:23:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
visVoltage.drawVis();
|
|
|
|
visCurrent.drawVis();
|
2019-06-10 20:25:13 +00:00
|
|
|
visSteer.drawVis();
|
|
|
|
visSpeed.drawVis();
|
|
|
|
visYaw.drawVis();
|
2019-06-11 12:37:08 +00:00
|
|
|
visGT.drawVis();
|
|
|
|
visGT_Vertical.drawVis();
|
2019-06-09 21:23:02 +00:00
|
|
|
|
|
|
|
fill(color(0,0,0));
|
|
|
|
textSize(12);
|
|
|
|
long _delay=lastDelay;
|
|
|
|
if (millis()-lastReceive>1000){ //show counting up if update too long ago
|
|
|
|
_delay=millis()-lastReceive;
|
|
|
|
}
|
|
|
|
text("Delay="+(_delay), 5,12);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void receive()
|
|
|
|
{
|
2019-06-09 21:23:57 +00:00
|
|
|
boolean received=false;
|
2019-06-10 20:25:13 +00:00
|
|
|
byte[] inBuffer = new byte[16];
|
2019-06-09 21:23:02 +00:00
|
|
|
while(serialport.available()>0) {
|
2019-06-10 20:25:13 +00:00
|
|
|
|
2019-06-09 21:23:57 +00:00
|
|
|
inBuffer = serialport.readBytes();
|
2019-06-09 21:23:02 +00:00
|
|
|
serialport.readBytes(inBuffer);
|
2019-06-10 20:25:13 +00:00
|
|
|
if (inBuffer != null && inBuffer.length==16) {
|
|
|
|
received=true;
|
2019-06-11 12:37:08 +00:00
|
|
|
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;
|
2019-06-10 20:25:13 +00:00
|
|
|
//println("yaw="+yaw);
|
2019-06-11 12:37:08 +00:00
|
|
|
//println("gt_horizontal="+gt_horizontal);
|
2019-06-09 21:23:02 +00:00
|
|
|
|
2019-06-09 21:23:57 +00:00
|
|
|
}
|
2019-06-09 21:23:02 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
if (received){
|
|
|
|
lastDelay=millis()-lastReceive;
|
|
|
|
lastReceive=millis();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-11 12:37:08 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2019-06-09 21:23:02 +00:00
|
|
|
|
|
|
|
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);
|
2019-06-10 20:25:13 +00:00
|
|
|
}
|