@@ -105,10 +105,6 @@ controller_interface::return_type
105105JointTrajectoryController::update ()
106106{
107107 if (get_current_state ().id () == lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE) {
108- if (!is_halted_) {
109- halt ();
110- is_halted_ = true ;
111- }
112108 return controller_interface::return_type::OK;
113109 }
114110
@@ -322,8 +318,6 @@ JointTrajectoryController::on_configure(const rclcpp_lifecycle::State &)
322318 if (!reset ()) {
323319 return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::ERROR;
324320 }
325- // The controller should be in halted state after creation otherwise memory corruption
326- is_halted_ = true ;
327321
328322 if (joint_names_.empty ()) {
329323 RCLCPP_WARN (logger, " 'joints' parameter is empty." );
@@ -453,24 +447,22 @@ JointTrajectoryController::on_configure(const rclcpp_lifecycle::State &)
453447 return CallbackReturn::ERROR;
454448 }
455449
450+ auto get_interface_list = [](const std::vector<std::string> & interface_types) {
451+ std::stringstream ss_command_interfaces;
452+ for (size_t index = 0 ; index < interface_types.size (); ++index) {
453+ if (index != 0 ) {
454+ ss_command_interfaces << " " ;
455+ }
456+ ss_command_interfaces << interface_types[index];
457+ }
458+ return ss_command_interfaces.str ();
459+ };
460+
456461 // Print output so users can be sure the interface setup is correct
457- std::stringstream ss_command_interfaces;
458- for (auto index = 0ul ; index < command_interface_types_.size (); ++index) {
459- if (index != 0 ) {
460- ss_command_interfaces << " " ;
461- }
462- ss_command_interfaces << command_interface_types_[index];
463- }
464- std::stringstream ss_state_interfaces;
465- for (auto index = 0ul ; index < state_interface_types_.size (); ++index) {
466- if (index != 0 ) {
467- ss_state_interfaces << " " ;
468- }
469- ss_state_interfaces << state_interface_types_[index];
470- }
471462 RCLCPP_INFO (
472463 logger, " Command interfaces are [%s] and and state interfaces are [%s]." ,
473- ss_command_interfaces.str ().c_str (), ss_state_interfaces.str ().c_str ());
464+ get_interface_list (command_interface_types_).c_str (),
465+ get_interface_list (state_interface_types_).c_str ());
474466
475467 default_tolerances_ = get_segment_tolerances (*node_, joint_names_);
476468
@@ -632,7 +624,6 @@ JointTrajectoryController::on_activate(const rclcpp_lifecycle::State &)
632624 traj_external_point_ptr_ = std::make_shared<Trajectory>();
633625 traj_home_point_ptr_ = std::make_shared<Trajectory>();
634626
635- is_halted_ = false ;
636627 subscriber_is_active_ = true ;
637628 traj_point_active_ptr_ = &traj_external_point_ptr_;
638629 last_state_publish_time_ = node_->now ();
@@ -644,6 +635,12 @@ JointTrajectoryController::on_activate(const rclcpp_lifecycle::State &)
644635rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn
645636JointTrajectoryController::on_deactivate (const rclcpp_lifecycle::State &)
646637{
638+ // TODO(anyone): How to halt when using effort commands?
639+ for (auto index = 0ul ; index < joint_names_.size (); ++index) {
640+ joint_command_interface_[0 ][index].get ().set_value (
641+ joint_command_interface_[0 ][index].get ().get_value ());
642+ }
643+
647644 for (auto index = 0ul ; index < allowed_interface_types_.size (); ++index) {
648645 joint_command_interface_[index].clear ();
649646 joint_state_interface_[index].clear ();
@@ -687,8 +684,6 @@ JointTrajectoryController::reset()
687684 traj_home_point_ptr_.reset ();
688685 traj_msg_home_ptr_.reset ();
689686
690- is_halted_ = false ;
691-
692687 return true ;
693688}
694689
@@ -700,18 +695,6 @@ JointTrajectoryController::on_shutdown(const rclcpp_lifecycle::State &)
700695 return rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn::SUCCESS;
701696}
702697
703- void
704- JointTrajectoryController::halt ()
705- {
706- // TODO(anyone): How to halt when using effort commands?
707- // TODO(anyone): Does this make sense at all? When we stop controller an call deactivate
708- // the controller does not have access to the interfaces anymore...
709- for (auto index = 0ul ; index < joint_names_.size (); ++index) {
710- joint_command_interface_[0 ][index].get ().set_value (
711- joint_command_interface_[0 ][index].get ().get_value ());
712- }
713- }
714-
715698void JointTrajectoryController::publish_state (
716699 const JointTrajectoryPoint & desired_state,
717700 const JointTrajectoryPoint & current_state, const JointTrajectoryPoint & state_error)
@@ -752,7 +735,7 @@ rclcpp_action::GoalResponse JointTrajectoryController::goal_callback(
752735 RCLCPP_INFO (node_->get_logger (), " Received new action goal" );
753736
754737 // Precondition: Running controller
755- if (is_halted_ ) {
738+ if (get_current_state (). id () == lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE ) {
756739 RCLCPP_ERROR (
757740 node_->get_logger (),
758741 " Can't accept new action goals. Controller is not running." );
0 commit comments