-
Notifications
You must be signed in to change notification settings - Fork 464
Enhance JointSaturationLimiter with Jerk limits #3417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 24 commits
8363bef
c0d7a0d
167ea8a
11756d0
763310b
886bb9c
e75ee32
4a9acd5
3051238
7f2ecf9
54a9c5c
2ac2b0f
d3fccd6
9653d5b
cc204f6
98f03d1
b53bf25
bf25ba0
57c1353
3a5d31e
b61a15a
cb7e3f0
89d71c5
f96151e
735a1f2
b6442a6
947bac0
ee8960b
4334f2d
b2c4751
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,19 @@ class JointSaturationLimiter : public JointLimiterInterface<JointLimitsStateData | |
| bool on_configure(const JointLimitsStateDataType & current_joint_states) override | ||
| { | ||
| prev_command_ = current_joint_states; | ||
| const size_t num_joints = this->number_of_joints_; | ||
|
|
||
| desired_pos_.assign(num_joints, 0.0); | ||
| desired_vel_.assign(num_joints, 0.0); | ||
| desired_acc_.assign(num_joints, 0.0); | ||
| expected_pos_.assign(num_joints, 0.0); | ||
| expected_vel_.assign(num_joints, 0.0); | ||
|
|
||
| pos_limit_hit_.assign(num_joints, false); | ||
| vel_limit_hit_.assign(num_joints, false); | ||
| acc_limit_hit_.assign(num_joints, false); | ||
| dec_limit_hit_.assign(num_joints, false); | ||
| jerk_limit_hit_.assign(num_joints, false); | ||
| return true; | ||
| } | ||
|
|
||
|
|
@@ -91,6 +104,42 @@ class JointSaturationLimiter : public JointLimiterInterface<JointLimitsStateData | |
| rclcpp::Clock::SharedPtr clock_; | ||
| JointLimitsStateDataType prev_command_; | ||
| std::mutex mutex_; | ||
|
|
||
| private: | ||
| // Cached vectors to eliminate dynamic memory allocation (malloc) in the real-time execution loop | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @saikishor is this true that we had the memory allocations previously? Can this be? |
||
| std::vector<double> desired_pos_; | ||
| std::vector<double> desired_vel_; | ||
| std::vector<double> desired_acc_; | ||
| std::vector<double> expected_vel_; | ||
| std::vector<double> expected_pos_; | ||
|
|
||
| // Pre-allocation boolean flags for tracking limits | ||
| std::vector<bool> pos_limit_hit_; | ||
| std::vector<bool> vel_limit_hit_; | ||
| std::vector<bool> acc_limit_hit_; | ||
| std::vector<bool> dec_limit_hit_; | ||
| std::vector<bool> jerk_limit_hit_; | ||
|
|
||
| /** | ||
| * @brief | ||
| * Clamps the joint limits | ||
| */ | ||
| void clamp_joint_limits( | ||
| const bool has_desired_position, const bool has_desired_velocity, | ||
| const bool has_desired_acceleration, const bool has_current_velocity, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be part of the restructuring. I would like to see this in a separate PR. This is hard to figure out what is important and why.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Separate PR created for restructuring. |
||
| const trajectory_msgs::msg::JointTrajectoryPoint & current_joint_states, | ||
| trajectory_msgs::msg::JointTrajectoryPoint & desired_joint_states, bool & limits_enforced, | ||
| const std::vector<double> & current_joint_velocities, | ||
| bool & braking_near_position_limit_triggered, const double dt_seconds); | ||
|
|
||
| /** | ||
| * @brief | ||
| * Handles the braking near position limit | ||
| */ | ||
| void handle_braking_near_position_limit( | ||
| const std::vector<double> & current_joint_velocities, double dt_seconds, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why only "position" and "velocity" input? |
||
| bool has_desired_position, bool has_desired_velocity, | ||
| const trajectory_msgs::msg::JointTrajectoryPoint & current_joint_states); | ||
| }; | ||
|
|
||
| template <typename JointLimitsStateDataType> | ||
|
|
@@ -114,6 +163,22 @@ bool JointSaturationLimiter<JointLimitsStateDataType>::on_init() | |
| template <> | ||
| bool JointSaturationLimiter<JointControlInterfacesData>::on_init(); | ||
|
|
||
| template <> | ||
| void JointSaturationLimiter<trajectory_msgs::msg::JointTrajectoryPoint>::clamp_joint_limits( | ||
| const bool has_desired_position, const bool has_desired_velocity, | ||
| const bool has_desired_acceleration, const bool has_current_velocity, | ||
| const trajectory_msgs::msg::JointTrajectoryPoint & current_joint_states, | ||
| trajectory_msgs::msg::JointTrajectoryPoint & desired_joint_states, bool & limits_enforced, | ||
| const std::vector<double> & current_joint_velocities, | ||
| bool & braking_near_position_limit_triggered, const double dt_seconds); | ||
|
|
||
| template <> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is template for what exactly? |
||
| void JointSaturationLimiter<trajectory_msgs::msg::JointTrajectoryPoint>:: | ||
| handle_braking_near_position_limit( | ||
| const std::vector<double> & current_joint_velocities, double dt_seconds, | ||
| bool has_desired_position, bool has_desired_velocity, | ||
| const trajectory_msgs::msg::JointTrajectoryPoint & current_joint_states); | ||
|
|
||
| } // namespace joint_limits | ||
|
|
||
| #endif // JOINT_LIMITS__JOINT_SATURATION_LIMITER_HPP_ | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very good catch! I would like to see this in a separate PR, as this seems to be merged very fast.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separate PR created for this.