-
Notifications
You must be signed in to change notification settings - Fork 520
Fix JTC segfault #164
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
Fix JTC segfault #164
Changes from all commits
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 |
|---|---|---|
|
|
@@ -186,7 +186,8 @@ JointTrajectoryController::update() | |
| } | ||
| } | ||
|
|
||
| if (rt_active_goal_) { | ||
| const auto active_goal = *rt_active_goal_.readFromRT(); | ||
| if (active_goal) { | ||
| // send feedback | ||
| auto feedback = std::make_shared<FollowJTrajAction::Feedback>(); | ||
| feedback->header.stamp = node_->now(); | ||
|
|
@@ -195,7 +196,7 @@ JointTrajectoryController::update() | |
| feedback->actual = state_current; | ||
| feedback->desired = state_desired; | ||
| feedback->error = state_error; | ||
| rt_active_goal_->setFeedback(feedback); | ||
| active_goal->setFeedback(feedback); | ||
|
|
||
| // check abort | ||
| if (abort || outside_goal_tolerance) { | ||
|
|
@@ -208,17 +209,18 @@ JointTrajectoryController::update() | |
| RCLCPP_WARN(node_->get_logger(), "Aborted due to goal tolerance violation"); | ||
| result->set__error_code(FollowJTrajAction::Result::GOAL_TOLERANCE_VIOLATED); | ||
| } | ||
| rt_active_goal_->setAborted(result); | ||
| rt_active_goal_.reset(); | ||
| } | ||
| active_goal->setAborted(result); | ||
| // TODO(matthew-reynolds): Need a lock-free write here | ||
| rt_active_goal_.writeFromNonRT(RealtimeGoalHandlePtr()); | ||
|
|
||
| // check goal tolerance | ||
| if (!before_last_point) { | ||
| // check goal tolerance | ||
| } else if (!before_last_point) { | ||
| if (!outside_goal_tolerance) { | ||
| auto res = std::make_shared<FollowJTrajAction::Result>(); | ||
| res->set__error_code(FollowJTrajAction::Result::SUCCESSFUL); | ||
| rt_active_goal_->setSucceeded(res); | ||
| rt_active_goal_.reset(); | ||
| active_goal->setSucceeded(res); | ||
| // TODO(matthew-reynolds): Need a lock-free write here | ||
| rt_active_goal_.writeFromNonRT(RealtimeGoalHandlePtr()); | ||
|
|
||
| RCLCPP_INFO(node_->get_logger(), "Goal reached, success!"); | ||
| } else if (default_tolerances_.goal_time_tolerance != 0.0) { | ||
|
|
@@ -230,8 +232,9 @@ JointTrajectoryController::update() | |
| if (difference > default_tolerances_.goal_time_tolerance) { | ||
| auto result = std::make_shared<FollowJTrajAction::Result>(); | ||
| result->set__error_code(FollowJTrajAction::Result::GOAL_TOLERANCE_VIOLATED); | ||
| rt_active_goal_->setAborted(result); | ||
| rt_active_goal_.reset(); | ||
| active_goal->setAborted(result); | ||
| // TODO(matthew-reynolds): Need a lock-free write here | ||
| rt_active_goal_.writeFromNonRT(RealtimeGoalHandlePtr()); | ||
| RCLCPP_WARN( | ||
| node_->get_logger(), | ||
| "Aborted due goal_time_tolerance exceeding by %f seconds", | ||
|
|
@@ -554,7 +557,8 @@ rclcpp_action::CancelResponse JointTrajectoryController::cancel_callback( | |
| RCLCPP_INFO(node_->get_logger(), "Got request to cancel goal"); | ||
|
|
||
| // Check that cancel request refers to currently active goal (if any) | ||
| if (rt_active_goal_ && rt_active_goal_->gh_ == goal_handle) { | ||
| const auto active_goal = *rt_active_goal_.readFromNonRT(); | ||
| if (active_goal && active_goal->gh_ == goal_handle) { | ||
| // Controller uptime | ||
| // Enter hold current position mode | ||
| set_hold_position(); | ||
|
|
@@ -565,10 +569,8 @@ rclcpp_action::CancelResponse JointTrajectoryController::cancel_callback( | |
|
|
||
| // Mark the current goal as canceled | ||
| auto action_res = std::make_shared<FollowJTrajAction::Result>(); | ||
| rt_active_goal_->setCanceled(action_res); | ||
|
|
||
| // Reset current goal | ||
| rt_active_goal_.reset(); | ||
| active_goal->setCanceled(action_res); | ||
| rt_active_goal_.writeFromNonRT(RealtimeGoalHandlePtr()); | ||
| } | ||
| return rclcpp_action::CancelResponse::ACCEPT; | ||
| } | ||
|
|
@@ -583,17 +585,18 @@ void JointTrajectoryController::feedback_setup_callback( | |
| goal_handle->get_goal()->trajectory); | ||
|
|
||
| add_new_trajectory_msg(traj_msg); | ||
|
|
||
| RealtimeGoalHandlePtr rt_goal = std::make_shared<RealtimeGoalHandle>(goal_handle); | ||
| rt_goal->preallocated_feedback_->joint_names = joint_names_; | ||
| rt_active_goal_ = rt_goal; | ||
| rt_active_goal_->execute(); | ||
| } | ||
|
|
||
| // Update the active goal | ||
| RealtimeGoalHandlePtr rt_goal = std::make_shared<RealtimeGoalHandle>(goal_handle); | ||
| rt_goal->preallocated_feedback_->joint_names = joint_names_; | ||
| rt_goal->execute(); | ||
| rt_active_goal_.writeFromNonRT(rt_goal); | ||
|
|
||
| // Setup goal status checking timer | ||
| goal_handle_timer_ = node_->create_wall_timer( | ||
| action_monitor_period_.to_chrono<std::chrono::seconds>(), | ||
| std::bind(&RealtimeGoalHandle::runNonRealtime, rt_active_goal_)); | ||
| std::bind(&RealtimeGoalHandle::runNonRealtime, rt_goal)); | ||
| } | ||
|
Comment on lines
+590
to
600
Member
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. I think this needs further work, probably in a follow-up PR. In both the old and new code, I worry that we might end up in a condition where we're overwriting the Similarly, I think we could probably end up in a race condition where something is resetting the Would appreciate your thoughts so we can consider appropriate follow-up PRs. This PR leaves the behaviour unchanged from before, and I haven't yet run into either of those cases, so I think we're ok to leave it to a future task.
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 write-up above is a perfect start for the description of a follow-up issue ;)
Member
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. |
||
|
|
||
| void JointTrajectoryController::fill_partial_goal( | ||
|
|
@@ -782,12 +785,13 @@ void JointTrajectoryController::add_new_trajectory_msg( | |
|
|
||
| void JointTrajectoryController::preempt_active_goal() | ||
| { | ||
| if (rt_active_goal_) { | ||
| const auto active_goal = *rt_active_goal_.readFromNonRT(); | ||
| if (active_goal) { | ||
| auto action_res = std::make_shared<FollowJTrajAction::Result>(); | ||
| action_res->set__error_code(FollowJTrajAction::Result::INVALID_GOAL); | ||
| action_res->set__error_string("Current goal cancelled due to new incoming action."); | ||
| rt_active_goal_->setCanceled(action_res); | ||
| rt_active_goal_.reset(); | ||
| active_goal->setCanceled(action_res); | ||
| rt_active_goal_.writeFromNonRT(RealtimeGoalHandlePtr()); | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.