dynamic_graph_manager
ros_robot_state_publisher_mt.hpp
Go to the documentation of this file.
1 
10 #ifndef ROS_ROBOT_STATE_PUBLISHER_HPP
11 #define ROS_ROBOT_STATE_PUBLISHER_HPP
12 
13 #include <deque>
14 #include <memory>
15 #include <mutex>
16 #include <thread>
17 
18 #include <dynamic-graph/all-commands.h>
19 #include <dynamic-graph/all-signals.h>
20 #include <dynamic-graph/entity.h>
21 #include <dynamic-graph/factory.h>
22 #include <dynamic-graph/linear-algebra.h>
23 
24 #include <realtime_tools/realtime_publisher.h>
25 #include <ros/ros.h>
26 #include <sensor_msgs/JointState.h>
27 #include <tf2_msgs/TFMessage.h>
28 #include <real_time_tools/spinner.hpp>
29 #include <real_time_tools/thread.hpp>
30 
34 namespace dynamic_graph
35 {
39 typedef dynamicgraph::SignalTimeDependent<int, int> SignalOUT;
43 typedef dynamicgraph::SignalPtr<dynamicgraph::Vector, int> SignalIN;
47 typedef boost::function<void(int)> callback_t;
48 
52 typedef realtime_tools::RealtimePublisher<tf2_msgs::TFMessage> TfRtPublisher;
53 
57 typedef realtime_tools::RealtimePublisher<sensor_msgs::JointState>
59 
61 {
62  std::shared_ptr<TfRtPublisher> base_tf_publisher_;
63  std::shared_ptr<JointStateRtPublisher> joint_state_publisher_;
64  std::shared_ptr<SignalIN> robot_state_input_signal_;
65  callback_t callback_function_;
66  std::thread thread_;
67  real_time_tools::Spinner spinner_;
68  bool stop_publish_;
69  std::mutex mutex_;
70  dynamicgraph::Vector robot_state_;
71 
73  {
74  stop_publish_ = true;
75  thread_.join();
76  }
77 };
78 
82 class RosRobotStatePublisherMt : public dynamicgraph::Entity
83 {
84 public:
85  RosRobotStatePublisherMt(const std::string& name);
86 
88  {
89  }
90 
99  void add(const std::string& base_link_name,
100  const std::string& joint_names,
101  const std::string& tf_prefix,
102  const std::string& signal_name,
103  const std::string& joint_state_topic_name);
104 
110  int& trigger(int&, int);
111 
118  void copy_data_internally(
119  std::shared_ptr<RosRobotStatePublisherMtInternal> publisher,
120  int dg_time);
121 
125  void send_data(RosRobotStatePublisherMtInternal& publisher);
126 
127 private:
131  static const std::string CLASS_NAME;
132 
138  virtual const std::string& getClassName(void) const
139  {
140  return CLASS_NAME;
141  }
142 
148  void set_tf_msg_to_identity(geometry_msgs::TransformStamped& msg);
149 
155  void normalize_tf_msg_quaternion(geometry_msgs::TransformStamped& msg);
156 
162  SignalOUT trigger_signal_;
163 
168  ros::NodeHandle& ros_node_handle_;
169 
175  std::map<std::string, std::shared_ptr<RosRobotStatePublisherMtInternal>>
177 
181  ros::Duration rate_;
182 
187 };
188 } // namespace dynamic_graph
189 
190 namespace dynamicgraph
191 {
195 namespace command
196 {
200 namespace ros_state_publish
201 {
202 using ::dynamicgraph::command::Command;
203 using ::dynamicgraph::command::Value;
204 
209 // Define here a macro that automatically generates a command
210 #define ROS_PUBLISH_MAKE_COMMAND(CMD) \
211  class CMD : public Command \
212  { \
213  public: \
214  CMD(dynamic_graph::RosRobotStatePublisherMt& entity, \
215  const std::string& docstring); \
216  virtual Value doExecute(); \
217  }
218 
219 // Generate a couple of command classes
221 // Later in the code no one must have access to this macro.
222 #undef ROS_PUBLISH_MAKE_COMMAND
223 } // end of namespace ros_state_publish
224 } // end of namespace command
225 } // end of namespace dynamicgraph
226 
227 #endif // ROS_ROBOT_STATE_PUBLISHER_HPP
ros::Time last_time_of_publication_
Check at what time the publication was done.
Definition: ros_robot_state_publisher_mt.hpp:186
boost::function< void(int)> callback_t
Simple shortcut for code writing convenience.
Definition: ros_robot_state_publisher.hpp:43
This class define a dynamic graph wrapper around the vicon client.
Definition: ros_robot_state_publisher_mt.hpp:82
std::map< std::string, std::shared_ptr< RosRobotStatePublisherMtInternal > > publishers_
This is the list of publishers registered for this class.
Definition: ros_robot_state_publisher_mt.hpp:176
dynamicgraph::SignalPtr< dynamicgraph::Vector, int > SignalIN
Simple shortcut for code writing convenience.
Definition: ros_robot_state_publisher.hpp:39
realtime_tools::RealtimePublisher< sensor_msgs::JointState > JointStateRtPublisher
Renaming of the joint position publisher type.
Definition: ros_robot_state_publisher.hpp:54
#define ROS_PUBLISH_MAKE_COMMAND(CMD)
Declare here a couple of python command used for the ros_state publisher.
Definition: ros_robot_state_publisher_mt.hpp:210
realtime_tools::RealtimePublisher< tf2_msgs::TFMessage > TfRtPublisher
Renaming of the tf publisher type.
Definition: ros_robot_state_publisher.hpp:48
this is this package namespace in order to avoid naming conflict
Definition: device.hh:22
static const std::string CLASS_NAME
The class name used to identify it in the dynamic graph pool.
Definition: ros_robot_state_publisher_mt.hpp:131
ros::Duration rate_
manage the rate data publication in topics
Definition: ros_robot_state_publisher_mt.hpp:181
ros::NodeHandle & ros_node_handle_
Ros node handle corresponding to the dynamic graph process node handle.
Definition: ros_robot_state_publisher_mt.hpp:168
Definition: ros_robot_state_publisher_mt.hpp:60
SignalOUT trigger_signal_
Create an internal output signal which should be call periodically in the device in order to publish ...
Definition: ros_robot_state_publisher_mt.hpp:162
virtual const std::string & getClassName(void) const
Get the CLASS_NAME object.
Definition: ros_robot_state_publisher_mt.hpp:138
Definition of the command.
Definition: ros_robot_state_publisher.hpp:164
dynamicgraph::SignalTimeDependent< int, int > SignalOUT
Simple shortcut for code writing convenience.
Definition: ros_robot_state_publisher.hpp:35