ethercat_driver_ros2  main
C++ ROS test
ethercat_driver.hpp
Go to the documentation of this file.
1 // Copyright 2022 ICUBE Laboratory, University of Strasbourg
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 ETHERCAT_DRIVER__ETHERCAT_DRIVER_HPP_
16 #define ETHERCAT_DRIVER__ETHERCAT_DRIVER_HPP_
17 
18 #include <unordered_map>
19 #include <memory>
20 #include <string>
21 #include <vector>
22 #include <pluginlib/class_loader.hpp>
23 #include "hardware_interface/handle.hpp"
24 #include "hardware_interface/hardware_info.hpp"
25 #include "hardware_interface/system_interface.hpp"
26 #include "hardware_interface/types/hardware_interface_return_values.hpp"
27 #include "rclcpp/macros.hpp"
28 #include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp"
29 #include "rclcpp_lifecycle/state.hpp"
33 
35 
36 namespace ethercat_driver
37 {
38 
39 class EthercatDriver : public hardware_interface::SystemInterface
40 {
41 public:
42  RCLCPP_SHARED_PTR_DEFINITIONS(EthercatDriver)
43 
45  CallbackReturn on_init(const hardware_interface::HardwareInfo & info) override;
46 
48  CallbackReturn on_configure(const rclcpp_lifecycle::State & previous_state) override;
49 
51  std::vector<hardware_interface::StateInterface> export_state_interfaces() override;
52 
54  std::vector<hardware_interface::CommandInterface> export_command_interfaces() override;
55 
57  CallbackReturn on_activate(const rclcpp_lifecycle::State & previous_state) override;
58 
60  CallbackReturn on_deactivate(const rclcpp_lifecycle::State & previous_state) override;
61 
63  hardware_interface::return_type read(const rclcpp::Time &, const rclcpp::Duration &) override;
64 
66  hardware_interface::return_type write(const rclcpp::Time &, const rclcpp::Duration &) override;
67 
68 private:
69  std::vector<std::unordered_map<std::string, std::string>> getEcModuleParam(
70  std::string & urdf, std::string component_name, std::string component_type);
71 
72  std::vector<std::shared_ptr<ethercat_interface::EcSlave>> ec_modules_;
73  std::vector<std::unordered_map<std::string, std::string>> ec_module_parameters_;
74 
75  std::vector<std::vector<double>> hw_joint_commands_;
76  std::vector<std::vector<double>> hw_sensor_commands_;
77  std::vector<std::vector<double>> hw_gpio_commands_;
78  std::vector<std::vector<double>> hw_joint_states_;
79  std::vector<std::vector<double>> hw_sensor_states_;
80  std::vector<std::vector<double>> hw_gpio_states_;
81 
82  pluginlib::ClassLoader<ethercat_interface::EcSlave> ec_loader_{
83  "ethercat_interface", "ethercat_interface::EcSlave"};
84 
85  int control_frequency_;
87  std::mutex ec_mutex_;
88  bool activated_;
89 };
90 } // namespace ethercat_driver
91 
92 #endif // ETHERCAT_DRIVER__ETHERCAT_DRIVER_HPP_
Definition: ethercat_driver.hpp:40
ETHERCAT_DRIVER_PUBLIC CallbackReturn on_configure(const rclcpp_lifecycle::State &previous_state) override
ETHERCAT_DRIVER_PUBLIC hardware_interface::return_type read(const rclcpp::Time &, const rclcpp::Duration &) override
ETHERCAT_DRIVER_PUBLIC CallbackReturn on_init(const hardware_interface::HardwareInfo &info) override
ETHERCAT_DRIVER_PUBLIC std::vector< hardware_interface::CommandInterface > export_command_interfaces() override
ETHERCAT_DRIVER_PUBLIC hardware_interface::return_type write(const rclcpp::Time &, const rclcpp::Duration &) override
ETHERCAT_DRIVER_PUBLIC CallbackReturn on_deactivate(const rclcpp_lifecycle::State &previous_state) override
ETHERCAT_DRIVER_PUBLIC std::vector< hardware_interface::StateInterface > export_state_interfaces() override
ETHERCAT_DRIVER_PUBLIC CallbackReturn on_activate(const rclcpp_lifecycle::State &previous_state) override
Definition: ec_master.hpp:32
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn CallbackReturn
Definition: ethercat_driver.hpp:34
Definition: ethercat_driver.hpp:37
#define ETHERCAT_DRIVER_PUBLIC
Definition: visibility_control.h:43