@@ -186,7 +186,8 @@ JointTrajectoryController::update()
186
186
}
187
187
}
188
188
189
- if (rt_active_goal_) {
189
+ const auto active_goal = *rt_active_goal_.readFromRT ();
190
+ if (active_goal) {
190
191
// send feedback
191
192
auto feedback = std::make_shared<FollowJTrajAction::Feedback>();
192
193
feedback->header .stamp = node_->now ();
@@ -195,7 +196,7 @@ JointTrajectoryController::update()
195
196
feedback->actual = state_current;
196
197
feedback->desired = state_desired;
197
198
feedback->error = state_error;
198
- rt_active_goal_ ->setFeedback (feedback);
199
+ active_goal ->setFeedback (feedback);
199
200
200
201
// check abort
201
202
if (abort || outside_goal_tolerance) {
@@ -208,17 +209,18 @@ JointTrajectoryController::update()
208
209
RCLCPP_WARN (node_->get_logger (), " Aborted due to goal tolerance violation" );
209
210
result->set__error_code (FollowJTrajAction::Result::GOAL_TOLERANCE_VIOLATED);
210
211
}
211
- rt_active_goal_ ->setAborted (result);
212
- rt_active_goal_. reset ();
213
- }
212
+ active_goal ->setAborted (result);
213
+ // TODO(matthew-reynolds): Need a lock-free write here
214
+ rt_active_goal_. writeFromNonRT ( RealtimeGoalHandlePtr ());
214
215
215
- // check goal tolerance
216
- if (!before_last_point) {
216
+ // check goal tolerance
217
+ } else if (!before_last_point) {
217
218
if (!outside_goal_tolerance) {
218
219
auto res = std::make_shared<FollowJTrajAction::Result>();
219
220
res->set__error_code (FollowJTrajAction::Result::SUCCESSFUL);
220
- rt_active_goal_->setSucceeded (res);
221
- rt_active_goal_.reset ();
221
+ active_goal->setSucceeded (res);
222
+ // TODO(matthew-reynolds): Need a lock-free write here
223
+ rt_active_goal_.writeFromNonRT (RealtimeGoalHandlePtr ());
222
224
223
225
RCLCPP_INFO (node_->get_logger (), " Goal reached, success!" );
224
226
} else if (default_tolerances_.goal_time_tolerance != 0.0 ) {
@@ -230,8 +232,9 @@ JointTrajectoryController::update()
230
232
if (difference > default_tolerances_.goal_time_tolerance ) {
231
233
auto result = std::make_shared<FollowJTrajAction::Result>();
232
234
result->set__error_code (FollowJTrajAction::Result::GOAL_TOLERANCE_VIOLATED);
233
- rt_active_goal_->setAborted (result);
234
- rt_active_goal_.reset ();
235
+ active_goal->setAborted (result);
236
+ // TODO(matthew-reynolds): Need a lock-free write here
237
+ rt_active_goal_.writeFromNonRT (RealtimeGoalHandlePtr ());
235
238
RCLCPP_WARN (
236
239
node_->get_logger (),
237
240
" Aborted due goal_time_tolerance exceeding by %f seconds" ,
@@ -554,7 +557,8 @@ rclcpp_action::CancelResponse JointTrajectoryController::cancel_callback(
554
557
RCLCPP_INFO (node_->get_logger (), " Got request to cancel goal" );
555
558
556
559
// Check that cancel request refers to currently active goal (if any)
557
- if (rt_active_goal_ && rt_active_goal_->gh_ == goal_handle) {
560
+ const auto active_goal = *rt_active_goal_.readFromNonRT ();
561
+ if (active_goal && active_goal->gh_ == goal_handle) {
558
562
// Controller uptime
559
563
// Enter hold current position mode
560
564
set_hold_position ();
@@ -565,10 +569,8 @@ rclcpp_action::CancelResponse JointTrajectoryController::cancel_callback(
565
569
566
570
// Mark the current goal as canceled
567
571
auto action_res = std::make_shared<FollowJTrajAction::Result>();
568
- rt_active_goal_->setCanceled (action_res);
569
-
570
- // Reset current goal
571
- rt_active_goal_.reset ();
572
+ active_goal->setCanceled (action_res);
573
+ rt_active_goal_.writeFromNonRT (RealtimeGoalHandlePtr ());
572
574
}
573
575
return rclcpp_action::CancelResponse::ACCEPT;
574
576
}
@@ -583,17 +585,18 @@ void JointTrajectoryController::feedback_setup_callback(
583
585
goal_handle->get_goal ()->trajectory );
584
586
585
587
add_new_trajectory_msg (traj_msg);
586
-
587
- RealtimeGoalHandlePtr rt_goal = std::make_shared<RealtimeGoalHandle>(goal_handle);
588
- rt_goal->preallocated_feedback_ ->joint_names = joint_names_;
589
- rt_active_goal_ = rt_goal;
590
- rt_active_goal_->execute ();
591
588
}
592
589
590
+ // Update the active goal
591
+ RealtimeGoalHandlePtr rt_goal = std::make_shared<RealtimeGoalHandle>(goal_handle);
592
+ rt_goal->preallocated_feedback_ ->joint_names = joint_names_;
593
+ rt_goal->execute ();
594
+ rt_active_goal_.writeFromNonRT (rt_goal);
595
+
593
596
// Setup goal status checking timer
594
597
goal_handle_timer_ = node_->create_wall_timer (
595
598
action_monitor_period_.to_chrono <std::chrono::seconds>(),
596
- std::bind (&RealtimeGoalHandle::runNonRealtime, rt_active_goal_ ));
599
+ std::bind (&RealtimeGoalHandle::runNonRealtime, rt_goal ));
597
600
}
598
601
599
602
void JointTrajectoryController::fill_partial_goal (
@@ -782,12 +785,13 @@ void JointTrajectoryController::add_new_trajectory_msg(
782
785
783
786
void JointTrajectoryController::preempt_active_goal ()
784
787
{
785
- if (rt_active_goal_) {
788
+ const auto active_goal = *rt_active_goal_.readFromNonRT ();
789
+ if (active_goal) {
786
790
auto action_res = std::make_shared<FollowJTrajAction::Result>();
787
791
action_res->set__error_code (FollowJTrajAction::Result::INVALID_GOAL);
788
792
action_res->set__error_string (" Current goal cancelled due to new incoming action." );
789
- rt_active_goal_ ->setCanceled (action_res);
790
- rt_active_goal_.reset ( );
793
+ active_goal ->setCanceled (action_res);
794
+ rt_active_goal_.writeFromNonRT ( RealtimeGoalHandlePtr () );
791
795
}
792
796
}
793
797
0 commit comments