Skip to content

Commit 6d681ef

Browse files
Cleanup wrong lifecycle transitions in tests and unnecessary checks (#1534)
1 parent c83cfb3 commit 6d681ef

File tree

17 files changed

+17
-154
lines changed

17 files changed

+17
-154
lines changed

diff_drive_controller/include/diff_drive_controller/diff_drive_controller.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@ class DiffDriveController : public controller_interface::ChainableControllerInte
141141
rclcpp::Duration publish_period_ = rclcpp::Duration::from_nanoseconds(0);
142142
rclcpp::Time previous_publish_timestamp_{0, 0, RCL_CLOCK_UNINITIALIZED};
143143

144-
bool is_halted = false;
145-
146144
bool reset();
147145
void halt();
148146

diff_drive_controller/src/diff_drive_controller.cpp

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,6 @@ controller_interface::return_type DiffDriveController::update_reference_from_sub
101101
const rclcpp::Time & time, const rclcpp::Duration & /*period*/)
102102
{
103103
auto logger = get_node()->get_logger();
104-
if (get_lifecycle_state().id() == State::PRIMARY_STATE_INACTIVE)
105-
{
106-
if (!is_halted)
107-
{
108-
halt();
109-
is_halted = true;
110-
}
111-
return controller_interface::return_type::OK;
112-
}
113104

114105
const std::shared_ptr<TwistStamped> command_msg_ptr = *(received_velocity_msg_ptr_.readFromRT());
115106

@@ -149,15 +140,6 @@ controller_interface::return_type DiffDriveController::update_and_write_commands
149140
const rclcpp::Time & time, const rclcpp::Duration & period)
150141
{
151142
auto logger = get_node()->get_logger();
152-
if (get_lifecycle_state().id() == State::PRIMARY_STATE_INACTIVE)
153-
{
154-
if (!is_halted)
155-
{
156-
halt();
157-
is_halted = true;
158-
}
159-
return controller_interface::return_type::OK;
160-
}
161143

162144
// command may be limited further by SpeedLimit,
163145
// without affecting the stored twist command
@@ -562,7 +544,6 @@ controller_interface::CallbackReturn DiffDriveController::on_activate(
562544
return controller_interface::CallbackReturn::ERROR;
563545
}
564546

565-
is_halted = false;
566547
subscriber_is_active_ = true;
567548

568549
RCLCPP_DEBUG(get_node()->get_logger(), "Subscriber and publisher are now active.");
@@ -573,11 +554,7 @@ controller_interface::CallbackReturn DiffDriveController::on_deactivate(
573554
const rclcpp_lifecycle::State &)
574555
{
575556
subscriber_is_active_ = false;
576-
if (!is_halted)
577-
{
578-
halt();
579-
is_halted = true;
580-
}
557+
halt();
581558
reset_buffers();
582559
registered_left_wheel_handles_.clear();
583560
registered_right_wheel_handles_.clear();
@@ -616,7 +593,6 @@ bool DiffDriveController::reset()
616593
subscriber_is_active_ = false;
617594
velocity_command_subscriber_.reset();
618595

619-
is_halted = false;
620596
return true;
621597
}
622598

diff_drive_controller/test/test_diff_drive_controller.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -719,11 +719,16 @@ TEST_F(TestDiffDriveController, cleanup)
719719
controller_->update(rclcpp::Time(0, 0, RCL_ROS_TIME), rclcpp::Duration::from_seconds(0.01)),
720720
controller_interface::return_type::OK);
721721

722+
// should be moving
723+
EXPECT_LT(0.0, left_wheel_vel_cmd_.get_value());
724+
EXPECT_LT(0.0, right_wheel_vel_cmd_.get_value());
725+
722726
state = controller_->get_node()->deactivate();
723727
ASSERT_EQ(State::PRIMARY_STATE_INACTIVE, state.id());
724-
ASSERT_EQ(
725-
controller_->update(rclcpp::Time(0, 0, RCL_ROS_TIME), rclcpp::Duration::from_seconds(0.01)),
726-
controller_interface::return_type::OK);
728+
729+
// should be stopped
730+
EXPECT_EQ(0.0, left_wheel_vel_cmd_.get_value()) << "Wheels should be halted on deactivate()";
731+
EXPECT_EQ(0.0, right_wheel_vel_cmd_.get_value()) << "Wheels should be halted on deactivate()";
727732

728733
state = controller_->get_node()->cleanup();
729734
ASSERT_EQ(State::PRIMARY_STATE_UNCONFIGURED, state.id());

forward_command_controller/src/forward_command_controller.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ void ForwardCommandController::declare_parameters()
3131

