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 
81 {
82 public:
85 
86  bool open(yarp::os::Searchable &params) override;
87  bool close() override;
89 
90  bool threadInit() override;
91  void threadRelease() override;
92  void run() override;
93 
94 private:
95  std::mutex m_mutex;
96  std::string m_streamingPortName;
97  std::string m_rpcPortName;
98  yarp::os::Stamp m_lastStateStamp;
99  double m_period;
100  yarp::os::Node* m_rosNode;
101  bool m_enable_publish_ros_tf;
102  bool m_enable_subscribe_ros_tf;
103  Transforms_server_storage* m_ros_timed_transform_storage;
104  Transforms_server_storage* m_ros_static_transform_storage;
105  Transforms_server_storage* m_yarp_timed_transform_storage;
106  Transforms_server_storage* m_yarp_static_transform_storage;
107  double m_FrameTransformTimeout;
108 
109  yarp::os::RpcServer m_rpcPort;
111  yarp::os::Publisher<yarp::rosmsg::tf2_msgs::TFMessage> m_rosPublisherPort_tf_timed;
112  yarp::os::Publisher<yarp::rosmsg::tf2_msgs::TFMessage> m_rosPublisherPort_tf_static;
113  yarp::os::Subscriber<yarp::rosmsg::tf2_msgs::TFMessage> m_rosSubscriberPort_tf_timed;
114  yarp::os::Subscriber<yarp::rosmsg::tf2_msgs::TFMessage> m_rosSubscriberPort_tf_static;
115 
116  bool read(yarp::os::ConnectionReader& connection) override;
117  inline void list_response(yarp::os::Bottle& out);
118  bool parseStartingTf(yarp::os::Searchable &config);
119 };
120 
121 #endif // YARP_DEV_FRAMETRANSFORMSERVER_FRAMETRANSFORMSERVER_H
float t
contains the definition of a Vector type
bool close() override
Close the DeviceDriver.
void threadRelease() override
Release method.
FrameTransformServer()
FrameTransformServer.
bool open(yarp::os::Searchable &params) override
Open the DeviceDriver.
yarp::os::Bottle getOptions()
bool threadInit() override
Initialization method.
void run() override
Loop function.
bool delete_transform(int id)
Transforms storage.
bool set_transform(const yarp::math::FrameTransform &t)
yarp::math::FrameTransform & operator[](std::size_t idx)
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:73
An interface for reading from a network connection.
The Node class.
Definition: Node.h:27
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 port that is specialized as an RPC server.
Definition: RpcServer.h:27
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