ROSBridge client for Processing.
Just clone the repo to the libraries
folder inside your Processing sketchbook and restart Processing.
-
Import the library
import rosprocessing.*;
-
Create a global variable for the main library class
ROSProcessing rp;
-
Initialize the library and connect to rosbridge inside your
setup()
void setup() { ... rp = new ROSProcessing(this); rp.connect(); ... }
You can specify the hostname and port like this:
rp = new ROSProcessing(this, "192.168.1.1", 8080);
If not specified, "localhost" and port 9090 are used.
-
Subscribe to your topics using the
subscribe
method (e.g. also in yoursetup()
).rp.subscribe("/image", "newImage");
The arguments are the topic name and the name of the event callback to be called when new data arrive.
-
Create a callback function that will receive the data and save it in a global variable.
PImage pImage; void newImage(Image image) { pImage=image.toPImage(this); }
The event function must take an argument of a class corresponding to the message type of the ROS topic. Currently implemented message classes are storred in the
src/rosprocessing/messages
folder. Sometimes, those message classes provide convenience functions for parsing the raw ROS data, as in the example above where we convert ROS data to aPImage
. -
Draw!
void draw() { if (pImage!=null) image(pImage,0,0); }
For additional features, see the example for now.
You can find an example in the examples
folder.