mc_rtc  2.12.0
ros.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2019 CNRS-UM LIRMM, CNRS-AIST JRL
3  */
4 
5 #pragma once
6 
7 #include <mc_rtc_ros/api.h>
8 
9 #include <mc_rtc/config.h>
10 
11 #include <SpaceVecAlg/SpaceVecAlg>
12 
13 #include <Eigen/Geometry>
14 #include <map>
15 #include <memory>
16 #include <string>
17 #include <vector>
18 
19 #ifdef MC_RTC_ROS_IS_ROS2
20 namespace rclcpp
21 {
22 class Node;
23 }
24 #else
25 namespace ros
26 {
27 class NodeHandle;
28 }
29 #endif
30 
31 namespace mc_rbdyn
32 {
33 struct Robot;
34 }
35 
36 namespace mc_control
37 {
38 struct MCGlobalController;
39 } // namespace mc_control
40 
41 namespace mc_rtc
42 {
43 
44 struct ROSBridgeImpl;
45 
46 #ifdef MC_RTC_ROS_IS_ROS2
47 using NodeHandlePtr = std::shared_ptr<rclcpp::Node>;
48 #else
49 using NodeHandlePtr = std::shared_ptr<ros::NodeHandle>;
50 #endif
51 
54 {
62 
68  static void set_publisher_timestep(double timestep);
69 
81  static void init_robot_publisher(const std::string & publisher,
82  double dt,
83  const mc_rbdyn::Robot & robot,
84  bool use_real = false);
85 
95  static void update_robot_publisher(const std::string & publisher, double dt, const mc_rbdyn::Robot & robot);
96 
101  static void stop_robot_publisher(const std::string & publisher);
102 
104  static void shutdown();
105 
106 private:
107  static ROSBridgeImpl & impl_();
108 };
109 
110 struct RobotPublisherImpl;
111 
119 {
120 public:
132  RobotPublisher(const std::string & prefix, double rate, double dt);
133 
136 
138  void init(const mc_rbdyn::Robot & robot, bool use_real = false);
139 
141  void update(double dt, const mc_rbdyn::Robot & robot);
142 
144  void set_rate(double rate);
145 
146 private:
147  std::unique_ptr<RobotPublisherImpl> impl;
148 };
149 
150 } // namespace mc_rtc
Definition: CompletionCriteria.h:11
Definition: generic_gripper.h:15
auto Robot(const std::string &name, GetT get_fn)
Definition: Robot.h:56
Definition: Contact.h:88
std::shared_ptr< ros::NodeHandle > NodeHandlePtr
Definition: ros.h:49
Definition: ros.h:26
#define MC_RTC_ROS_DLLAPI
Definition: api.h:50
Definition: Robot.h:63
Allows to access ROS functionalities within mc_rtc without explicit ROS dependencies.
Definition: ros.h:54
static void update_robot_publisher(const std::string &publisher, double dt, const mc_rbdyn::Robot &robot)
static NodeHandlePtr get_node_handle()
Get a ros::NodeHandle/rclcpp::Node.
static void stop_robot_publisher(const std::string &publisher)
static void init_robot_publisher(const std::string &publisher, double dt, const mc_rbdyn::Robot &robot, bool use_real=false)
static void shutdown()
Stop ROS.
static void set_publisher_timestep(double timestep)
This structure is able to publish a Robot's state to ROS.
Definition: ros.h:119
void init(const mc_rbdyn::Robot &robot, bool use_real=false)
Initialize the publisher.
void set_rate(double rate)
Reset the publishing rate.
~RobotPublisher()
Destructor.
RobotPublisher(const std::string &prefix, double rate, double dt)
void update(double dt, const mc_rbdyn::Robot &robot)
Update the publisher.