ros2_control - iron
Loading...
Searching...
No Matches
gz_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 GZ_ROS2_CONTROL__GZ_SYSTEM_INTERFACE_HPP_
17#define GZ_ROS2_CONTROL__GZ_SYSTEM_INTERFACE_HPP_
18
19#include <map>
20#include <memory>
21#include <string>
22#include <vector>
23
24#ifdef GZ_HEADERS
25#include <gz/sim/System.hh>
26namespace sim = gz::sim;
27#else
28#include <ignition/gazebo/System.hh>
29namespace sim = ignition::gazebo;
30#endif
31
32#include <hardware_interface/system_interface.hpp>
33#include <hardware_interface/types/hardware_interface_type_values.hpp>
34
35#include <rclcpp/rclcpp.hpp>
36
37namespace gz_ros2_control
38{
39
56
57template<class ENUM, class UNDERLYING = typename std::underlying_type<ENUM>::type>
59{
60public:
61 SafeEnum()
62 : mFlags(0) {}
63 explicit SafeEnum(ENUM singleFlag)
64 : mFlags(singleFlag) {}
65 SafeEnum(const SafeEnum & original)
66 : mFlags(original.mFlags) {}
67
68 SafeEnum & operator|=(ENUM addValue) {mFlags |= addValue; return *this;}
69 SafeEnum operator|(ENUM addValue) {SafeEnum result(*this); result |= addValue; return result;}
70 SafeEnum & operator&=(ENUM maskValue) {mFlags &= maskValue; return *this;}
71 SafeEnum operator&(ENUM maskValue) {SafeEnum result(*this); result &= maskValue; return result;}
72 SafeEnum operator~() {SafeEnum result(*this); result.mFlags = ~result.mFlags; return result;}
73 explicit operator bool() {return mFlags != 0;}
74
75protected:
76 UNDERLYING mFlags;
77};
78
79// SystemInterface provides API-level access to read and command joint properties.
82{
83public:
91 virtual bool initSim(
92 rclcpp::Node::SharedPtr & model_nh,
93 std::map<std::string, sim::Entity> & joints,
94 const hardware_interface::HardwareInfo & hardware_info,
95 sim::EntityComponentManager & _ecm,
96 int & update_rate) = 0;
97
98 // Methods used to control a joint.
99 enum ControlMethod_
100 {
101 NONE = 0,
102 POSITION = (1 << 0),
103 VELOCITY = (1 << 1),
104 EFFORT = (1 << 2),
105 };
106
107 typedef SafeEnum<enum ControlMethod_> ControlMethod;
108
109protected:
110 rclcpp::Node::SharedPtr nh_;
111};
112
113} // namespace gz_ros2_control
114
115#endif // GZ_ROS2_CONTROL__GZ_SYSTEM_INTERFACE_HPP_
Definition gz_system_interface.hpp:82
virtual bool initSim(rclcpp::Node::SharedPtr &model_nh, std::map< std::string, sim::Entity > &joints, const hardware_interface::HardwareInfo &hardware_info, sim::EntityComponentManager &_ecm, int &update_rate)=0
Initialize the system interface param[in] model_nh Pointer to the ros2 node param[in] joints Map with...
This class allows us to handle flags easily, instead of using strings.
Definition gz_system_interface.hpp:59
Definition system_interface.hpp:73
This structure stores information about hardware defined in a robot's URDF.
Definition hardware_info.hpp:107