YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
FrameTransformServer.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
7
8#include <yarp/os/Log.h>
10#include <yarp/os/LogStream.h>
12
13#include <yarp/math/Math.h>
14
15#include <cmrc/cmrc.hpp>
16#include <mutex>
17#include <fstream>
19
20using namespace yarp::dev;
21using namespace yarp::os;
22using namespace yarp::sig;
23using namespace yarp::math;
24
25namespace {
26YARP_LOG_COMPONENT(FRAMETRANSFORMSERVER, "yarp.device.FrameTransformServer")
27}
28#define LOG_THROTTLE_PERIOD 1.0
29
30//------------------------------------------------------------------------------------------------------------------------------
32{
33 std::lock_guard<std::mutex> lock (m_rpc_mutex);
36 bool ok = in.read(connection);
37 if (!ok) {
38 return false;
39 }
40
41 std::string request = in.get(0).asString();
42 if (request == "help")
43 {
44 out.addVocab32("many");
45 out.addString("No RPC commands available");
46 }
47 else
48 {
49 yCError(FRAMETRANSFORMSERVER, "Invalid vocab received in FrameTransformServer");
50 out.clear();
52 out.addString("Invalid command name");
53 }
54
56 if (returnToSender != nullptr)
57 {
59 }
60 else
61 {
62 yCError(FRAMETRANSFORMSERVER) << "Invalid return to sender";
63 }
64 return true;
65}
66
68{
69 yCWarning(FRAMETRANSFORMSERVER) << "The 'FrameTransformServer' device is experimental and could be modified without any warning";
70
71 if (!this->parseParams(config)) { return false; }
72
73 std::string cfg_string = config.toString();
75 cfg.fromString(cfg_string);
76
77 std::string configuration_to_open;
78 std::string innerFilePath="config_xml/fts_yarp_only.xml";
79 if(!m_testxml_from.empty())
80 {
82 if(!m_testxml_context.empty())
83 {
84 findXml.setDefaultContext(m_testxml_context);
85 }
86 innerFilePath = findXml.findFileByName(m_testxml_from);
87 std::ifstream xmlFile(innerFilePath);
88 std::stringstream stream_file;
89 stream_file << xmlFile.rdbuf();
91 }
92 else
93 {
94 auto fs = cmrc::frameTransformServerRC::get_filesystem();
95 if(!m_filexml_option.empty()) { innerFilePath="config_xml/"+ m_filexml_option;}
96 cfg.unput("filexml_option");
97 auto xmlFile = fs.open(innerFilePath);
98 for(const auto& lemma : xmlFile)
99 {
101 }
102 }
103
104 cfg.unput("local_rpc");
105
107 {
108 yarp::os::Value vval (true);
109 cfg.put("FrameTransform_verbose_debug", vval);
110 }
111
114 if (result.parsingIsSuccessful == false)
115 {
116 yCError(FRAMETRANSFORMSERVER) << "Unable to parse configuration";
117 return false;
118 }
119
120 m_robot = std::move(result.robot);
121
123 return false;
124 }
125
127 return false;
128 }
129
131 {
132 yCError(FRAMETRANSFORMSERVER,"Failed to open rpc port");
133 }
134
136
137 return true;
138}
139
151
155
157
159{
160 yCTrace(FRAMETRANSFORMSERVER, "Thread started");
161 return true;
162}
163
165{
166 yCTrace(FRAMETRANSFORMSERVER, "Thread stopped");
167}
168
170{
171 //Empty (placeholder for future developments)
172}
CMRC_DECLARE(frameTransformServerRC)
constexpr yarp::conf::vocab32_t VOCAB_ERR
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
bool close() override
Close the DeviceDriver.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
void threadRelease() override
Release method.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
yarp::os::Port m_rpc_InterfaceToUser
yarp::robotinterface::Robot m_robot
bool threadInit() override
Initialization method.
void run() override
Loop function.
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
void addVocab32(yarp::conf::vocab32_t x)
Places a vocabulary item in the bottle, at the end of the list.
Definition Bottle.cpp:164
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
Definition Bottle.cpp:240
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Definition Bottle.cpp:246
void clear()
Empties the bottle of any objects it contains.
Definition Bottle.cpp:121
bool write(ConnectionWriter &writer) const override
Output a representation of the bottle to a network connection.
Definition Bottle.cpp:230
void addString(const char *str)
Places a string in the bottle, at the end of the list.
Definition Bottle.cpp:170
A mini-server for performing network communication in the background.
An interface for reading from a network connection.
An interface for writing to a network connection.
An abstraction for a periodic thread.
void askToStop()
Stop the thread.
void setReader(PortReader &reader) override
Set an external reader for port data.
Definition Port.cpp:511
void close() override
Stop port activity.
Definition Port.cpp:363
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
Definition Port.cpp:79
A class for storing options and configuration information.
Definition Property.h:33
Helper class for finding config files and other external resources.
A base class for nested structures that can be searched.
Definition Searchable.h:31
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
A single value (typically within a Bottle).
Definition Value.h:43
virtual std::string asString() const
Get string value.
Definition Value.cpp:234
bool enterPhase(yarp::robotinterface::ActionPhase phase)
Definition Robot.cpp:629
Result of the parsing of yarp::robotinterface::XMLReader.
Definition XMLReader.h:26
bool parsingIsSuccessful
True if the parsing was successful, false otherwise.
Definition XMLReader.h:38
Robot robot
If parsingIsSuccessful is true, contains a valid robot instance.
Definition XMLReader.h:43
Class to read an XML file.
Definition XMLReader.h:52
XMLReaderResult getRobotFromString(const std::string &filename, const yarp::os::Searchable &config=yarp::os::Property())
Parse the XML description of a robotinterface from a string.
#define yCError(component,...)
#define yCTrace(component,...)
#define yCWarning(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
Definition jointData.cpp:13
An interface to the operating system, including Port based communication.