|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
29 const unsigned int line,
34 const char* comp_name)
44 static const char* err_str =
"[ERROR] ";
45 static const char* warn_str =
"[WARNING] ";
46 static const char* no_str =
"";
53 "yarp.carrier.tcpros.yarpros",
61 string addPart(
string t,
string name,
int code,
Value *val,
string orig,
string mode=
"") {
64 sprintf(buf,
"%s %s # suggested length: %d",
t.c_str(), name.c_str(), code);
65 }
else if (mode==
"string") {
66 sprintf(buf,
"%s %s # value seen: \"%s\"",
t.c_str(), name.c_str(), orig.c_str());
67 }
else if (mode==
"vocab") {
68 char char4 = (code>>24)%256;
69 char char3 = (code>>16)%256;
70 char char2 = (code>>8)%256;
71 char char1 = code%256;
74 r +=
'\''; r += char1; r +=
"\'*256^3";
78 r +=
'\''; r += char2; r +=
"\'*256^2";
82 r +=
'\''; r += char3; r +=
"\'*256";
86 r +=
'\''; r += char4; r +=
'\'';
91 sprintf(buf,
"%s %s # set to %d (=%s=%s)",
t.c_str(), name.c_str(), code, r.c_str(), orig.c_str());
94 sprintf(buf,
"%s %s # set to %s (%s)",
t.c_str(), name.c_str(), val->
toString().c_str(), orig.c_str());
96 sprintf(buf,
"%s %s # set to %d (%s)",
t.c_str(), name.c_str(), code, orig.c_str());
107 bool specialized = (code>0);
109 r +=
addPart(
"int32[]",root,b.
size(),
nullptr,
"length",
"length");
112 r +=
" # integers seen: ";
113 for (
size_t i=0; i<b.
size(); i++) {
123 r +=
addPart(
"float64[]",root,b.
size(),
nullptr,
"length",
"length");
126 r +=
" # floats seen: ";
127 for (
size_t i=0; i<b.
size(); i++) {
136 r +=
addPart(
"int32",root +
"_len",b.
size(),
nullptr,
"elements in list");
138 for (
size_t i=0; i<b.
size(); i++) {
142 sprintf(tag_name,
"%s%zu_tag", root.c_str(), i);
143 sprintf(val_name,
"%s%zu", root.c_str(), i);
163 "BOTTLE_TAG_FLOAT64");
180 "BOTTLE_TAG_STRING");
196 const char *example =
nullptr,
197 const char *explanation =
nullptr) {
198 yCInfo(YARPROS,
"\n yarpros %s", action);
199 yCInfo(YARPROS,
" %s\n", msg);
200 if (example!=
nullptr) {
201 yCInfo(YARPROS,
" $ yarpros %s", example);
203 if (explanation!=
nullptr) {
204 yCInfo(YARPROS,
" # %s", explanation);
209 yCInfo(YARPROS,
"Welcome to yarpros. Here are the most useful commands available:");
210 usage(
"sniff out <port>",
"suggest .msg for output from <port> ",
"sniff out /grabber");
211 usage(
"sniff in <port>",
"suggest .msg for input to <port> ",
"sniff in /grabber");
212 usage(
"type <name>",
"(MOVED to yarpidl_rosmsg) generate YARP header files from <name>.msg",
"type PointCloud2");
213 usage(
"help",
"show this help",
nullptr);
216 yCInfo(YARPROS,
"YARP clients can use the ROS name server. If you'd prefer to stick");
217 yCInfo(YARPROS,
"with the native YARP name server, the following commands are useful:");
218 usage(
"roscore",
"register port /roscore to refer to ROS_MASTER_URI",
"roscore");
219 usage(
"roscore <hostname> <port number>",
"manually register port /roscore to point to the ros master",
"roscore 192.168.0.1 11311");
220 usage(
"pub[lisher] <node> <topic>",
"register a ROS publisher <node>/<topic> pair as a port called <node><topic>",
"publisher /talker /chatter",
"this registers a port called /talker/chatter");
221 usage(
"pub[lisher] <port> <node> <topic>",
"register a ROS publisher <node>/<topic> pair as a port called <port>",
"publisher /talker /talker /chatter");
222 usage(
"sub[scriber] <node> <topic>",
"register a ROS subscriber <node>/<topic> pair as a port called <node><topic>",
"subscriber /listener /chatter",
"this registers a port called /listener/chatter");
223 usage(
"sub[scriber] <yarp> <node> <topic>",
"register a ROS subscriber <node>/<topic> pair as a port called <port>",
"subscriber /listener /listener /chatter");
224 usage(
"service <yarp> <node> <service>",
"register a ROS service <node>/<service> pair as a port called <port>",
"service /adder /add_two_ints_server /add_two_ints");
225 usage(
"node <name>",
"register a ROS node name with YARP",
"node /talker");
240 const char *hostname,
261 int main(
int argc,
char *argv[]) {
266 if (std::string(argv[1])==
"help" ||
267 std::string(argv[1])==
"--help") {
276 for (
int i=1; i<argc; i++) {
279 if (argv[i][0]!=
'-') {
288 if (options.
check(
"verbose")) {
289 yCWarning(YARPROS,
"The 'verbose' option is deprecated");
296 if (tag==
"roscore") {
299 yCError(YARPROS,
"wrong syntax, run with no arguments for help");
311 yCError(YARPROS,
"cannot find roscore, is ROS_MASTER_URI set?");
320 }
else if (tag==
"node") {
323 yCError(YARPROS,
"wrong syntax, run with no arguments for help");
327 yCError(YARPROS,
"wrong syntax, run with no arguments for help");
341 }
else if (tag==
"publisher"||tag==
"pub"||tag==
"service"||tag==
"srv") {
342 bool service = (tag==
"service"||tag==
"srv");
344 if (cmd.
size()!=3 && cmd.
size()!=4) {
345 yCError(YARPROS,
"wrong syntax, run with no arguments for help");
352 std::string yarp_port = cmd.
get(1+offset).
asString();
353 std::string ros_port = cmd.
get(2+offset).
asString();
356 yarp_port = ros_port + topic;
359 yCDebug(YARPROS,
" * looking up ros node %s", ros_port.c_str());
362 yCDebug(YARPROS,
" * found ros node %s", ros_port.c_str());
363 yCDebug(YARPROS,
" * looking up topic %s", topic.c_str());
366 yCDebug(YARPROS,
" * found topic %s", topic.c_str());
367 string carrier =
"tcpros+role.pub+topic.";
369 carrier =
"rossrv+service.";
372 (carrier+topic).c_str(),
378 }
else if (tag==
"subscriber"||tag==
"sub") {
380 if (cmd.
size()!=3 && cmd.
size()!=4) {
381 yCError(YARPROS,
"wrong syntax, run with no arguments for help");
388 std::string yarp_port = cmd.
get(1+offset).
asString();
389 std::string ros_port = cmd.
get(2+offset).
asString();
392 yarp_port = ros_port + topic;
395 yCDebug(YARPROS,
" * looking up ros node %s", ros_port.c_str());
398 yCDebug(YARPROS,
" * found ros node %s", ros_port.c_str());
400 (
string(
"tcpros+role.sub+topic.")+topic).c_str(),
406 }
else if (tag==
"type") {
407 yCError(YARPROS,
"MOVED: 'yarpros type' is now 'yarpidl_rosmsg'");
409 }
else if (tag==
"sniff") {
411 yCError(YARPROS,
"Show the format of a YARP bottle-compatible message in ROS syntax.");
416 if (dir==
"in") in =
true;
417 else if (dir==
"out") in =
false;
419 yCError(YARPROS,
"Please specify one of 'in' or 'out'.");
424 if (!p.
open(
"..."))
return 1;
439 yCInfo(YARPROS,
"Got message: [%s]",r.c_str());
442 yCError(YARPROS,
"unknown command, run with no arguments for help");
A simple collection of objects that can be described and transmitted in a portable way.
virtual std::int32_t asVocab() const
Get vocabulary identifier as an integer.
std::string toString() const override
Gives a human-readable textual representation of the bottle.
constexpr yarp::conf::vocab32_t createVocab(char a, char b=0, char c=0, char d=0)
size_type size() const
Gets the number of elements in the bottle.
string showFormat(Bottle &b, string root)
#define yCWarning(component,...)
static bool write(const Contact &contact, PortWriter &cmd, PortReader &reply, bool admin=false, bool quiet=false, double timeout=-1)
Send a single command to a port and await a single response.
#define YARP_LOG_COMPONENT(name,...)
void print_callback(yarp::os::Log::LogType type, const char *msg, const char *file, const unsigned int line, const char *func, double systemtime, double networktime, double externaltime, const char *comp_name)
#define BOTTLE_TAG_STRING
int main(int argc, char *argv[])
bool lookupTopic(const std::string &name)
void usage(const char *action, const char *msg, const char *example=nullptr, const char *explanation=nullptr)
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
static yarp::os::Contact getRosCoreAddressFromEnv()
A mini-server for network communication.
virtual bool isString() const
Checks if value is a string.
void fromCommand(int argc, char *argv[], bool skipFirst=true, bool wipe=true)
Interprets a list of command arguments as a list of properties.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
virtual bool isBlob() const
Checks if value is a binary object.
virtual bool isFloat64() const
Checks if value is a 64-bit floating point number.
virtual std::string asString() const
Get string value.
static bool connect(const std::string &src, const std::string &dest, const std::string &carrier="", bool quiet=true)
Request that an output port connect to an input port.
bool register_port(const char *name, const char *carrier, const char *hostname, int portnum, PortReader &reply)
bool announce_port(const char *name, PortReader &reply)
string addPart(string t, string name, int code, Value *val, string orig, string mode="")
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
void addString(const char *str)
Places a string in the bottle, at the end of the list.
virtual bool isList() const
Checks if value is a list.
bool read(PortReader &reader, bool willReply=false) override
Read an object from the port.
bool lookupCore(const std::string &name)
#define yCError(component,...)
#define BOTTLE_TAG_FLOAT64
virtual std::int32_t asInt32() const
Get 32-bit integer value.
#define yCInfo(component,...)
An interface to the operating system, including Port based communication.
#define yCDebug(component,...)
Utilities for manipulating the YARP network, including initialization and shutdown.
The main, catch-all namespace for YARP.
void fromString(const char *str)
Set value to correspond to a textual representation.
virtual Bottle * asList() const
Get list value.
void add(const Value &value)
Add a Value to the bottle, at the end of the list.
std::string toString() const override
Return a standard text representation of the content of the object.
A single value (typically within a Bottle).
static Contact getNameServerContact()
Get the contact information for the port associated with the nameserver (usually "/root",...
virtual size_t asBlobLength() const
Get binary data length.
int getSpecialization()
Get numeric bottle code for this bottle.
virtual yarp::conf::float64_t asFloat64() const
Get 64-bit floating point value.
virtual bool isVocab() const
Checks if value is a vocabulary identifier.
A class for storing options and configuration information.
virtual bool isInt32() const
Checks if value is a 32-bit integer.