start implementing live serial display

This commit is contained in:
interfisch 2021-03-25 19:25:31 +01:00
parent 817ad11569
commit 6b335e1b8b
2 changed files with 104 additions and 32 deletions

View File

@ -1,6 +1,12 @@
import processing.serial.*;
int vis_textsize=12; //copy from Visualization class
boolean useSerial=false; //false=read from csv log, true=read from serial port
Serial serial;
String serialString=""; //last read string
int serial_endchar=10; //10=ASCII Linefeed
Visualization vis_cmd_FrontL;
Visualization vis_cmd_FrontR;
Visualization vis_cmd_RearL;
@ -62,9 +68,20 @@ void setup() {
size(1920, 1080);
frameRate(100);
if (useSerial) {
printArray(Serial.list());
// Open the port you are using at the rate you want:
serial = new Serial(this, Serial.list()[0], 9600);
serial.clear();
// Throw out the first reading, in case we started reading
// in the middle of a string from the sender.
serialString = serial.readStringUntil(serial_endchar);
serialString = null;
}else{
logdata = loadTable("LOG00008_rumfahren_neu.TXT", "header, csv");
println("loaded "+logdata.getRowCount()+" lines. Times: "+logdata.getRow(0).getFloat("time")+"s to "+logdata.getRow(logdata.getRowCount()-1).getFloat("time")+"s");
}
PVector pos_vis_cmd = new PVector(100,150);
PVector size_vis_cmd = new PVector(10,100);
@ -166,7 +183,41 @@ void setup() {
void draw() {
long loopmillis=millis()+25000;
if (loopmillis>=nextTime){
if (useSerial) {
while (serial.available() > 0) {
serialString = serial.readStringUntil(serial_endchar);
if (serialString != null) {
println(serialString);
lastTimeData=nextTime;
nextTime=loopmillis;
String[] list = split(serialString, ',');
cmd_FrontL=parseInt(list[0]);
cmd_FrontR=parseInt(list[1]);
cmd_RearL=parseInt(list[2]);
cmd_RearR=parseInt(list[3]);
current_FrontL=parseFloat(list[4]);
current_FrontR=parseFloat(list[5]);
current_RearL=parseFloat(list[6]);
current_RearR=parseFloat(list[7]);
speed_FrontL=parseInt(list[8]);
speed_FrontR=parseInt(list[9]);
speed_RearL=parseInt(list[10]);
speed_RearR=parseInt(list[11]);
temp_Front=parseFloat(list[12]);
temp_Rear=parseFloat(list[13]);
vbat_Front=parseFloat(list[14]);
vbat_Rear=parseFloat(list[15]);
currentAll=parseFloat(list[16]);
throttle=parseInt(list[17]);
brake=parseInt(list[18]);
}
}
}else{
if (loopmillis>=nextTime){ //New Data
TableRow row = logdata.getRow(nextID);
lastTimeData=nextTime;
nextTime=(long)(row.getFloat("time")*1000); //get time and convert from seconds to ms
@ -198,6 +249,7 @@ void draw() {
nextID++;
nextID=nextID%logdata.getRowCount();
}
}
@ -253,7 +305,7 @@ void draw() {
textAlign(LEFT);
textSize(12);
text("d="+(nextTime-lastTimeData)+"ms", 5+70,12);
if (loopmillis-lastTimeData>(nextTime-lastTimeData)*10) { //deviation too high
if (!useSerial && loopmillis-lastTimeData>(nextTime-lastTimeData)*10) { //deviation too high when reading from file
text("ff="+(loopmillis-lastTimeData)+"ms", 5+70+70,12); //show warning
}

View File

@ -0,0 +1,20 @@
// Example by Tom Igoe
import processing.serial.*;
// The serial port:
Serial serial;
void setup() {
// List all the available serial ports:
printArray(Serial.list());
// Open the port you are using at the rate you want:
serial = new Serial(this, Serial.list()[0], 115200);
}
void loop() {
serial.write("asdf");
}