ros2_control - humble
ign_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 IGN_ROS2_CONTROL__IGN_SYSTEM_HPP_
17 #define IGN_ROS2_CONTROL__IGN_SYSTEM_HPP_
18 
19 #include <map>
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 #include "ign_ros2_control/ign_system_interface.hpp"
25 #include "rclcpp_lifecycle/state.hpp"
26 #include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp"
27 
28 namespace ign_ros2_control
29 {
30 using CallbackReturn = rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn;
31 
32 // Forward declaration
33 class IgnitionSystemPrivate;
34 
35 // These class must inherit `ign_ros2_control::IgnitionSystemInterface` which implements a
36 // simulated `ros2_control` `hardware_interface::SystemInterface`.
37 
39 {
40 public:
41  // Documentation Inherited
42  CallbackReturn on_init(const hardware_interface::HardwareInfo & system_info)
43  override;
44 
45  CallbackReturn on_configure(const rclcpp_lifecycle::State & previous_state) override;
46 
47  // Documentation Inherited
48  std::vector<hardware_interface::StateInterface> export_state_interfaces() override;
49 
50  // Documentation Inherited
51  std::vector<hardware_interface::CommandInterface> export_command_interfaces() override;
52 
53  // Documentation Inherited
54  CallbackReturn on_activate(const rclcpp_lifecycle::State & previous_state) override;
55 
56  // Documentation Inherited
57  CallbackReturn on_deactivate(const rclcpp_lifecycle::State & previous_state) 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 read(
66  const rclcpp::Time & time,
67  const rclcpp::Duration & period) override;
68 
69  // Documentation Inherited
70  hardware_interface::return_type write(
71  const rclcpp::Time & time,
72  const rclcpp::Duration & period) override;
73 
74  // Documentation Inherited
75  bool initSim(
76  rclcpp::Node::SharedPtr & model_nh,
77  std::map<std::string, ignition::gazebo::Entity> & joints,
78  const hardware_interface::HardwareInfo & hardware_info,
79  ignition::gazebo::EntityComponentManager & _ecm,
80  int & update_rate) override;
81 
82 private:
83  // Register a sensor (for now just IMUs)
84  // \param[in] hardware_info hardware information where the data of
85  // the sensors is extract.
86  void registerSensors(
87  const hardware_interface::HardwareInfo & hardware_info);
88 
90  std::unique_ptr<IgnitionSystemPrivate> dataPtr;
91 };
92 
93 } // namespace ign_ros2_control
94 
95 #endif // IGN_ROS2_CONTROL__IGN_SYSTEM_HPP_
Definition: ign_system_interface.hpp:76
Definition: ign_system.hpp:39
hardware_interface::return_type read(const rclcpp::Time &time, const rclcpp::Duration &period) override
Read the current state values from the actuator.
Definition: ign_system.cpp:527
CallbackReturn on_init(const hardware_interface::HardwareInfo &system_info) override
Initialization of the hardware interface from data parsed from the robot's URDF.
Definition: ign_system.cpp:485
std::vector< hardware_interface::StateInterface > export_state_interfaces() override
Exports all state interfaces for this hardware interface.
Definition: ign_system.cpp:504
hardware_interface::return_type write(const rclcpp::Time &time, const rclcpp::Duration &period) override
Write the current command values to the actuator.
Definition: ign_system.cpp:623
std::vector< hardware_interface::CommandInterface > export_command_interfaces() override
Exports all command interfaces for this hardware interface.
Definition: ign_system.cpp:510
hardware_interface::return_type perform_command_mode_switch(const std::vector< std::string > &start_interfaces, const std::vector< std::string > &stop_interfaces) override
Definition: ign_system.cpp:577
bool initSim(rclcpp::Node::SharedPtr &model_nh, std::map< std::string, ignition::gazebo::Entity > &joints, const hardware_interface::HardwareInfo &hardware_info, ignition::gazebo::EntityComponentManager &_ecm, int &update_rate) override
Initialize the system interface param[in] model_nh Pointer to the ros2 node param[in] joints Map with...
Definition: ign_system.cpp:163
This structure stores information about hardware defined in a robot's URDF.
Definition: hardware_info.hpp:106