YARP
Yet Another Robot Platform
transformClient.h
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 
6 #ifndef YARP_DEV_FRAMETRANSFORMCLIENT_H
7 #define YARP_DEV_FRAMETRANSFORMCLIENT_H
8 
9 
10 #include <yarp/os/Network.h>
11 #include <yarp/os/BufferedPort.h>
17 #include <yarp/sig/Vector.h>
18 #include <yarp/os/Semaphore.h>
19 #include <yarp/os/Time.h>
20 #include <yarp/dev/PolyDriver.h>
22 #include <yarp/os/PeriodicThread.h>
23 #include <mutex>
24 
25 
26 #define DEFAULT_THREAD_PERIOD 20 //ms
27 const int TRANSFORM_TIMEOUT_MS = 100; //ms
28 const int MAX_PORTS = 5;
29 
30 
32  public yarp::os::BufferedPort<yarp::os::Bottle>
33 {
34 private:
35  yarp::os::Bottle m_lastBottle;
36  yarp::os::Stamp m_lastStamp;
37  double m_deltaT;
38  double m_deltaTMax;
39  double m_deltaTMin;
40  double m_prev;
41  double m_now;
42  int m_state;
43  int m_count;
44 
45  std::vector <yarp::math::FrameTransform> m_transforms;
46 
47 public:
48  std::recursive_mutex m_mutex;
49  size_t size();
51  void clear();
52 
53 public:
54  Transforms_client_storage (std::string port_name);
57  bool delete_transform(std::string t1, std::string t2);
58 
59  inline void resetStat();
61  void onRead(yarp::os::Bottle &v) override;
62  inline int getLast(yarp::os::Bottle &data, yarp::os::Stamp &stmp);
63  inline int getIterations();
64  void getEstFrequency(int &ite, double &av, double &min, double &max);
65 };
66 
67 
77  public yarp::os::PortReader,
79 {
80 private:
81  enum ConnectionType {DISCONNECTED = 0, DIRECT, INVERSE, UNDIRECT, IDENTITY};
82 
83  TransformClient::ConnectionType getConnectionType(const std::string &target_frame, const std::string &source_frame, std::string* commonAncestor);
84 
85  bool canExplicitTransform(const std::string& target_frame_id, const std::string& source_frame_id) const;
86  bool getChainedTransform(const std::string &target_frame_id, const std::string &source_frame_id, yarp::sig::Matrix &transform) const;
87 
88 protected:
89 
92  std::string m_local_name;
93  std::string m_remote_name;
94 
95  std::string m_local_rpcServer;
96  std::string m_local_rpcUser;
97  std::string m_remote_rpc;
100 
103  double m_period;
104  std::mutex m_rpc_mutex;
106  {
107  std::string format;
109  std::string transform_src;
110  std::string transform_dst;
111  };
112  std::vector<broadcast_port_t*> m_array_of_ports;
113 
114 public:
115 
116  /* DeviceDriver methods */
117  bool open(yarp::os::Searchable& config) override;
118  bool close() override;
119  bool read(yarp::os::ConnectionReader& connection) override;
120 
121  /* IPreciselyTimed methods */
127 
128  bool allFramesAsString(std::string &all_frames) override;
129  bool canTransform(const std::string &target_frame, const std::string &source_frame) override;
130  bool clear() override;
131  bool frameExists(const std::string &frame_id) override;
132  bool getAllFrameIds(std::vector< std::string > &ids) override;
133  bool getParent(const std::string &frame_id, std::string &parent_frame_id) override;
134  bool getTransform(const std::string &target_frame_id, const std::string &source_frame_id, yarp::sig::Matrix &transform) override;
135  bool setTransform(const std::string &target_frame_id, const std::string &source_frame_id, const yarp::sig::Matrix &transform) override;
136  bool setTransformStatic(const std::string &target_frame_id, const std::string &source_frame_id, const yarp::sig::Matrix &transform) override;
137  bool deleteTransform(const std::string &target_frame_id, const std::string &source_frame_id) override;
138  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;
139  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;
140  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;
141  bool waitForTransform(const std::string &target_frame_id, const std::string &source_frame_id, const double &timeout) override;
142 
143  bool isConnectedWithServer() override;
144  bool reconnectWithServer() override;
145 
146  TransformClient();
148  bool threadInit() override;
149  void threadRelease() override;
150  void run() override;
151 };
152 
153 #endif // YARP_DEV_FRAMETRANSFORMCLIENT_H
define control board standard interfaces
float t
contains the definition of a Vector type
transformClient deprecated: Documentation to be added
yarp::os::Port m_rpc_InterfaceToServer
bool canTransform(const std::string &target_frame, const std::string &source_frame) override
Test if a transform exists.
std::string m_remote_streaming_name
bool allFramesAsString(std::string &all_frames) override
Creates a debug string containing the list of all registered frames.
void run() override
Loop function.
bool clear() override
Removes all the registered transforms.
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.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
std::string m_local_rpcUser
bool isConnectedWithServer() override
Returns true if the client is connected with the server, false otherwise.
yarp::os::Port m_rpc_InterfaceToUser
bool getAllFrameIds(std::vector< std::string > &ids) override
Gets a vector containing all the registered frames.
std::vector< broadcast_port_t * > m_array_of_ports
std::string m_remote_name
std::mutex m_rpc_mutex
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.
void threadRelease() override
Release method.
bool reconnectWithServer() override
Attempts to reconnect the client with the server.
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.
std::string m_local_rpcServer
std::string m_streaming_connection_type
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
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.
bool close() override
Close the DeviceDriver.
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.
std::string m_local_name
bool deleteTransform(const std::string &target_frame_id, const std::string &source_frame_id) override
Deletes a transform between two frames.
std::string m_remote_rpc
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.
yarp::os::Stamp getLastInputStamp()
Get the time stamp for the last read data.
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.
bool frameExists(const std::string &frame_id) override
Check if a frame exists.
bool threadInit() override
Initialization method.
std::string m_local_streaming_name
Transforms_client_storage * m_transform_storage
bool getParent(const std::string &frame_id, std::string &parent_frame_id) override
Get the parent of a frame.
void onRead(yarp::os::Bottle &v) override
bool set_transform(yarp::math::FrameTransform t)
int getLast(yarp::os::Bottle &data, yarp::os::Stamp &stmp)
std::recursive_mutex m_mutex
void getEstFrequency(int &ite, double &av, double &min, double &max)
Transforms_client_storage(std::string port_name)
bool delete_transform(std::string t1, std::string t2)
yarp::math::FrameTransform & operator[](std::size_t idx)
Interface implemented by all device drivers.
Definition: DeviceDriver.h:35
IFrameTransformClientControl Interface.
Transform Interface.
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:74
A mini-server for performing network communication in the background.
Definition: BufferedPort.h:61
An interface for reading from a network connection.
An abstraction for a periodic thread.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:25
A mini-server for network communication.
Definition: Port.h:47
A base class for nested structures that can be searched.
Definition: Searchable.h:66
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:22
A class for a Matrix.
Definition: Matrix.h:43
const int TRANSFORM_TIMEOUT_MS
const int MAX_PORTS