-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Processing sketch to visualize robo's debug data graphically
- Loading branch information
Ramith Hettiarachchi
committed
May 14, 2019
1 parent
9bd4691
commit 474d737
Showing
2 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* Simple Read | ||
* | ||
* Read data from the serial port and change the color of a rectangle | ||
* when a switch connected to a Wiring or Arduino board is pressed and released. | ||
* This example works with the Wiring / Arduino program that follows below. | ||
*/ | ||
|
||
float angle =0; | ||
float p_angle=0; | ||
import processing.serial.*; | ||
PShape robot; | ||
PShape robot2; | ||
Serial myPort; // Create object from Serial class | ||
String val; // Data received from the serial port | ||
|
||
|
||
int sizex=700; | ||
int sizey=700; | ||
void setup() | ||
{ | ||
size(700, 700); | ||
|
||
// I know that the first port in the serial list on my mac | ||
// is always my FTDI adaptor, so I open Serial.list()[0]. | ||
// On Windows machines, this generally opens COM1. | ||
// Open whatever port is the one you're using. | ||
printArray(Serial.list()); | ||
String portName = Serial.list()[8]; | ||
myPort = new Serial(this, portName, 230400); | ||
|
||
|
||
robot = loadShape("robot.svg"); | ||
|
||
|
||
} | ||
|
||
void draw(){ | ||
|
||
rectMode(CENTER); | ||
translate(width/2, height/2); | ||
rotate(radians(angle)); | ||
|
||
background(225); | ||
|
||
|
||
frame.setTitle(mouseX + ", " + mouseY); | ||
float posx= -robot.width/2; | ||
float posy= robot.height/2; | ||
|
||
|
||
shape(robot, posx, posy); | ||
|
||
rect(posx,posy,5,5); //left bottom | ||
rect(posx+robot.width,posy,5,5); //left right | ||
rect(posx,posy-robot.height,5,5); | ||
rect(posx+robot.width,posy-robot.height,5,5); | ||
|
||
strokeWeight(4); | ||
stroke(255,0,0); | ||
|
||
if (myPort.available() > 0) { // If data is available, | ||
val = myPort.readStringUntil(10); // read it and store it in val | ||
myPort.clear(); | ||
try{ | ||
|
||
String c=val; | ||
|
||
|
||
if(c.length()<=18 && c.length()>13 && c.charAt(0)=='T'){ //got ToF line info list | ||
//print(c); | ||
String[] list = split(c,":"); //split by : | ||
|
||
line(posx+robot.width+float(list[3]),posy-100,posx+robot.width+float(list[3]),posy-80); | ||
line(posx-float(list[1]),posy-100,posx-float(list[1]),posy-80); | ||
}else if(c.length()>35 && c.charAt(0)=='a'){ //got ToF line info list | ||
print(c); | ||
String[] list = split(c,":"); //split by : | ||
|
||
angle=float(list[5]); | ||
|
||
} | ||
|
||
|
||
}catch (NullPointerException e) { | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
|
||
} |