Skip to content

Commit 00475d7

Browse files
committed
Address further comments
1 parent fde616b commit 00475d7

File tree

3 files changed

+50
-68
lines changed

3 files changed

+50
-68
lines changed

joint_trajectory_controller/include/joint_trajectory_controller/joint_trajectory_controller.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ class JointTrajectoryController : public controller_interface::ControllerInterfa
208208
void set_hold_position();
209209

210210
bool reset();
211-
void halt();
212211

213212
using JointTrajectoryPoint = trajectory_msgs::msg::JointTrajectoryPoint;
214213
void publish_state(

joint_trajectory_controller/src/joint_trajectory_controller.cpp

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,6 @@ controller_interface::return_type
105105
JointTrajectoryController::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 &)
644635
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn
645636
JointTrajectoryController::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-
715698
void 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.");

joint_trajectory_controller/test/test_trajectory_controller.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -814,38 +814,38 @@ INSTANTIATE_TEST_CASE_P(
814814
);
815815

816816
// position_velocity controllers
817-
// INSTANTIATE_TEST_CASE_P(
818-
// PositionVelocityTrajectoryControllers,
819-
// TrajectoryControllerTestParameterized,
820-
// ::testing::Values(
821-
// std::make_tuple(
822-
// std::vector<std::string>({"position", "velocity"}),
823-
// std::vector<std::string>({"position"})),
824-
// std::make_tuple(
825-
// std::vector<std::string>({"position", "velocity"}),
826-
// std::vector<std::string>({"position", "velocity"})),
827-
// std::make_tuple(
828-
// std::vector<std::string>({"position", "velocity"}),
829-
// std::vector<std::string>({"position", "velocity", "acceleration"}))
830-
// )
831-
// );
817+
INSTANTIATE_TEST_CASE_P(
818+
PositionVelocityTrajectoryControllers,
819+
TrajectoryControllerTestParameterized,
820+
::testing::Values(
821+
std::make_tuple(
822+
std::vector<std::string>({"position", "velocity"}),
823+
std::vector<std::string>({"position"})),
824+
std::make_tuple(
825+
std::vector<std::string>({"position", "velocity"}),
826+
std::vector<std::string>({"position", "velocity"})),
827+
std::make_tuple(
828+
std::vector<std::string>({"position", "velocity"}),
829+
std::vector<std::string>({"position", "velocity", "acceleration"}))
830+
)
831+
);
832832

833833
// position_velocity_acceleration controllers
834-
// INSTANTIATE_TEST_CASE_P(
835-
// PositionVelocityAccelerationTrajectoryControllers,
836-
// TrajectoryControllerTestParameterized,
837-
// ::testing::Values(
838-
// std::make_tuple(
839-
// std::vector<std::string>({"position", "velocity", "acceleration"}),
840-
// std::vector<std::string>({"position"})),
841-
// std::make_tuple(
842-
// std::vector<std::string>({"position", "velocity", "acceleration"}),
843-
// std::vector<std::string>({"position", "velocity"})),
844-
// std::make_tuple(
845-
// std::vector<std::string>({"position", "velocity", "acceleration"}),
846-
// std::vector<std::string>({"position", "velocity", "acceleration"}))
847-
// )
848-
// );
834+
INSTANTIATE_TEST_CASE_P(
835+
PositionVelocityAccelerationTrajectoryControllers,
836+
TrajectoryControllerTestParameterized,
837+
::testing::Values(
838+
std::make_tuple(
839+
std::vector<std::string>({"position", "velocity", "acceleration"}),
840+
std::vector<std::string>({"position"})),
841+
std::make_tuple(
842+
std::vector<std::string>({"position", "velocity", "acceleration"}),
843+
std::vector<std::string>({"position", "velocity"})),
844+
std::make_tuple(
845+
std::vector<std::string>({"position", "velocity", "acceleration"}),
846+
std::vector<std::string>({"position", "velocity", "acceleration"}))
847+
)
848+
);
849849

850850
TEST_F(TrajectoryControllerTest, incorrect_initialization_using_interface_parameters) {
851851
auto set_parameter_and_check_result = [&]() {

0 commit comments

Comments
 (0)