YARP
Yet Another Robot Platform
FrameTransformServer.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_FRAMETRANSFORMSERVER_FRAMETRANSFORMSERVER_H
20 #define YARP_DEV_FRAMETRANSFORMSERVER_FRAMETRANSFORMSERVER_H
21 
22 #include <vector>
23 #include <iostream>
24 #include <string>
25 #include <sstream>
26 #include <mutex>
27 
28 #include <yarp/os/Network.h>
29 #include <yarp/os/Port.h>
30 #include <yarp/os/BufferedPort.h>
31 #include <yarp/os/Bottle.h>
32 #include <yarp/os/Time.h>
33 #include <yarp/os/Property.h>
34 
35 #include <yarp/os/PeriodicThread.h>
36 #include <yarp/os/BufferedPort.h>
37 #include <yarp/os/Stamp.h>
38 #include <yarp/os/RpcServer.h>
39 #include <yarp/sig/Vector.h>
40 
41 #include <yarp/dev/PolyDriver.h>
42 #include <yarp/dev/DeviceDriver.h>
43 #include <yarp/dev/api.h>
44 #include <yarp/os/Publisher.h>
45 #include <yarp/os/Subscriber.h>
46 #include <yarp/os/Node.h>
48 
50 
53 
54 
55 #define ROSNODENAME "/tfNode"
56 #define ROSTOPICNAME_TF "/tf"
57 #define ROSTOPICNAME_TF_STATIC "/tf_static"
58 #define DEFAULT_THREAD_PERIOD 0.02 //s
59 
61 {
62 private:
63  std::vector <yarp::math::FrameTransform> m_transforms;
64  std::mutex m_mutex;
65 
66 public:
70  bool delete_transform (int id);
71  bool delete_transform (std::string t1, std::string t2);
72  inline size_t size() { return m_transforms.size(); }
73  inline yarp::math::FrameTransform& operator[] (std::size_t idx) { return m_transforms[idx]; }
74  void clear ();
75 };
76 
86 {
87 public:
90 
91  bool open(yarp::os::Searchable &params) override;
92  bool close() override;
94 
95  bool threadInit() override;
96  void threadRelease() override;
97  void run() override;
98 
99 private:
100  std::mutex m_mutex;
101  std::string m_streamingPortName;
102  std::string m_rpcPortName;
103  yarp::os::Stamp m_lastStateStamp;
104  double m_period;
105  yarp::os::Node* m_rosNode;
106  bool m_enable_publish_ros_tf;
107  bool m_enable_subscribe_ros_tf;
108  Transforms_server_storage* m_ros_timed_transform_storage;
109  Transforms_server_storage* m_ros_static_transform_storage;
110  Transforms_server_storage* m_yarp_timed_transform_storage;
111  Transforms_server_storage* m_yarp_static_transform_storage;
112  double m_FrameTransformTimeout;
113 
114  enum show_transforms_in_diagram_t
115  {
116  do_not_show=0,
117  show_quaternion=1,
118  show_matrix=2,
119  show_rpy=3
120  };
121  show_transforms_in_diagram_t m_show_transforms_in_diagram= do_not_show;
122 
123  yarp::os::RpcServer m_rpcPort;
125  yarp::os::Publisher<yarp::rosmsg::tf2_msgs::TFMessage> m_rosPublisherPort_tf_timed;
126  yarp::os::Publisher<yarp::rosmsg::tf2_msgs::TFMessage> m_rosPublisherPort_tf_static;
127  yarp::os::Subscriber<yarp::rosmsg::tf2_msgs::TFMessage> m_rosSubscriberPort_tf_timed;
128  yarp::os::Subscriber<yarp::rosmsg::tf2_msgs::TFMessage> m_rosSubscriberPort_tf_static;
129 
130  bool read(yarp::os::ConnectionReader& connection) override;
131  inline void list_response(yarp::os::Bottle& out);
132  bool generate_view();
133  std::string get_matrix_as_text(Transforms_server_storage* storage, int i);
134  bool parseStartingTf(yarp::os::Searchable &config);
135 };
136 
137 #endif // YARP_DEV_FRAMETRANSFORMSERVER_FRAMETRANSFORMSERVER_H
FrameTransformServer
transformServer: Documentation to be added
Definition: FrameTransformServer.h:86
FrameTransformServer::run
void run() override
Loop function.
Definition: FrameTransformServer.cpp:792
yarp::os::Bottle
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
yarp::math::FrameTransform
Definition: FrameTransform.h:21
Network.h
FrameTransformServer::~FrameTransformServer
~FrameTransformServer()
Definition: FrameTransformServer.cpp:162
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
Vector.h
contains the definition of a Vector type
Transforms_server_storage::delete_transform
bool delete_transform(int id)
Transforms storage.
Definition: FrameTransformServer.cpp:50
t
float t
Definition: FfmpegWriter.cpp:74
Subscriber.h
FrameTransformServer::open
bool open(yarp::os::Searchable &params) override
Open the DeviceDriver.
Definition: FrameTransformServer.cpp:689
Port.h
yarp::dev::DeviceDriver
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
TFMessage.h
yarp::os::Publisher< yarp::rosmsg::tf2_msgs::TFMessage >
yarp::os::BufferedPort< yarp::os::Bottle >
TransformStamped.h
FrameTransformServer::FrameTransformServer
FrameTransformServer()
FrameTransformServer.
Definition: FrameTransformServer.cpp:149
yarp::os::PortReader
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:28
Transforms_server_storage::Transforms_server_storage
Transforms_server_storage()
Definition: FrameTransformServer.h:67
Property.h
RpcServer.h
PolyDriver.h
Stamp.h
Transforms_server_storage::~Transforms_server_storage
~Transforms_server_storage()
Definition: FrameTransformServer.h:68
yarp::os::RpcServer
A port that is specialized as an RPC server.
Definition: RpcServer.h:27
Node.h
Transforms_server_storage
Definition: FrameTransformServer.h:61
Transforms_server_storage::size
size_t size()
Definition: FrameTransformServer.h:72
yarp::os::Node
The Node class.
Definition: Node.h:27
BufferedPort.h
Transforms_server_storage::operator[]
yarp::math::FrameTransform & operator[](std::size_t idx)
Definition: FrameTransformServer.h:73
yarp::os::PeriodicThread
An abstraction for a periodic thread.
Definition: PeriodicThread.h:25
FrameTransformServer::close
bool close() override
Close the DeviceDriver.
Definition: FrameTransformServer.cpp:1029
Transforms_server_storage::set_transform
bool set_transform(const yarp::math::FrameTransform &t)
Definition: FrameTransformServer.cpp:61
PeriodicThread.h
yarp::os::ConnectionReader
An interface for reading from a network connection.
Definition: ConnectionReader.h:40
FrameTransformServer::threadRelease
void threadRelease() override
Release method.
Definition: FrameTransformServer.cpp:758
yarp::os::Stamp
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:25
Publisher.h
FrameTransformServer::getOptions
yarp::os::Bottle getOptions()
FrameTransform.h
yarp::os::Subscriber< yarp::rosmsg::tf2_msgs::TFMessage >
Time.h
FrameTransformServer::threadInit
bool threadInit() override
Initialization method.
Definition: FrameTransformServer.cpp:529
api.h
Transforms_server_storage::clear
void clear()
Definition: FrameTransformServer.cpp:139
Bottle.h
IFrameTransform.h
DeviceDriver.h