Skip to content

Commit dd3c813

Browse files
committed
add hpp for gimbal_position_controller
1 parent 4e48250 commit dd3c813

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#ifndef GIMBAL_CONTROLLER__GIMBAL_POSITION_CONTROLLER_HPP_
2+
#define GIMBAL_CONTROLLER__GIMBAL_POSITION_CONTROLLER_HPP_
3+
4+
#include <control_toolbox/pid_ros.hpp>
5+
#include <memory>
6+
#include <rclcpp/subscription.hpp>
7+
#include <string>
8+
#include <vector>
9+
10+
#include "control_toolbox/pid_ros.hpp"
11+
#include "controller_interface/chainable_controller_interface.hpp"
12+
#include "meta_gimbal_position_controller_parameters.hpp"
13+
#include "rclcpp/duration.hpp"
14+
#include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp"
15+
#include "rclcpp_lifecycle/state.hpp"
16+
#include "realtime_tools/realtime_buffer.h"
17+
#include "realtime_tools/realtime_publisher.h"
18+
#include "std_srvs/srv/set_bool.hpp"
19+
20+
#include "behavior_interface/msg/aim.hpp"
21+
#include "control_msgs/msg/multi_dof_state_stamped.hpp"
22+
#include "sensor_msgs/msg/imu.hpp"
23+
24+
namespace gimbal_controller {
25+
// name constants for state interfaces
26+
static constexpr size_t STATE_MY_ITFS = 0;
27+
28+
// name constants for command interfaces
29+
static constexpr size_t CMD_MY_ITFS = 0;
30+
31+
class GimbalPositionController : public controller_interface::ChainableControllerInterface {
32+
public:
33+
GimbalPositionController() = default;
34+
35+
controller_interface::CallbackReturn on_init() override;
36+
37+
controller_interface::InterfaceConfiguration
38+
command_interface_configuration() const override;
39+
40+
controller_interface::InterfaceConfiguration
41+
state_interface_configuration() const override;
42+
43+
controller_interface::CallbackReturn
44+
on_configure(const rclcpp_lifecycle::State &previous_state) override;
45+
46+
controller_interface::CallbackReturn
47+
on_activate(const rclcpp_lifecycle::State &previous_state) override;
48+
49+
controller_interface::CallbackReturn
50+
on_deactivate(const rclcpp_lifecycle::State &previous_state) override;
51+
52+
controller_interface::return_type update_reference_from_subscribers() override;
53+
54+
controller_interface::return_type
55+
update_and_write_commands(const rclcpp::Time &time,
56+
const rclcpp::Duration &period) override;
57+
58+
using ControllerFeedbackMsg = sensor_msgs::msg::Imu;
59+
using ControllerReferenceMsg = behavior_interface::msg::Aim;
60+
using ControllerModeSrvType = std_srvs::srv::SetBool;
61+
using ControllerStateMsg = control_msgs::msg::MultiDOFStateStamped;
62+
63+
protected:
64+
std::shared_ptr<gimbal_position_controller::ParamListener> param_listener_;
65+
gimbal_position_controller::Params params_;
66+
67+
// Command subscribers
68+
rclcpp::Subscription<ControllerReferenceMsg>::SharedPtr ref_subscriber_ = nullptr;
69+
realtime_tools::RealtimeBuffer<std::shared_ptr<ControllerReferenceMsg>> input_ref_;
70+
71+
// Feedback subscribers
72+
rclcpp::Subscription<ControllerFeedbackMsg>::SharedPtr feedback_subscriber_ = nullptr;
73+
realtime_tools::RealtimeBuffer<std::shared_ptr<ControllerFeedbackMsg>>
74+
input_feedback_;
75+
76+
std::shared_ptr<control_toolbox::PidROS> yaw_pos2vel_pid_;
77+
std::shared_ptr<control_toolbox::PidROS> pitch_pos2vel_pid_;
78+
std::shared_ptr<control_toolbox::PidROS> yaw_vel2eff_pid_;
79+
std::shared_ptr<control_toolbox::PidROS> pitch_vel2eff_pid_;
80+
81+
using ControllerStatePublisher =
82+
realtime_tools::RealtimePublisher<ControllerStateMsg>;
83+
84+
rclcpp::Publisher<ControllerStateMsg>::SharedPtr s_publisher_;
85+
std::unique_ptr<ControllerStatePublisher> state_publisher_;
86+
87+
// override methods from ChainableControllerInterface
88+
std::vector<hardware_interface::CommandInterface>
89+
on_export_reference_interfaces() override;
90+
91+
bool on_set_chained_mode(bool chained_mode) override;
92+
93+
private:
94+
void reference_callback(const std::shared_ptr<ControllerReferenceMsg> msg);
95+
void feedback_callback(const std::shared_ptr<ControllerFeedbackMsg> msg);
96+
void reset_controller_reference_msg(
97+
const std::shared_ptr<ControllerReferenceMsg> &msg,
98+
const std::shared_ptr<rclcpp_lifecycle::LifecycleNode> &);
99+
void reset_controller_feedback_msg(
100+
const std::shared_ptr<ControllerFeedbackMsg> &msg,
101+
const std::shared_ptr<rclcpp_lifecycle::LifecycleNode> &node);
102+
};
103+
104+
} // namespace gimbal_controller
105+
106+
#endif // GIMBAL_CONTROLLER__GIMBAL_POSITION_CONTROLLER_HPP_

0 commit comments

Comments
 (0)