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>
16#include <yarp/sig/Vector.h>
17#include <yarp/os/Semaphore.h>
18#include <yarp/os/Time.h>
19#include <yarp/os/Stamp.h>
20#include <yarp/dev/PolyDriver.h>
23#include <mutex>
24
25
26#define DEFAULT_THREAD_PERIOD 20 //ms
27const int TRANSFORM_TIMEOUT_MS = 100; //ms
28const int MAX_PORTS = 5;
29
30
32 public yarp::os::BufferedPort<yarp::os::Bottle>
33{
34private:
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
47public:
48 std::recursive_mutex m_mutex;
49 size_t size();
51 void clear();
52
53public:
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
79{
80private:
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
88protected:
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
114public:
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 bool allFramesAsString(std::string &all_frames) override;
122 bool canTransform(const std::string &target_frame, const std::string &source_frame) override;
123 bool clear() override;
124 bool frameExists(const std::string &frame_id) override;
125 bool getAllFrameIds(std::vector< std::string > &ids) override;
126 bool getParent(const std::string &frame_id, std::string &parent_frame_id) override;
127 bool getTransform(const std::string &target_frame_id, const std::string &source_frame_id, yarp::sig::Matrix &transform) override;
128 bool setTransform(const std::string &target_frame_id, const std::string &source_frame_id, const yarp::sig::Matrix &transform) override;
129 bool setTransformStatic(const std::string &target_frame_id, const std::string &source_frame_id, const yarp::sig::Matrix &transform) override;
130 bool deleteTransform(const std::string &target_frame_id, const std::string &source_frame_id) override;
131 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;
132 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;
133 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;
134 bool waitForTransform(const std::string &target_frame_id, const std::string &source_frame_id, const double &timeout) override;
135
136 bool isConnectedWithServer() override;
137 bool reconnectWithServer() override;
138
141 bool threadInit() override;
142 void threadRelease() override;
143 void run() override;
144};
145
146#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.
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
Callback method.
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:30
IFrameTransformClientControl Interface.
Transform Interface.
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:64
A mini-server for performing network communication in the background.
Definition: BufferedPort.h:60
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:24
A mini-server for network communication.
Definition: Port.h:46
A base class for nested structures that can be searched.
Definition: Searchable.h:63
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:21
A class for a Matrix.
Definition: Matrix.h:39
const int TRANSFORM_TIMEOUT_MS
const int MAX_PORTS