add commands
This commit is contained in:
parent
b7dd466f02
commit
56266c35e9
|
@ -11,6 +11,7 @@ Visualization visGT_Vertical;
|
|||
|
||||
int steer=0;
|
||||
int speed=0;
|
||||
int booleanvalues=0;
|
||||
float voltage = 50;
|
||||
float current = 0.0;
|
||||
float yaw=0;
|
||||
|
@ -94,16 +95,17 @@ void draw() {
|
|||
public void receive()
|
||||
{
|
||||
boolean received=false;
|
||||
byte[] inBuffer = new byte[16];
|
||||
byte[] inBuffer = new byte[17];
|
||||
while(serialport.available()>0) {
|
||||
|
||||
inBuffer = serialport.readBytes();
|
||||
serialport.readBytes(inBuffer);
|
||||
if (inBuffer != null && inBuffer.length==16) {
|
||||
if (inBuffer != null && inBuffer.length==17) {
|
||||
received=true;
|
||||
int _address=0;
|
||||
steer = extract_int16_t(inBuffer,_address); _address+=2;
|
||||
speed = 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;
|
||||
|
@ -113,6 +115,10 @@ public void receive()
|
|||
//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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -130,6 +136,10 @@ public int extract_int8_t(byte array[], int startbyte) {
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue