ros2_control - galactic
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 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 #include "angles/angles.h"
24 
25 #include "gazebo_ros2_control/gazebo_system_interface.hpp"
26 
27 #include "std_msgs/msg/bool.hpp"
28 
29 namespace gazebo_ros2_control
30 {
31 // Forward declaration
32 class GazeboSystemPrivate;
33 
34 // These class must inherit `gazebo_ros2_control::GazeboSystemInterface` which implements a
35 // simulated `ros2_control` `hardware_interface::SystemInterface`.
36 
38 {
39 public:
40  // Documentation Inherited
41  CallbackReturn on_init(const hardware_interface::HardwareInfo & system_info)
42  override;
43 
44  // Documentation Inherited
45  std::vector<hardware_interface::StateInterface> export_state_interfaces() override;
46 
47  // Documentation Inherited
48  std::vector<hardware_interface::CommandInterface> export_command_interfaces() override;
49 
50  // Documentation Inherited
51  CallbackReturn on_activate(const rclcpp_lifecycle::State & previous_state) override;
52 
53  // Documentation Inherited
54  CallbackReturn on_deactivate(const rclcpp_lifecycle::State & previous_state) override;
55 
56  // Documentation Inherited
57  hardware_interface::return_type read() override;
58 
59  // Documentation Inherited
60  hardware_interface::return_type perform_command_mode_switch(
61  const std::vector<std::string> & start_interfaces,
62  const std::vector<std::string> & stop_interfaces) override;
63 
64  // Documentation Inherited
65  hardware_interface::return_type write() override;
66 
67  // Documentation Inherited
68  bool initSim(
69  rclcpp::Node::SharedPtr & model_nh,
70  gazebo::physics::ModelPtr parent_model,
71  const hardware_interface::HardwareInfo & hardware_info,
72  sdf::ElementPtr sdf) override;
73 
74 private:
75  void registerJoints(
76  const hardware_interface::HardwareInfo & hardware_info,
77  gazebo::physics::ModelPtr parent_model);
78 
79  void registerSensors(
80  const hardware_interface::HardwareInfo & hardware_info,
81  gazebo::physics::ModelPtr parent_model);
82 
84  std::unique_ptr<GazeboSystemPrivate> dataPtr;
85 };
86 
87 } // namespace gazebo_ros2_control
88 
89 #endif // GAZEBO_ROS2_CONTROL__GAZEBO_SYSTEM_HPP_
Definition: gazebo_system_interface.hpp:60
Definition: gazebo_system.hpp:38
hardware_interface::return_type read() override
Read the current state values from the actuator.
Definition: gazebo_system.cpp:494
hardware_interface::return_type write() override
Write the current command values to the actuator.
Definition: gazebo_system.cpp:536
std::vector< hardware_interface::CommandInterface > export_command_interfaces() override
Exports all command interfaces for this hardware interface.
Definition: gazebo_system.cpp:430
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:415
std::vector< hardware_interface::StateInterface > export_state_interfaces() override
Exports all state interfaces for this hardware interface.
Definition: gazebo_system.cpp:424
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:446
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:109
This structure stores information about hardware defined in a robot's URDF.
Definition: hardware_info.hpp:101