|
| 1 | +// Copyright 1996-2021 Cyberbotics Ltd. |
| 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 | +#ifndef ROS2_CONTROL_HPP |
| 16 | +#define ROS2_CONTROL_HPP |
| 17 | + |
| 18 | +#include <memory> |
| 19 | +#include <string> |
| 20 | +#include <vector> |
| 21 | + |
| 22 | +#include "hardware_interface/base_interface.hpp" |
| 23 | +#include "hardware_interface/system_interface.hpp" |
| 24 | +#include "hardware_interface/handle.hpp" |
| 25 | +#include "hardware_interface/hardware_info.hpp" |
| 26 | +#include "hardware_interface/types/hardware_interface_return_values.hpp" |
| 27 | +#include "hardware_interface/types/hardware_interface_status_values.hpp" |
| 28 | +#include "rclcpp/macros.hpp" |
| 29 | +#include "webots_ros2_driver/PluginInterface.hpp" |
| 30 | +#include "webots_ros2_driver/WebotsNode.hpp" |
| 31 | + |
| 32 | +#include "webots_ros2_control/Ros2ControlSystemInterface.hpp" |
| 33 | +#include "webots/Motor.hpp" |
| 34 | +#include "webots/PositionSensor.hpp" |
| 35 | + |
| 36 | +namespace webots_ros2_control |
| 37 | +{ |
| 38 | + struct Joint { |
| 39 | + double positionCommand; |
| 40 | + double position; |
| 41 | + double velocityCommand; |
| 42 | + double velocity; |
| 43 | + double effortCommand; |
| 44 | + double effort; |
| 45 | + bool controlPosition; |
| 46 | + bool controlVelocity; |
| 47 | + bool controlEffort; |
| 48 | + std::string name; |
| 49 | + webots::Motor* motor; |
| 50 | + webots::PositionSensor* sensor; |
| 51 | + }; |
| 52 | + |
| 53 | + class Ros2ControlSystem : public Ros2ControlSystemInterface |
| 54 | + { |
| 55 | + public: |
| 56 | + void init(webots_ros2_driver::WebotsNode *node, const hardware_interface::HardwareInfo &info) override; |
| 57 | + |
| 58 | + hardware_interface::return_type configure(const hardware_interface::HardwareInfo &info) override; |
| 59 | + std::vector<hardware_interface::StateInterface> export_state_interfaces() override; |
| 60 | + std::vector<hardware_interface::CommandInterface> export_command_interfaces() override; |
| 61 | + hardware_interface::return_type start() override; |
| 62 | + hardware_interface::return_type stop() override; |
| 63 | + hardware_interface::return_type read() override; |
| 64 | + hardware_interface::return_type write() override; |
| 65 | + |
| 66 | + private: |
| 67 | + webots_ros2_driver::WebotsNode *mNode; |
| 68 | + std::vector<Joint> mJoints; |
| 69 | + }; |
| 70 | +} |
| 71 | + |
| 72 | +#endif |
0 commit comments