ros2_control - galactic
Loading...
Searching...
No Matches
ign_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 IGN_ROS2_CONTROL__IGN_SYSTEM_INTERFACE_HPP_
17#define IGN_ROS2_CONTROL__IGN_SYSTEM_INTERFACE_HPP_
18
19#include <ignition/gazebo/System.hh>
20
21#include <hardware_interface/system_interface.hpp>
22#include <hardware_interface/types/hardware_interface_type_values.hpp>
23
24#include <rclcpp/rclcpp.hpp>
25
26#include <map>
27#include <memory>
28#include <string>
29#include <vector>
30
31namespace ign_ros2_control
32{
33
50
51template<class ENUM, class UNDERLYING = typename std::underlying_type<ENUM>::type>
53{
54public:
55 SafeEnum()
56 : mFlags(0) {}
57 explicit SafeEnum(ENUM singleFlag)
58 : mFlags(singleFlag) {}
59 SafeEnum(const SafeEnum & original)
60 : mFlags(original.mFlags) {}
61
62 SafeEnum & operator|=(ENUM addValue) {mFlags |= addValue; return *this;}
63 SafeEnum operator|(ENUM addValue) {SafeEnum result(*this); result |= addValue; return result;}
64 SafeEnum & operator&=(ENUM maskValue) {mFlags &= maskValue; return *this;}
65 SafeEnum operator&(ENUM maskValue) {SafeEnum result(*this); result &= maskValue; return result;}
66 SafeEnum operator~() {SafeEnum result(*this); result.mFlags = ~result.mFlags; return result;}
67 explicit operator bool() {return mFlags != 0;}
68
69protected:
70 UNDERLYING mFlags;
71};
72
73// SystemInterface provides API-level access to read and command joint properties.
76{
77public:
85 virtual bool initSim(
86 rclcpp::Node::SharedPtr & model_nh,
87 std::map<std::string, ignition::gazebo::Entity> & joints,
88 const hardware_interface::HardwareInfo & hardware_info,
89 ignition::gazebo::EntityComponentManager & _ecm,
90 int & update_rate) = 0;
91
92 // Methods used to control a joint.
93 enum ControlMethod_
94 {
95 NONE = 0,
96 POSITION = (1 << 0),
97 VELOCITY = (1 << 1),
98 EFFORT = (1 << 2),
99 };
100
101 typedef SafeEnum<enum ControlMethod_> ControlMethod;
102
103protected:
104 rclcpp::Node::SharedPtr nh_;
105};
106
107} // namespace ign_ros2_control
108
109#endif // IGN_ROS2_CONTROL__IGN_SYSTEM_INTERFACE_HPP_
Virtual Class to implement when integrating a complex system into ros2_control.
Definition system_interface.hpp:68
Definition ign_system_interface.hpp:76
virtual 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)=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 ign_system_interface.hpp:53
This structure stores information about hardware defined in a robot's URDF.
Definition hardware_info.hpp:101