YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025-2025 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
8#include <yarp/os/Network.h>
9#include <yarp/os/LogStream.h>
10#include<fstream>
11
12using namespace std;
13using namespace yarp::os;
14using namespace yarp::dev;
15
16namespace
17{
18 YARP_LOG_COMPONENT(YARPDESCINFO, "yarp.yarpRobotDescriptionInfo")
19}
20
22{
23 yCInfo(YARPDESCINFO) << "This is the tool yarpRobotDescriptionInfo.";
24 yCInfo(YARPDESCINFO) << "By default it prints on screen all the connections found on the yarp network.";
25 yCInfo(YARPDESCINFO) << "use the --file <filename> to choose the name of the output file. (default: outputfile.dot) ";
26 yCInfo(YARPDESCINFO) << "use the --remote <remote_port> to select a specific the robotDescription_nws_yarp rpc port (default: /robotDescription_nws_yarp/rpc)";
27 yCInfo(YARPDESCINFO) << "use an online dot editor (e.g. https://dreampuf.github.io/GraphvizOnline) to visualize the graph.";
28}
29
30int main(int argc, char *argv[])
31{
33
35 if (argc > 1) {
36 p.fromCommand(argc, argv);
37 }
38
39 std::string filename = "outputfile.dot";
40 std::string remotename = "/robotDescription_nws_yarp/rpc";
41
42 if (p.check("file"))
43 {
44 filename = p.find("file").asString();
45 }
46 if (p.check("remote")) {
47 remotename = p.find("remote").asString();
48 }
49
52 pcfg.put("device", "robotDescription_nwc_yarp");
53 pcfg.put("local", "/robotDescription_nwc_yarp/rpc");
54 pcfg.put("remote", remotename);
55 pp.open(pcfg);
56 IRobotDescription* idesc = nullptr;
57 pp.view(idesc);
58
59 std::vector<yarp::dev::DeviceDescription> devlist;
61 if (idesc)
62 {
63 ret = idesc->getAllDevices(devlist);
64 }
65
66 std::ofstream file;
67 file.open(filename.c_str(), std::ios::out);
68 file << "digraph G" << endl;
69 file << "{" << endl;
70 file << " splines = \"compound\"" << endl;
71 file << " rankdir= \"TB\"" << endl;
72 file << " subgraph cluster_net" << endl;
73 file << " {" << endl;
74
75#if 0
77d1.device_name = "left_arm_b1";
78d1.device_type = "ControlBoard";
80d2.device_name = "left_arm_b2";
81d2.device_type = "ControlBoard";
83d3.device_name = "left_arm_Remapper";
84d3.device_type = "ControlBoardRemapper";
85d3.device_extra_info = "left_arm_b1 left_arm_b2";
87d4.device_name = "left_arm_NWS";
88d4.device_type = "ControlBoard_nws_yarp";
89d4.device_extra_info = "left_arm_Remapper";
90devlist.push_back(d1);
91devlist.push_back(d2);
92devlist.push_back(d3);
93devlist.push_back(d4);
94#endif
95
96 for (auto it = devlist.begin(); it != devlist.end(); it++)
97 {
98 string dname = it->device_name;
99 string dtype = it->device_type;
100 if (dtype.find("nws_yarp") != std::string::npos)
101 {
102 file << " node_" << dname << "[label = <<FONT COLOR=\"red\" > " << dtype << "</FONT><BR/><FONT COLOR= \"black\"> " << dname << "</FONT> > shape=box style=filled fillcolor=lightblue];" << endl;
103 }
104 else
105 {
106 file << " node_" << dname << "[label = <<FONT COLOR=\"red\" > " << dtype << "</FONT><BR/><FONT COLOR= \"black\"> " << dname << "</FONT> > shape=box];" << endl;
107 }
108 }
109 file << endl;
110
111 for (auto it = devlist.begin(); it != devlist.end(); it++)
112 {
113 string src = it->device_name;
114 string extra = it->device_extra_info;
115 std::vector<std::string> tokens;
116 std::string token;
117 std::istringstream extrastream(extra);
118 while (extrastream >> token) {tokens.push_back(token);}
119 for (auto it2 = tokens.begin(); it2!=tokens.end(); it2++)
120 {
121 string dest = *it2;
122 file << " node_" << src << " -> " << "node_" << dest << endl;
123 }
124 }
125 file << endl;
126
127 file << " label = yarprobotinterface"<< endl;
128 file << " }" << endl;
129 file << "}" << endl << endl;
130 file.close();
131
132 return 1;
133}
134
135/********************
136* dot file example
137*********************
138
139digraph G {
140
141 splines="compound"
142
143 rankdir="TB"
144 subgraph cluster_net {
145
146 node1 [label=<<FONT COLOR="red">ControlBoard_nws_yarp</FONT><BR/><FONT COLOR="black">left_arm</FONT>> shape=box];
147 node_mot1 [label=<<FONT COLOR="red">Motor Control</FONT><BR/><FONT COLOR="black">left_arm_j0-1</FONT>> shape=box];
148 node_mot2 [label=<<FONT COLOR="red">Motor Control</FONT><BR/><FONT COLOR="black">left_arm_j2-3</FONT>> shape=box];
149 node_mot3 [label=<<FONT COLOR="red">Motor Control</FONT><BR/><FONT COLOR="black">left_arm_j4-j6</FONT>> shape=box];
150 node_mot4 [label=<<FONT COLOR="red">Motor Control</FONT><BR/><FONT COLOR="black">left_arm_j7-j10</FONT>> shape=box];
151 node_mot5 [label=<<FONT COLOR="red">Motor Control</FONT><BR/><FONT COLOR="black">left_arm_j11-j12</FONT>> shape=box];
152 node100 [label=<<FONT COLOR="red">ControlBoard_nws_yarp</FONT><BR/><FONT COLOR="black">all_joints</FONT>> shape=box];
153 node101 [label=<<FONT COLOR="red">ControlBoard_nws_ros2</FONT><BR/><FONT COLOR="black">all_joints</FONT>> shape=box];
154 node_remap1 [label=<<FONT COLOR="red">ControlBoard_remapper</FONT><BR/><FONT COLOR="black">left_arm_remapper</FONT>> shape=box];
155 node_remap1b [label=<<FONT COLOR="red">ControlBoard_remapper</FONT><BR/><FONT COLOR="black">left_arm_no_hand_remapper</FONT>> shape=box];
156 node_remap2 [label=<<FONT COLOR="red">ControlBoard_remapper</FONT><BR/><FONT COLOR="black">all_joints</FONT>> shape=box];
157 node_calib [label=<<FONT COLOR="red">Calibrator</FONT><BR/><FONT COLOR="black">left_arm_calibrator</FONT>> shape=box];
158
159 node1 -> node_remap1
160 node_remap1 -> node_mot1
161 node_remap1 -> node_mot2
162 node_remap1 -> node_mot3
163 node_remap1 -> node_mot4
164 node_remap1 -> node_mot5
165 node_calib -> node_remap1
166 node_remap1b -> node_mot1
167 node_remap1b -> node_mot2
168 node_remap1b -> node_mot3
169 node_remap2 -> node_mot1
170 node_remap2 -> node_mot2
171 node_remap2 -> node_mot3
172 node_remap2 -> node_mot4
173 node_remap2 -> node_mot5
174 node100 -> node_remap2
175 node101 -> node_remap2
176
177 label = yarprobotinterface
178}
179}
180*/
bool ret
This interface allows users to retrieve a list which contains the names and the types of the currentl...
A container for a device driver.
Definition PolyDriver.h:23
A mini-server for performing network communication in the background.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
Utilities for manipulating the YARP network, including initialization and shutdown.
Definition Network.h:706
A class for storing options and configuration information.
Definition Property.h:33
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
bool check(const std::string &key) const override
Check if there exists a property of the given name.
void fromCommand(int argc, char *argv[], bool skipFirst=true, bool wipe=true)
Interprets a list of command arguments as a list of properties.
virtual std::string asString() const
Get string value.
Definition Value.cpp:246
int main(int argc, char *argv[])
Definition main.cpp:30
void display_help()
Definition main.cpp:21
#define yCInfo(component,...)
#define YARP_LOG_COMPONENT(name,...)
STL namespace.
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.
The main, catch-all namespace for YARP.
Definition dirs.h:16