ros2_control - humble
gazebo_system.hpp
1 // Copyright 2021 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 
16 #ifndef GAZEBO_ROS2_CONTROL__GAZEBO_SYSTEM_HPP_
17 #define GAZEBO_ROS2_CONTROL__GAZEBO_SYSTEM_HPP_
18 
19 #define VELOCITY_PID_PARAMS_PREFIX "vel_"
20 #define POSITION_PID_PARAMS_PREFIX "pos_"
21 
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 #include "angles/angles.h"
27 
28 #include "control_toolbox/pid.hpp"
29 #include "gazebo_ros2_control/gazebo_system_interface.hpp"
30 
31 #include "std_msgs/msg/bool.hpp"
32 
33 namespace gazebo_ros2_control
34 {
35 using CallbackReturn = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;
36 
37 // Forward declaration
38 class GazeboSystemPrivate;
39 
40 // These class must inherit `gazebo_ros2_control::GazeboSystemInterface` which implements a
41 // simulated `ros2_control` `hardware_interface::SystemInterface`.
42 
44 {
45 public:
46  // Documentation Inherited
47  CallbackReturn on_init(const hardware_interface::HardwareInfo & system_info)
48  override;
49 
50  // Documentation Inherited
51  std::vector<hardware_interface::StateInterface> export_state_interfaces() override;
52 
53  // Documentation Inherited
54  std::vector<hardware_interface::CommandInterface> export_command_interfaces() override;
55 
56  // Documentation Inherited
57  CallbackReturn on_activate(const rclcpp_lifecycle::State & previous_state) override;
58 
59  // Documentation Inherited
60  CallbackReturn on_deactivate(const rclcpp_lifecycle::State & previous_state) override;
61 
62  // Documentation Inherited
63  hardware_interface::return_type perform_command_mode_switch(
64  const std::vector<std::string> & start_interfaces,
65  const std::vector<std::string> & stop_interfaces) override;
66 
67  // Documentation Inherited
68  hardware_interface::return_type read(
69  const rclcpp::Time & time,
70  const rclcpp::Duration & period) override;
71 
72  // Documentation Inherited
73  hardware_interface::return_type write(
74  const rclcpp::Time & time,
75  const rclcpp::Duration & period) override;
76 
77  // Documentation Inherited
78  bool initSim(
79  rclcpp::Node::SharedPtr & model_nh,
80  gazebo::physics::ModelPtr parent_model,
81  const hardware_interface::HardwareInfo & hardware_info,
82  sdf::ElementPtr sdf) override;
83 
84 private:
85  void registerJoints(
86  const hardware_interface::HardwareInfo & hardware_info,
87  gazebo::physics::ModelPtr parent_model);
88 
89  void registerSensors(
90  const hardware_interface::HardwareInfo & hardware_info,
91  gazebo::physics::ModelPtr parent_model);
92 
93  bool extractPID(
94  const std::string & prefix,
96 
97  bool extractPIDFromParameters(
98  const std::string & control_mode, const std::string & joint_name, control_toolbox::Pid & pid);
99 
101  std::unique_ptr<GazeboSystemPrivate> dataPtr;
102 };
103 
104 } // namespace gazebo_ros2_control
105 
106 #endif // GAZEBO_ROS2_CONTROL__GAZEBO_SYSTEM_HPP_
A basic pid class.
Definition: pid.hpp:106
Definition: gazebo_system_interface.hpp:62
Definition: gazebo_system.hpp:44
std::vector< hardware_interface::CommandInterface > export_command_interfaces() override
Exports all command interfaces for this hardware interface.
Definition: gazebo_system.cpp:706
CallbackReturn on_init(const hardware_interface::HardwareInfo &system_info) override
Initialization of the hardware interface from data parsed from the robot's URDF.
Definition: gazebo_system.cpp:691
hardware_interface::return_type read(const rclcpp::Time &time, const rclcpp::Duration &period) override
Read the current state values from the actuator.
Definition: gazebo_system.cpp:777
std::vector< hardware_interface::StateInterface > export_state_interfaces() override
Exports all state interfaces for this hardware interface.
Definition: gazebo_system.cpp:700
hardware_interface::return_type perform_command_mode_switch(const std::vector< std::string > &start_interfaces, const std::vector< std::string > &stop_interfaces) override
Definition: gazebo_system.cpp:722
bool initSim(rclcpp::Node::SharedPtr &model_nh, gazebo::physics::ModelPtr parent_model, const hardware_interface::HardwareInfo &hardware_info, sdf::ElementPtr sdf) override
Initialize the system interface param[in] model_nh pointer to the ros2 node param[in] parent_model po...
Definition: gazebo_system.cpp:134
hardware_interface::return_type write(const rclcpp::Time &time, const rclcpp::Duration &period) override
Write the current command values to the actuator.
Definition: gazebo_system.cpp:818
Definition: hardware_info.hpp:52
This structure stores information about hardware defined in a robot's URDF.
Definition: hardware_info.hpp:106