17 #ifndef JOINT_LIMITS__JOINT_LIMITER_INTERFACE_HPP_
18 #define JOINT_LIMITS__JOINT_LIMITER_INTERFACE_HPP_
23 #include "joint_limits/joint_limits_rosparam.hpp"
24 #include "joint_limits/visibility_control.h"
25 #include "rclcpp/node.hpp"
26 #include "rclcpp_lifecycle/lifecycle_node.hpp"
27 #include "realtime_tools/realtime_buffer.h"
28 #include "trajectory_msgs/msg/joint_trajectory_point.hpp"
32 using JointLimitsStateDataType = trajectory_msgs::msg::JointTrajectoryPoint;
34 template <
typename LimitsType>
55 JOINT_LIMITS_PUBLIC
virtual bool init(
56 const std::vector<std::string> & joint_names,
57 const rclcpp::node_interfaces::NodeParametersInterface::SharedPtr & param_itf,
58 const rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr & logging_itf,
59 const std::string & robot_description_topic =
"/robot_description")
61 number_of_joints_ = joint_names.size();
62 joint_names_ = joint_names;
63 joint_limits_.resize(number_of_joints_);
64 node_param_itf_ = param_itf;
65 node_logging_itf_ = logging_itf;
72 for (
size_t i = 0; i < number_of_joints_; ++i)
77 node_logging_itf_->get_logger(),
78 "JointLimiter: Joint '%s': parameter declaration has failed", joint_names[i].c_str());
82 if (!
get_joint_limits(joint_names[i], node_param_itf_, node_logging_itf_, joint_limits_[i]))
85 node_logging_itf_->get_logger(),
86 "JointLimiter: Joint '%s': getting parameters has failed", joint_names[i].c_str());
91 node_logging_itf_->get_logger(),
"Limits for joint %zu (%s) are:\n%s", i,
92 joint_names[i].c_str(), joint_limits_[i].to_string().c_str());
94 updated_limits_.writeFromNonRT(joint_limits_);
96 auto on_parameter_event_callback = [
this](
const std::vector<rclcpp::Parameter> & parameters)
98 rcl_interfaces::msg::SetParametersResult set_parameters_result;
99 set_parameters_result.successful =
true;
101 std::vector<LimitsType> updated_joint_limits = joint_limits_;
102 bool changed =
false;
104 for (
size_t i = 0; i < number_of_joints_; ++i)
107 joint_names_[i], parameters, node_logging_itf_, updated_joint_limits[i]);
112 updated_limits_.writeFromNonRT(updated_joint_limits);
113 RCLCPP_INFO(node_logging_itf_->get_logger(),
"Limits are dynamically updated!");
116 return set_parameters_result;
119 parameter_callback_ =
120 node_param_itf_->add_on_set_parameters_callback(on_parameter_event_callback);
127 (void)robot_description_topic;
136 JOINT_LIMITS_PUBLIC
virtual bool init(
137 const std::vector<std::string> & joint_names,
const rclcpp::Node::SharedPtr & node,
138 const std::string & robot_description_topic =
"/robot_description")
141 joint_names, node->get_node_parameters_interface(), node->get_node_logging_interface(),
142 robot_description_topic);
149 JOINT_LIMITS_PUBLIC
virtual bool init(
150 const std::vector<std::string> & joint_names,
151 const rclcpp_lifecycle::LifecycleNode::SharedPtr & lifecycle_node,
152 const std::string & robot_description_topic =
"/robot_description")
155 joint_names, lifecycle_node->get_node_parameters_interface(),
156 lifecycle_node->get_node_logging_interface(), robot_description_topic);
159 JOINT_LIMITS_PUBLIC
virtual bool configure(
const JointLimitsStateDataType & current_joint_states)
174 JointLimitsStateDataType & current_joint_states,
175 JointLimitsStateDataType & desired_joint_states,
const rclcpp::Duration & dt)
177 joint_limits_ = *(updated_limits_.readFromRT());
178 return on_enforce(current_joint_states, desired_joint_states, dt);
188 JOINT_LIMITS_PUBLIC
virtual bool enforce(std::vector<double> & desired_joint_states)
190 joint_limits_ = *(updated_limits_.readFromRT());
200 JOINT_LIMITS_PUBLIC
virtual bool on_init() = 0;
208 const JointLimitsStateDataType & current_joint_states) = 0;
221 JointLimitsStateDataType & current_joint_states,
222 JointLimitsStateDataType & desired_joint_states,
const rclcpp::Duration & dt) = 0;
234 JOINT_LIMITS_PUBLIC
virtual bool on_enforce(std::vector<double> & desired_joint_states) = 0;
236 size_t number_of_joints_;
237 std::vector<std::string> joint_names_;
238 std::vector<LimitsType> joint_limits_;
239 rclcpp::node_interfaces::NodeParametersInterface::SharedPtr node_param_itf_;
240 rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr node_logging_itf_;
243 rclcpp::node_interfaces::OnSetParametersCallbackHandle::SharedPtr parameter_callback_;
Definition: joint_limiter_interface.hpp:36
virtual JOINT_LIMITS_PUBLIC bool init(const std::vector< std::string > &joint_names, const rclcpp::Node::SharedPtr &node, const std::string &robot_description_topic="/robot_description")
Definition: joint_limiter_interface.hpp:136
virtual JOINT_LIMITS_PUBLIC bool init(const std::vector< std::string > &joint_names, const rclcpp::node_interfaces::NodeParametersInterface::SharedPtr ¶m_itf, const rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr &logging_itf, const std::string &robot_description_topic="/robot_description")
Initialization of every JointLimiter.
Definition: joint_limiter_interface.hpp:55
virtual JOINT_LIMITS_PUBLIC bool on_enforce(std::vector< double > &desired_joint_states)=0
Method is realized by an implementation.
virtual JOINT_LIMITS_PUBLIC bool on_configure(const JointLimitsStateDataType ¤t_joint_states)=0
Method is realized by an implementation.
virtual JOINT_LIMITS_PUBLIC bool enforce(std::vector< double > &desired_joint_states)
Enforce joint limits to desired joint state for single physical quantity.
Definition: joint_limiter_interface.hpp:188
virtual JOINT_LIMITS_PUBLIC bool on_enforce(JointLimitsStateDataType ¤t_joint_states, JointLimitsStateDataType &desired_joint_states, const rclcpp::Duration &dt)=0
Method is realized by an implementation.
virtual JOINT_LIMITS_PUBLIC bool init(const std::vector< std::string > &joint_names, const rclcpp_lifecycle::LifecycleNode::SharedPtr &lifecycle_node, const std::string &robot_description_topic="/robot_description")
Definition: joint_limiter_interface.hpp:149
virtual JOINT_LIMITS_PUBLIC bool enforce(JointLimitsStateDataType ¤t_joint_states, JointLimitsStateDataType &desired_joint_states, const rclcpp::Duration &dt)
Enforce joint limits to desired joint state for multiple physical quantities.
Definition: joint_limiter_interface.hpp:173
virtual JOINT_LIMITS_PUBLIC bool on_init()=0
Method is realized by an implementation.
Definition: joint_limiter_interface.hpp:31
bool check_for_limits_update(const std::string &joint_name, const std::vector< rclcpp::Parameter > ¶meters, const rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr &logging_itf, JointLimits &updated_limits)
Definition: joint_limits_rosparam.hpp:431
bool declare_parameters(const std::string &joint_name, const rclcpp::node_interfaces::NodeParametersInterface::SharedPtr ¶m_itf, const rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr &logging_itf)
Definition: joint_limits_rosparam.hpp:86
bool get_joint_limits(const std::string &joint_name, const rclcpp::node_interfaces::NodeParametersInterface::SharedPtr ¶m_itf, const rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr &logging_itf, JointLimits &limits)
Populate a JointLimits instance from the node parameters.
Definition: joint_limits_rosparam.hpp:225