3232
controller_interface::CallbackReturn ForwardCommandController::read_parameters()
3333
{
34-
if (!param_listener_)
35-
{
36-
RCLCPP_ERROR(get_node()->get_logger(), "Error encountered during init");
37-
return controller_interface::CallbackReturn::ERROR;
38-
}
3934
params_ = param_listener_->get_params();
4035

4136
if (params_.joints.empty())

forward_command_controller/src/multi_interface_forward_command_controller.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ void MultiInterfaceForwardCommandController::declare_parameters()
3232

3333
controller_interface::CallbackReturn MultiInterfaceForwardCommandController::read_parameters()
3434
{
35-
if (!param_listener_)
36-
{
37-
RCLCPP_ERROR(get_node()->get_logger(), "Error encountered during init");
38-
return controller_interface::CallbackReturn::ERROR;
39-
}
4035
params_ = param_listener_->get_params();
4136

4237
if (params_.joint.empty())

gpio_controllers/src/gpio_command_controller.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,6 @@ controller_interface::return_type GpioCommandController::update(
158158
bool GpioCommandController::update_dynamic_map_parameters()
159159
{
160160
auto logger = get_node()->get_logger();
161-
if (!param_listener_)
162-
{
163-
RCLCPP_ERROR(logger, "Error encountered during init");
164-
return false;
165-
}
166161
// update the dynamic map parameters
167162
param_listener_->refresh_dynamic_parameters();
168163
// get parameters from the listener in case they were updated

gripper_controllers/include/gripper_controllers/gripper_action_controller_impl.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,6 @@ controller_interface::CallbackReturn GripperActionController<HardwareInterface>:
206206
const rclcpp_lifecycle::State &)
207207
{
208208
const auto logger = get_node()->get_logger();
209-
if (!param_listener_)
210-
{
211-
RCLCPP_ERROR(get_node()->get_logger(), "Error encountered during init");
212-
return controller_interface::CallbackReturn::ERROR;
213-
}
214209
params_ = param_listener_->get_params();
215210

216211
// Action status checking update rate

joint_state_broadcaster/src/joint_state_broadcaster.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ controller_interface::InterfaceConfiguration JointStateBroadcaster::state_interf
9090
controller_interface::CallbackReturn JointStateBroadcaster::on_configure(
9191
const rclcpp_lifecycle::State & /*previous_state*/)
9292
{
93-
if (!param_listener_)
94-
{
95-
RCLCPP_ERROR(get_node()->get_logger(), "Error encountered during init");
96-
return controller_interface::CallbackReturn::ERROR;
97-
}
9893
params_ = param_listener_->get_params();
9994

10095
if (use_all_available_interfaces())

joint_state_broadcaster/test/test_joint_state_broadcaster.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -149,23 +149,6 @@ void JointStateBroadcasterTest::assign_state_interfaces(
149149
state_broadcaster_->assign_interfaces({}, std::move(state_ifs));
150150
}
151151

152-
TEST_F(JointStateBroadcasterTest, ConfigureErrorTest)
153-
{
154-
// publishers not initialized yet
155-
ASSERT_FALSE(state_broadcaster_->realtime_joint_state_publisher_);
156-
ASSERT_FALSE(state_broadcaster_->realtime_dynamic_joint_state_publisher_);
157-
158-
// configure failed
159-
ASSERT_THROW(state_broadcaster_->on_configure(rclcpp_lifecycle::State()), std::exception);
160-
161-
SetUpStateBroadcaster();
162-
// check state remains unchanged
163-
164-
// publishers still not initialized
165-
ASSERT_FALSE(state_broadcaster_->realtime_joint_state_publisher_);
166-
ASSERT_FALSE(state_broadcaster_->realtime_dynamic_joint_state_publisher_);
167-
}
168-
169152
TEST_F(JointStateBroadcasterTest, ActivateEmptyTest)
170153
{
171154
// publishers not initialized yet

joint_trajectory_controller/src/joint_trajectory_controller.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,6 @@ JointTrajectoryController::state_interface_configuration() const
144144
controller_interface::return_type JointTrajectoryController::update(
145145
const rclcpp::Time & time, const rclcpp::Duration & period)
146146
{
147-
if (get_lifecycle_state().id() == lifecycle_msgs::msg::State::PRIMARY_STATE_INACTIVE)
148-
{
149-
return controller_interface::return_type::OK;
150-
}
151147
auto logger = this->get_node()->get_logger();
152148
// update dynamic parameters
153149
if (param_listener_->is_old(params_))
@@ -655,12 +651,6 @@ controller_interface::CallbackReturn JointTrajectoryController::on_configure(
655651
{
656652
auto logger = get_node()->get_logger();
657653

658-
if (!param_listener_)
659-
{
660-
RCLCPP_ERROR(logger, "Error encountered during init");
661-
return controller_interface::CallbackReturn::ERROR;
662-
}
663-
664654
// update the dynamic map parameters
665655
param_listener_->refresh_dynamic_parameters();
666656

0 commit comments

Comments
 (0)