YARP
Yet Another Robot Platform
FrameTransformClient.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef YARP_DEV_FRAMETRANSFORMCLIENT_H
20 #define YARP_DEV_FRAMETRANSFORMCLIENT_H
21 
22 
23 #include <yarp/os/Network.h>
24 #include <yarp/os/BufferedPort.h>
30 #include <yarp/sig/Vector.h>
31 #include <yarp/os/Semaphore.h>
32 #include <yarp/os/Time.h>
33 #include <yarp/dev/PolyDriver.h>
35 #include <yarp/os/PeriodicThread.h>
36 #include <mutex>
37 
38 
39 #define DEFAULT_THREAD_PERIOD 20 //ms
40 const int TRANSFORM_TIMEOUT_MS = 100; //ms
41 const int MAX_PORTS = 5;
42 
43 
45  public yarp::os::BufferedPort<yarp::os::Bottle>
46 {
47 private:
48  yarp::os::Bottle m_lastBottle;
49  yarp::os::Stamp m_lastStamp;
50  double m_deltaT;
51  double m_deltaTMax;
52  double m_deltaTMin;
53  double m_prev;
54  double m_now;
55  int m_state;
56  int m_count;
57 
58  std::vector <yarp::math::FrameTransform> m_transforms;
59 
60 public:
61  std::recursive_mutex m_mutex;
62  size_t size();
63  yarp::math::FrameTransform& operator[] (std::size_t idx);
64  void clear();
65 
66 public:
67  Transforms_client_storage (std::string port_name);
70  bool delete_transform(std::string t1, std::string t2);
71 
72  inline void resetStat();
74  void onRead(yarp::os::Bottle &v) override;
75  inline int getLast(yarp::os::Bottle &data, yarp::os::Stamp &stmp);
76  inline int getIterations();
77  void getEstFrequency(int &ite, double &av, double &min, double &max);
78 };
79 
80 
90  public yarp::os::PortReader,
92 {
93 private:
94  enum ConnectionType {DISCONNECTED = 0, DIRECT, INVERSE, UNDIRECT, IDENTITY};
95 
96  FrameTransformClient::ConnectionType getConnectionType(const std::string &target_frame, const std::string &source_frame, std::string* commonAncestor);
97 
98  bool canExplicitTransform(const std::string& target_frame_id, const std::string& source_frame_id) const;
99  bool getChainedTransform(const std::string &target_frame_id, const std::string &source_frame_id, yarp::sig::Matrix &transform) const;
100 
101 protected:
102 
105  std::string m_local_name;
106  std::string m_remote_name;
107 
108  std::string m_local_rpcServer;
109  std::string m_local_rpcUser;
110  std::string m_remote_rpc;
113 
116  double m_period;
117  std::mutex m_rpc_mutex;
119  {
120  std::string format;
122  std::string transform_src;
123  std::string transform_dst;
124  };
125  std::vector<broadcast_port_t*> m_array_of_ports;
126 
127 public:
128 
129  /* DeviceDriver methods */
130  bool open(yarp::os::Searchable& config) override;
131  bool close() override;
132  bool read(yarp::os::ConnectionReader& connection) override;
133 
134  /* IPreciselyTimed methods */
140 
141  bool allFramesAsString(std::string &all_frames) override;
142  bool canTransform(const std::string &target_frame, const std::string &source_frame) override;
143  bool clear() override;
144  bool frameExists(const std::string &frame_id) override;
145  bool getAllFrameIds(std::vector< std::string > &ids) override;
146  bool getParent(const std::string &frame_id, std::string &parent_frame_id) override;
147  bool getTransform(const std::string &target_frame_id, const std::string &source_frame_id, yarp::sig::Matrix &transform) override;
148  bool setTransform(const std::string &target_frame_id, const std::string &source_frame_id, const yarp::sig::Matrix &transform) override;
149  bool setTransformStatic(const std::string &target_frame_id, const std::string &source_frame_id, const yarp::sig::Matrix &transform) override;
150  bool deleteTransform(const std::string &target_frame_id, const std::string &source_frame_id) override;
151  bool transformPoint(const std::string &target_frame_id, const std::string &source_frame_id, const yarp::sig::Vector &input_point, yarp::sig::Vector &transformed_point) override;
152  bool transformPose(const std::string &target_frame_id, const std::string &source_frame_id, const yarp::sig::Vector &input_pose, yarp::sig::Vector &transformed_pose) override;
153  bool transformQuaternion(const std::string &target_frame_id, const std::string &source_frame_id, const yarp::math::Quaternion &input_quaternion, yarp::math::Quaternion &transformed_quaternion) override;
154  bool waitForTransform(const std::string &target_frame_id, const std::string &source_frame_id, const double &timeout) override;
155 
156  bool isConnectedWithServer() override;
157  bool reconnectWithServer() override;
158 
161  bool threadInit() override;
162  void threadRelease() override;
163  void run() override;
164 };
165 
166 #endif // YARP_DEV_FRAMETRANSFORMCLIENT_H
Transforms_client_storage::~Transforms_client_storage
~Transforms_client_storage()
Definition: FrameTransformClient.cpp:180
FrameTransformClient::transformQuaternion
bool transformQuaternion(const std::string &target_frame_id, const std::string &source_frame_id, const yarp::math::Quaternion &input_quaternion, yarp::math::Quaternion &transformed_quaternion) override
Transform a quaternion into the target frame.
Definition: FrameTransformClient.cpp:887
FrameTransformClient::m_rpc_mutex
std::mutex m_rpc_mutex
Definition: FrameTransformClient.h:117
Transforms_client_storage::Transforms_client_storage
Transforms_client_storage(std::string port_name)
Definition: FrameTransformClient.cpp:164
yarp::os::Bottle
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
Transforms_client_storage::operator[]
yarp::math::FrameTransform & operator[](std::size_t idx)
Definition: FrameTransformClient.cpp:192
Transforms_client_storage
Definition: FrameTransformClient.h:46
yarp::math::FrameTransform
Definition: FrameTransform.h:21
FrameTransformClient::broadcast_port_t::format
std::string format
Definition: FrameTransformClient.h:120
Network.h
Transforms_client_storage::clear
void clear()
Definition: FrameTransformClient.cpp:158
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
Transforms_client_storage::delete_transform
bool delete_transform(std::string t1, std::string t2)
Transforms_client_storage::getEstFrequency
void getEstFrequency(int &ite, double &av, double &min, double &max)
Definition: FrameTransformClient.cpp:141
Transforms_client_storage::m_mutex
std::recursive_mutex m_mutex
Definition: FrameTransformClient.h:61
Vector.h
contains the definition of a Vector type
FrameTransformClient::m_remote_streaming_name
std::string m_remote_streaming_name
Definition: FrameTransformClient.h:111
t
float t
Definition: FfmpegWriter.cpp:74
FrameTransformClient::open
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
Definition: FrameTransformClient.cpp:396
FrameTransformClient::FrameTransformClient
FrameTransformClient()
Definition: FrameTransformClient.cpp:917
TRANSFORM_TIMEOUT_MS
const int TRANSFORM_TIMEOUT_MS
Definition: FrameTransformClient.h:40
IPreciselyTimed.h
yarp::dev::DeviceDriver
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
FrameTransformClient::run
void run() override
Loop function.
Definition: FrameTransformClient.cpp:936
yarp::dev::IFrameTransformClientControl
IFrameTransformClientControl Interface.
Definition: IFrameTransformClientControl.h:29
FrameTransformClient::waitForTransform
bool waitForTransform(const std::string &target_frame_id, const std::string &source_frame_id, const double &timeout) override
Block until a transform from source_frame_id to target_frame_id is possible or it times out.
Definition: FrameTransformClient.cpp:901
FrameTransformClient::m_array_of_ports
std::vector< broadcast_port_t * > m_array_of_ports
Definition: FrameTransformClient.h:125
FrameTransformClient::getTransform
bool getTransform(const std::string &target_frame_id, const std::string &source_frame_id, yarp::sig::Matrix &transform) override
Get the transform between two frames.
Definition: FrameTransformClient.cpp:665
ControlBoardHelpers.h
FrameTransformClient::allFramesAsString
bool allFramesAsString(std::string &all_frames) override
Creates a debug string containing the list of all registered frames.
Definition: FrameTransformClient.cpp:476
ControlBoardInterfaces.h
define control board standard interfaces
yarp::dev::IFrameTransform
Transform Interface.
Definition: IFrameTransform.h:33
Transforms_client_storage::resetStat
void resetStat()
Definition: FrameTransformClient.cpp:40
MAX_PORTS
const int MAX_PORTS
Definition: FrameTransformClient.h:41
FrameTransformClient::reconnectWithServer
bool reconnectWithServer() override
Attempts to reconnect the client with the server.
Definition: FrameTransformClient.cpp:975
FrameTransformClient::getParent
bool getParent(const std::string &frame_id, std::string &parent_frame_id) override
Get the parent of a frame.
Definition: FrameTransformClient.cpp:603
yarp::sig::VectorOf< double >
yarp::os::Port
A mini-server for network communication.
Definition: Port.h:50
yarp::os::BufferedPort
A mini-server for performing network communication in the background.
Definition: BufferedPort.h:64
FrameTransformClient::transformPose
bool transformPose(const std::string &target_frame_id, const std::string &source_frame_id, const yarp::sig::Vector &input_pose, yarp::sig::Vector &transformed_pose) override
Transform a Stamped Pose into the target frame.
Definition: FrameTransformClient.cpp:853
FrameTransformClient::isConnectedWithServer
bool isConnectedWithServer() override
Returns true if the client is connected with the server, false otherwise.
Definition: FrameTransformClient.cpp:964
FrameTransformClient::m_transform_storage
Transforms_client_storage * m_transform_storage
Definition: FrameTransformClient.h:115
yarp::os::PortReader
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:28
FrameTransformClient::broadcast_port_t::port
yarp::os::Port port
Definition: FrameTransformClient.h:121
PolyDriver.h
FrameTransformClient::close
bool close() override
Close the DeviceDriver.
Definition: FrameTransformClient.cpp:464
FrameTransformClient
transformClient: Documentation to be added
Definition: FrameTransformClient.h:92
Transforms_client_storage::getLast
int getLast(yarp::os::Bottle &data, yarp::os::Stamp &stmp)
Definition: FrameTransformClient.cpp:119
yarp::math::Quaternion
Definition: Quaternion.h:27
FrameTransformClient::m_local_rpcUser
std::string m_local_rpcUser
Definition: FrameTransformClient.h:109
FrameTransformClient::m_local_name
std::string m_local_name
Definition: FrameTransformClient.h:105
FrameTransformClient::getLastInputStamp
yarp::os::Stamp getLastInputStamp()
Get the time stamp for the last read data.
Transforms_client_storage::getIterations
int getIterations()
Definition: FrameTransformClient.cpp:133
Transforms_client_storage::set_transform
bool set_transform(yarp::math::FrameTransform t)
FrameTransformClient::canTransform
bool canTransform(const std::string &target_frame, const std::string &source_frame) override
Test if a transform exists.
Definition: FrameTransformClient.cpp:538
Transforms_client_storage::onRead
void onRead(yarp::os::Bottle &v) override
Definition: FrameTransformClient.cpp:45
Semaphore.h
BufferedPort.h
FrameTransformClient::transformPoint
bool transformPoint(const std::string &target_frame_id, const std::string &source_frame_id, const yarp::sig::Vector &input_point, yarp::sig::Vector &transformed_point) override
Transform a point into the target frame.
Definition: FrameTransformClient.cpp:833
yarp::os::PeriodicThread
An abstraction for a periodic thread.
Definition: PeriodicThread.h:25
FrameTransformClient::clear
bool clear() override
Removes all the registered transforms.
Definition: FrameTransformClient.cpp:543
FrameTransformClient::setTransformStatic
bool setTransformStatic(const std::string &target_frame_id, const std::string &source_frame_id, const yarp::sig::Matrix &transform) override
Register a static transform between two frames.
Definition: FrameTransformClient.cpp:754
FrameTransformClient::m_remote_name
std::string m_remote_name
Definition: FrameTransformClient.h:106
FrameTransformClient::broadcast_port_t::transform_src
std::string transform_src
Definition: FrameTransformClient.h:122
FrameTransformClient::m_local_rpcServer
std::string m_local_rpcServer
Definition: FrameTransformClient.h:108
PeriodicThread.h
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
FrameTransformClient::m_rpc_InterfaceToUser
yarp::os::Port m_rpc_InterfaceToUser
Definition: FrameTransformClient.h:104
yarp::os::Stamp
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:25
FrameTransformClient::broadcast_port_t::transform_dst
std::string transform_dst
Definition: FrameTransformClient.h:123
FrameTransformClient::m_period
double m_period
Definition: FrameTransformClient.h:116
FrameTransformClient::setTransform
bool setTransform(const std::string &target_frame_id, const std::string &source_frame_id, const yarp::sig::Matrix &transform) override
Register a transform between two frames.
Definition: FrameTransformClient.cpp:700
Transforms_client_storage::size
size_t size()
Definition: FrameTransformClient.cpp:186
FrameTransform.h
FrameTransformClient::deleteTransform
bool deleteTransform(const std::string &target_frame_id, const std::string &source_frame_id) override
Deletes a transform between two frames.
Definition: FrameTransformClient.cpp:808
FrameTransformClient::m_remote_rpc
std::string m_remote_rpc
Definition: FrameTransformClient.h:110
Time.h
FrameTransformClient::read
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: FrameTransformClient.cpp:199
FrameTransformClient::m_local_streaming_name
std::string m_local_streaming_name
Definition: FrameTransformClient.h:112
FrameTransformClient::m_rpc_InterfaceToServer
yarp::os::Port m_rpc_InterfaceToServer
Definition: FrameTransformClient.h:103
FrameTransformClient::getAllFrameIds
bool getAllFrameIds(std::vector< std::string > &ids) override
Gets a vector containing all the registered frames.
Definition: FrameTransformClient.cpp:578
FrameTransformClient::threadRelease
void threadRelease() override
Release method.
Definition: FrameTransformClient.cpp:931
FrameTransformClient::m_streaming_connection_type
std::string m_streaming_connection_type
Definition: FrameTransformClient.h:114
FrameTransformClient::frameExists
bool frameExists(const std::string &frame_id) override
Check if a frame exists.
Definition: FrameTransformClient.cpp:568
FrameTransformClient::threadInit
bool threadInit() override
Initialization method.
Definition: FrameTransformClient.cpp:925
IFrameTransform.h
FrameTransformClient::broadcast_port_t
Definition: FrameTransformClient.h:119
IFrameTransformClientControl.h
FrameTransformClient::~FrameTransformClient
~FrameTransformClient()
yarp::sig::Matrix
A class for a Matrix.
Definition: Matrix.h:46