Skip to content

Instantly share code, notes, and snippets.

@plinioMoreno
Created October 8, 2015 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plinioMoreno/b6d0a894c3cf74478a22 to your computer and use it in GitHub Desktop.
Save plinioMoreno/b6d0a894c3cf74478a22 to your computer and use it in GitHub Desktop.
YARP code that reads the hello world string from ROS publisher
// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
#include <stdio.h>
#include <yarp/os/all.h>
using namespace yarp::os;
int main(int argc, char *argv[]) {
Network yarp;
//Node node("/yarp/hello_world_listener");
BufferedPort<Bottle> port;
port.setReadOnly();
if (!port.open("/topic_name@/dds")) {
fprintf(stderr,"Failed to open port\n");
return 1;
}
while (true) {
Bottle *msg = port.read();
if (msg==NULL) {
fprintf(stderr,"Failed to read msg\n");
continue;
}
printf("Got [%s]\n", msg->get(0).asString().c_str());
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment