ros2_control - humble
gazebo_system_interface.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_INTERFACE_HPP_
17 #define GAZEBO_ROS2_CONTROL__GAZEBO_SYSTEM_INTERFACE_HPP_
18 
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 #include "gazebo/physics/Joint.hh"
24 #include "gazebo/physics/Model.hh"
25 #include "gazebo/physics/physics.hh"
26 
27 #include "hardware_interface/system_interface.hpp"
28 
29 #include "rclcpp/rclcpp.hpp"
30 
31 
32 namespace gazebo_ros2_control
33 {
34 
35 template<class ENUM, class UNDERLYING = typename std::underlying_type<ENUM>::type>
36 class SafeEnum
37 {
38 public:
39  SafeEnum()
40  : mFlags(0) {}
41  explicit SafeEnum(ENUM singleFlag)
42  : mFlags(singleFlag) {}
43  SafeEnum(const SafeEnum & original)
44  : mFlags(original.mFlags) {}
45  ~SafeEnum() = default;
46 
47  SafeEnum & operator=(const SafeEnum & original) = default;
48  SafeEnum & operator|=(ENUM addValue) {mFlags |= addValue; return *this;}
49  SafeEnum operator|(ENUM addValue) {SafeEnum result(*this); result |= addValue; return result;}
50  SafeEnum & operator&=(ENUM maskValue) {mFlags &= maskValue; return *this;}
51  SafeEnum operator&(ENUM maskValue) {SafeEnum result(*this); result &= maskValue; return result;}
52  SafeEnum operator~() {SafeEnum result(*this); result.mFlags = ~result.mFlags; return result;}
53  explicit operator bool() {return mFlags != 0;}
54 
55 protected:
56  UNDERLYING mFlags;
57 };
58 
59 // SystemInterface provides API-level access to read and command joint properties.
62 {
63 public:
69  virtual bool initSim(
70  rclcpp::Node::SharedPtr & model_nh,
71  gazebo::physics::ModelPtr parent_model,
72  const hardware_interface::HardwareInfo & hardware_info,
73  sdf::ElementPtr sdf) = 0;
74 
75  // Methods used to control a joint.
76  enum ControlMethod_
77  {
78  NONE = 0,
79  POSITION = (1 << 0),
80  VELOCITY = (1 << 1),
81  EFFORT = (1 << 2),
82  VELOCITY_PID = (1 << 3),
83  POSITION_PID = (1 << 4),
84  };
85 
86  typedef SafeEnum<enum ControlMethod_> ControlMethod;
87 
88 protected:
89  rclcpp::Node::SharedPtr nh_;
90 };
91 
92 } // namespace gazebo_ros2_control
93 
94 #endif // GAZEBO_ROS2_CONTROL__GAZEBO_SYSTEM_INTERFACE_HPP_
Definition: gazebo_system_interface.hpp:62
virtual bool initSim(rclcpp::Node::SharedPtr &model_nh, gazebo::physics::ModelPtr parent_model, const hardware_interface::HardwareInfo &hardware_info, sdf::ElementPtr sdf)=0
Initialize the system interface param[in] model_nh pointer to the ros2 node param[in] parent_model po...
Definition: gazebo_system_interface.hpp:37
Definition: system_interface.hpp:73
This structure stores information about hardware defined in a robot's URDF.
Definition: hardware_info.hpp:106