1- // Copyright 2022 VoodooIT, sole proprietorship
1+ // Copyright 2021, PickNik Inc.
22//
33// Licensed under the Apache License, Version 2.0 (the "License");
44// you may not use this file except in compliance with the License.
1414
1515#include " cartesian_controllers/twist_controller.hpp"
1616
17+ #include < memory>
18+ #include < string>
19+ #include < vector>
20+
21+ #include " controller_interface/helpers.hpp"
22+ #include " hardware_interface/loaned_command_interface.hpp"
23+
1724namespace cartesian_controllers
1825{
26+ using hardware_interface::LoanedCommandInterface;
27+
1928TwistController::TwistController ()
2029: controller_interface::ControllerInterface(),
2130 rt_command_ptr_ (nullptr ),
@@ -60,38 +69,9 @@ CallbackReturn TwistController::on_init()
6069 return CallbackReturn::SUCCESS;
6170}
6271
63- controller_interface::return_type TwistController::update (
64- const rclcpp::Time & /* time*/ , const rclcpp::Duration & /* period*/ )
65- {
66- auto twist_commands = rt_command_ptr_.readFromRT ();
67-
68- // no command received yet
69- if (!twist_commands || !(*twist_commands))
70- {
71- return controller_interface::return_type::OK;
72- }
73-
74- if (command_interfaces_.size () != 6 )
75- {
76- RCLCPP_ERROR_THROTTLE (
77- get_node ()->get_logger (), *node_->get_clock (), 1000 ,
78- " Twist controller needs does not match number of interfaces needed 6, given (%zu) interfaces" ,
79- command_interfaces_.size ());
80- return controller_interface::return_type::ERROR;
81- }
82- command_interfaces_[0 ].set_value ((*twist_commands)->twist .linear .x );
83- command_interfaces_[1 ].set_value ((*twist_commands)->twist .linear .y );
84- command_interfaces_[2 ].set_value ((*twist_commands)->twist .linear .z );
85- command_interfaces_[3 ].set_value ((*twist_commands)->twist .angular .x );
86- command_interfaces_[4 ].set_value ((*twist_commands)->twist .angular .y );
87- command_interfaces_[5 ].set_value ((*twist_commands)->twist .angular .z );
88-
89- return controller_interface::return_type::OK;
90- }
91-
9272CallbackReturn TwistController::on_configure (const rclcpp_lifecycle::State & /* previous_state*/ )
9373{
94- joint_name_ = node_ ->get_parameter (" joint" ).as_string ();
74+ joint_name_ = get_node () ->get_parameter (" joint" ).as_string ();
9575
9676 if (joint_name_.empty ())
9777 {
@@ -102,7 +82,7 @@ CallbackReturn TwistController::on_configure(const rclcpp_lifecycle::State & /*p
10282 // Specialized, child controllers set interfaces before calling configure function.
10383 if (interface_names_.empty ())
10484 {
105- interface_names_ = node_ ->get_parameter (" interface_names" ).as_string_array ();
85+ interface_names_ = get_node () ->get_parameter (" interface_names" ).as_string_array ();
10686 }
10787
10888 if (interface_names_.empty ())
@@ -133,7 +113,36 @@ CallbackReturn TwistController::on_deactivate(const rclcpp_lifecycle::State & /*
133113 return CallbackReturn::SUCCESS;
134114}
135115
116+ controller_interface::return_type TwistController::update (
117+ const rclcpp::Time & /* time*/ , const rclcpp::Duration & /* period*/ )
118+ {
119+ auto twist_commands = rt_command_ptr_.readFromRT ();
120+
121+ // no command received yet
122+ if (!twist_commands || !(*twist_commands))
123+ {
124+ return controller_interface::return_type::OK;
125+ }
126+
127+ if (command_interfaces_.size () != 6 )
128+ {
129+ RCLCPP_ERROR_THROTTLE (
130+ get_node ()->get_logger (), *get_node ()->get_clock (), 1000 ,
131+ " Twist controller needs does not match number of interfaces needed 6, given (%zu) interfaces" ,
132+ command_interfaces_.size ());
133+ return controller_interface::return_type::ERROR;
134+ }
135+ command_interfaces_[0 ].set_value ((*twist_commands)->twist .linear .x );
136+ command_interfaces_[1 ].set_value ((*twist_commands)->twist .linear .y );
137+ command_interfaces_[2 ].set_value ((*twist_commands)->twist .linear .z );
138+ command_interfaces_[3 ].set_value ((*twist_commands)->twist .angular .x );
139+ command_interfaces_[4 ].set_value ((*twist_commands)->twist .angular .y );
140+ command_interfaces_[5 ].set_value ((*twist_commands)->twist .angular .z );
141+
142+ return controller_interface::return_type::OK;
143+ }
136144} // namespace cartesian_controllers
145+
137146#include " pluginlib/class_list_macros.hpp"
138147
139148PLUGINLIB_EXPORT_CLASS (
0 commit comments