@@ -230,15 +230,17 @@ controller_interface::return_type JointTrajectoryController::update(
230
230
if (
231
231
(before_last_point || first_sample) &&
232
232
!check_state_tolerance_per_joint (
233
- state_error_, index , default_tolerances_.state_tolerance [index ], false ))
233
+ state_error_, index , default_tolerances_.state_tolerance [index ], false ) &&
234
+ *(rt_is_holding_.readFromRT ()) == false )
234
235
{
235
236
tolerance_violated_while_moving = true ;
236
237
}
237
238
// past the final point, check that we end up inside goal tolerance
238
239
if (
239
240
!before_last_point &&
240
241
!check_state_tolerance_per_joint (
241
- state_error_, index , default_tolerances_.goal_state_tolerance [index ], false ))
242
+ state_error_, index , default_tolerances_.goal_state_tolerance [index ], false ) &&
243
+ *(rt_is_holding_.readFromRT ()) == false )
242
244
{
243
245
outside_goal_tolerance = true ;
244
246
@@ -831,6 +833,10 @@ controller_interface::CallbackReturn JointTrajectoryController::on_configure(
831
833
logger, " Using '%s' interpolation method." ,
832
834
interpolation_methods::InterpolationMethodMap.at (interpolation_method_).c_str ());
833
835
836
+ // prepare hold_position_msg
837
+ init_hold_position_msg ();
838
+
839
+ // create subscriber and publishers
834
840
joint_command_subscriber_ =
835
841
get_node ()->create_subscription <trajectory_msgs::msg::JointTrajectory>(
836
842
" ~/joint_trajectory" , rclcpp::SystemDefaultsQoS (),
@@ -1018,6 +1024,7 @@ controller_interface::CallbackReturn JointTrajectoryController::on_activate(
1018
1024
{
1019
1025
add_new_trajectory_msg (set_hold_position ());
1020
1026
}
1027
+ rt_is_holding_.writeFromNonRT (true );
1021
1028
1022
1029
return CallbackReturn::SUCCESS;
1023
1030
}
@@ -1203,6 +1210,7 @@ void JointTrajectoryController::topic_callback(
1203
1210
if (subscriber_is_active_)
1204
1211
{
1205
1212
add_new_trajectory_msg (msg);
1213
+ rt_is_holding_.writeFromNonRT (false );
1206
1214
}
1207
1215
};
1208
1216
@@ -1265,6 +1273,7 @@ void JointTrajectoryController::goal_accepted_callback(
1265
1273
std::make_shared<trajectory_msgs::msg::JointTrajectory>(goal_handle->get_goal ()->trajectory );
1266
1274
1267
1275
add_new_trajectory_msg (traj_msg);
1276
+ rt_is_holding_.writeFromNonRT (false );
1268
1277
}
1269
1278
1270
1279
// Update the active goal
@@ -1559,31 +1568,12 @@ std::shared_ptr<trajectory_msgs::msg::JointTrajectory>
1559
1568
JointTrajectoryController::set_hold_position ()
1560
1569
{
1561
1570
// Command to stay at current position
1562
- trajectory_msgs::msg::JointTrajectory current_pose_msg;
1563
- current_pose_msg.header .stamp =
1564
- rclcpp::Time (0.0 , 0.0 , get_node ()->get_clock ()->get_clock_type ()); // start immediately
1565
- current_pose_msg.joint_names = params_.joints ;
1566
- current_pose_msg.points .push_back (state_current_);
1567
- current_pose_msg.points [0 ].velocities .clear ();
1568
- current_pose_msg.points [0 ].accelerations .clear ();
1569
- current_pose_msg.points [0 ].effort .clear ();
1570
- if (has_velocity_command_interface_)
1571
- {
1572
- // ensure no velocity (PID will fix this)
1573
- current_pose_msg.points [0 ].velocities .resize (dof_, 0.0 );
1574
- }
1575
- if (has_acceleration_command_interface_)
1576
- {
1577
- // ensure no acceleration
1578
- current_pose_msg.points [0 ].accelerations .resize (dof_, 0.0 );
1579
- }
1580
- if (has_effort_command_interface_)
1581
- {
1582
- // ensure no explicit effort (PID will fix this)
1583
- current_pose_msg.points [0 ].effort .resize (dof_, 0.0 );
1584
- }
1571
+ hold_position_msg_ptr_->points [0 ].positions = state_current_.positions ;
1585
1572
1586
- return std::make_shared<trajectory_msgs::msg::JointTrajectory>(current_pose_msg);
1573
+ // set flag, otherwise tolerances will be checked with holding position too
1574
+ rt_is_holding_.writeFromNonRT (true );
1575
+
1576
+ return hold_position_msg_ptr_;
1587
1577
}
1588
1578
1589
1579
bool JointTrajectoryController::contains_interface_type (
@@ -1633,6 +1623,28 @@ bool JointTrajectoryController::has_active_trajectory()
1633
1623
return traj_external_point_ptr_ != nullptr && traj_external_point_ptr_->has_trajectory_msg ();
1634
1624
}
1635
1625
1626
+ void JointTrajectoryController::init_hold_position_msg ()
1627
+ {
1628
+ hold_position_msg_ptr_ = std::make_shared<trajectory_msgs::msg::JointTrajectory>();
1629
+ hold_position_msg_ptr_->header .stamp =
1630
+ rclcpp::Time (0.0 , 0.0 , get_node ()->get_clock ()->get_clock_type ()); // start immediately
1631
+ hold_position_msg_ptr_->joint_names = params_.joints ;
1632
+ hold_position_msg_ptr_->points .resize (1 ); // a trivial msg only
1633
+ hold_position_msg_ptr_->points [0 ].velocities .clear ();
1634
+ hold_position_msg_ptr_->points [0 ].accelerations .clear ();
1635
+ hold_position_msg_ptr_->points [0 ].effort .clear ();
1636
+ if (has_velocity_command_interface_ || has_acceleration_command_interface_)
1637
+ {
1638
+ // add velocity, so that trajectory sampling returns velocity points in any case
1639
+ hold_position_msg_ptr_->points [0 ].velocities .resize (dof_, 0.0 );
1640
+ }
1641
+ if (has_acceleration_command_interface_)
1642
+ {
1643
+ // add velocity, so that trajectory sampling returns acceleration points in any case
1644
+ hold_position_msg_ptr_->points [0 ].accelerations .resize (dof_, 0.0 );
1645
+ }
1646
+ }
1647
+
1636
1648
} // namespace joint_trajectory_controller
1637
1649
1638
1650
#include " pluginlib/class_list_macros.hpp"
0 commit comments