ros2_control - galactic
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 
46  SafeEnum & operator|=(ENUM addValue) {mFlags |= addValue; return *this;}
47  SafeEnum operator|(ENUM addValue) {SafeEnum result(*this); result |= addValue; return result;}
48  SafeEnum & operator&=(ENUM maskValue) {mFlags &= maskValue; return *this;}
49  SafeEnum operator&(ENUM maskValue) {SafeEnum result(*this); result &= maskValue; return result;}
50  SafeEnum operator~() {SafeEnum result(*this); result.mFlags = ~result.mFlags; return result;}
51  explicit operator bool() {return mFlags != 0;}
52 
53 protected:
54  UNDERLYING mFlags;
55 };
56 
57 // SystemInterface provides API-level access to read and command joint properties.
60 {
61 public:
67  virtual bool initSim(
68  rclcpp::Node::SharedPtr & model_nh,
69  gazebo::physics::ModelPtr parent_model,
70  const hardware_interface::HardwareInfo & hardware_info,
71  sdf::ElementPtr sdf) = 0;
72 
73  // Methods used to control a joint.
74  enum ControlMethod_
75  {
76  NONE = 0,
77  POSITION = (1 << 0),
78  VELOCITY = (1 << 1),
79  EFFORT = (1 << 2),
80  };
81 
82  typedef SafeEnum<enum ControlMethod_> ControlMethod;
83 
84 protected:
85  rclcpp::Node::SharedPtr nh_;
86 };
87 
88 } // namespace gazebo_ros2_control
89 
90 #endif // GAZEBO_ROS2_CONTROL__GAZEBO_SYSTEM_INTERFACE_HPP_
Definition: gazebo_system_interface.hpp:60
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
Virtual Class to implement when integrating a complex system into ros2_control.
Definition: system_interface.hpp:68
This structure stores information about hardware defined in a robot's URDF.
Definition: hardware_info.hpp:101