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 
92  public yarp::os::PortReader,
94 {
95 private:
96  enum ConnectionType {DISCONNECTED = 0, DIRECT, INVERSE, UNDIRECT, IDENTITY};
97 
98  FrameTransformClient::ConnectionType getConnectionType(const std::string &target_frame, const std::string &source_frame, std::string* commonAncestor);
99 
100  bool canExplicitTransform(const std::string& target_frame_id, const std::string& source_frame_id) const;
101  bool getChainedTransform(const std::string &target_frame_id, const std::string &source_frame_id, yarp::sig::Matrix &transform) const;
102 
103 protected:
104 
107  std::string m_local_name;
108  std::string m_remote_name;
109 
110  std::string m_local_rpcServer;
111  std::string m_local_rpcUser;
112  std::string m_remote_rpc;
115 
118  double m_period;
119  std::mutex m_rpc_mutex;
121  {
122  std::string format;
124  std::string transform_src;
125  std::string transform_dst;
126  };
127  std::vector<broadcast_port_t*> m_array_of_ports;
128 
129 public:
130 
131  /* DeviceDriver methods */
132  bool open(yarp::os::Searchable& config) override;
133  bool close() override;
134  bool read(yarp::os::ConnectionReader& connection) override;
135 
136  /* IPreciselyTimed methods */
142 
143  bool allFramesAsString(std::string &all_frames) override;
144  bool canTransform(const std::string &target_frame, const std::string &source_frame) override;
145  bool clear() override;
146  bool frameExists(const std::string &frame_id) override;
147  bool getAllFrameIds(std::vector< std::string > &ids) override;
148  bool getParent(const std::string &frame_id, std::string &parent_frame_id) override;
149  bool getTransform(const std::string &target_frame_id, const std::string &source_frame_id, yarp::sig::Matrix &transform) override;
150  bool setTransform(const std::string &target_frame_id, const std::string &source_frame_id, const yarp::sig::Matrix &transform) override;
151  bool setTransformStatic(const std::string &target_frame_id, const std::string &source_frame_id, const yarp::sig::Matrix &transform) override;
152  bool deleteTransform(const std::string &target_frame_id, const std::string &source_frame_id) override;
153  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;
154  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;
155  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;
156  bool waitForTransform(const std::string &target_frame_id, const std::string &source_frame_id, const double &timeout) override;
157 
158  bool isConnectedWithServer() override;
159  bool reconnectWithServer() override;
160 
163  bool threadInit() override;
164  void threadRelease() override;
165  void run() override;
166 };
167 
168 #endif // YARP_DEV_FRAMETRANSFORMCLIENT_H
define control board standard interfaces
float t
const int TRANSFORM_TIMEOUT_MS
const int MAX_PORTS
contains the definition of a Vector type
The client side of any IBattery capable device.
bool reconnectWithServer() override
Attempts to reconnect the client with the server.
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.
bool getAllFrameIds(std::vector< std::string > &ids) override
Gets a vector containing all the registered frames.
bool allFramesAsString(std::string &all_frames) override
Creates a debug string containing the list of all registered frames.
bool getParent(const std::string &frame_id, std::string &parent_frame_id) override
Get the parent of a frame.
void threadRelease() override
Release method.
std::string m_streaming_connection_type
Transforms_client_storage * m_transform_storage
void run() override
Loop function.
bool deleteTransform(const std::string &target_frame_id, const std::string &source_frame_id) override
Deletes a transform between two frames.
bool isConnectedWithServer() override
Returns true if the client is connected with the server, false otherwise.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
yarp::os::Stamp getLastInputStamp()
Get the time stamp for the last read data.
bool close() override
Close the DeviceDriver.
yarp::os::Port m_rpc_InterfaceToServer
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.
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.
bool clear() override
Removes all the registered transforms.
std::vector< broadcast_port_t * > m_array_of_ports
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
bool threadInit() override
Initialization method.
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 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 frameExists(const std::string &frame_id) override
Check if a frame exists.
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.
yarp::os::Port m_rpc_InterfaceToUser
bool canTransform(const std::string &target_frame, const std::string &source_frame) override
Test if a transform exists.
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.
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:38
IFrameTransformClientControl Interface.
Transform Interface.
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
A mini-server for performing network communication in the background.
Definition: BufferedPort.h:64
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:28
A mini-server for network communication.
Definition: Port.h:50
A base class for nested structures that can be searched.
Definition: Searchable.h:69
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:25
A class for a Matrix.
Definition: Matrix.h:46