ros2_control - rolling
gpio_controller.hpp
1 // Copyright 2023 ros2_control Development Team
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_DEMO_EXAMPLE_10__GPIO_CONTROLLER_HPP_
16 #define ROS2_CONTROL_DEMO_EXAMPLE_10__GPIO_CONTROLLER_HPP_
17 
18 #include <memory>
19 #include <string>
20 #include <vector>
21 
22 #include "control_msgs/msg/interface_value.hpp"
23 #include "std_msgs/msg/float64_multi_array.hpp"
24 
25 #include "controller_interface/controller_interface.hpp"
26 
27 namespace ros2_control_demo_example_10
28 {
29 using CmdType = std_msgs::msg::Float64MultiArray;
30 
32 {
33 public:
34  RCLCPP_SHARED_PTR_DEFINITIONS(GPIOController);
35 
37 
39 
40  controller_interface::return_type update(
41  const rclcpp::Time & time, const rclcpp::Duration & period) override;
42 
43  CallbackReturn on_configure(const rclcpp_lifecycle::State & previous_state) override;
44 
45  CallbackReturn on_activate(const rclcpp_lifecycle::State & previous_state) override;
46 
47  CallbackReturn on_deactivate(const rclcpp_lifecycle::State & previous_state) override;
48 
49  CallbackReturn on_init() override;
50 
51 private:
52  std::vector<std::string> inputs_;
53  std::vector<std::string> outputs_;
54 
55 protected:
56  void initMsgs();
57 
58  // internal commands
59  std::shared_ptr<CmdType> output_cmd_ptr_;
60 
61  // publisher
62  std::shared_ptr<rclcpp::Publisher<control_msgs::msg::InterfaceValue>> gpio_publisher_;
63  control_msgs::msg::InterfaceValue gpio_msg_;
64 
65  // subscriber
66  rclcpp::Subscription<CmdType>::SharedPtr subscription_command_;
67 };
68 } // namespace ros2_control_demo_example_10
69 
70 #endif // ROS2_CONTROL_DEMO_EXAMPLE_10__GPIO_CONTROLLER_HPP_
Definition: controller_interface.hpp:28
Definition: gpio_controller.hpp:32
controller_interface::return_type update(const rclcpp::Time &time, const rclcpp::Duration &period) override
Definition: gpio_controller.cpp:54
controller_interface::InterfaceConfiguration state_interface_configuration() const override
Get configuration for controller's required state interfaces.
Definition: gpio_controller.cpp:45
CallbackReturn on_init() override
Extending interface with initialization method which is individual for each controller.
Definition: gpio_controller.cpp:21
controller_interface::InterfaceConfiguration command_interface_configuration() const override
Get configuration for controller's required command interfaces.
Definition: gpio_controller.cpp:36
Configuring what command/state interfaces to claim.
Definition: controller_interface_base.hpp:58