Skip to content

Commit 39dafe9

Browse files
committed
fix tests
1 parent aebb8be commit 39dafe9

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

steering_controllers_library/test/test_steering_controllers_library_steering_input.cpp

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,24 +107,35 @@ TEST_F(SteeringControllersLibrarySteeringInputTest, test_both_update_methods_for
107107
std::shared_ptr<ControllerSteeringReferenceMsg> msg =
108108
std::make_shared<ControllerSteeringReferenceMsg>();
109109

110-
// adjusting to achieve age_of_last_command > ref_timeout
110+
// First send a valid (non-timeout) message to establish command interface values
111+
msg->header.stamp = controller_->get_node()->now();
112+
msg->linear_velocity = TEST_LINEAR_VELOCITY_X;
113+
msg->steering_angle = TEST_STEERING_ANGLE;
114+
controller_->input_ref_steering_.set(*msg);
115+
116+
// Process the valid message
117+
ASSERT_EQ(
118+
controller_->update(controller_->get_node()->now(), rclcpp::Duration::from_seconds(0.01)),
119+
controller_interface::return_type::OK);
120+
121+
// Now send the timeout message to test timeout behavior
111122
msg->header.stamp = controller_->get_node()->now() - controller_->ref_timeout_ -
112123
rclcpp::Duration::from_seconds(0.1);
113124
msg->linear_velocity = TEST_LINEAR_VELOCITY_X;
114125
msg->steering_angle = TEST_STEERING_ANGLE;
115-
controller_->input_ref_steering_.writeFromNonRT(msg);
126+
controller_->input_ref_steering_.set(*msg);
116127

117128
const auto age_of_last_command =
118129
controller_->get_node()->now() -
119-
(*(controller_->input_ref_steering_.readFromNonRT()))->header.stamp;
130+
controller_->input_ref_steering_.get().header.stamp;
120131

121132
// case 1 position_feedback = false
122133
controller_->params_.position_feedback = false;
123134

124135
// age_of_last_command > ref_timeout_
125136
ASSERT_FALSE(age_of_last_command <= controller_->ref_timeout_);
126137
ASSERT_EQ(
127-
(*(controller_->input_ref_steering_.readFromRT()))->linear_velocity, TEST_LINEAR_VELOCITY_X);
138+
controller_->input_ref_steering_.get().linear_velocity, TEST_LINEAR_VELOCITY_X);
128139
ASSERT_EQ(
129140
controller_->update(controller_->get_node()->now(), rclcpp::Duration::from_seconds(0.01)),
130141
controller_interface::return_type::OK);
@@ -135,10 +146,8 @@ TEST_F(SteeringControllersLibrarySteeringInputTest, test_both_update_methods_for
135146
{
136147
EXPECT_TRUE(std::isnan(interface));
137148
}
138-
ASSERT_EQ(
139-
(*(controller_->input_ref_steering_.readFromNonRT()))->linear_velocity, TEST_LINEAR_VELOCITY_X);
140-
ASSERT_EQ(
141-
(*(controller_->input_ref_steering_.readFromNonRT()))->steering_angle, TEST_STEERING_ANGLE);
149+
ASSERT_TRUE(std::isnan(controller_->input_ref_steering_.get().linear_velocity));
150+
ASSERT_TRUE(std::isnan(controller_->input_ref_steering_.get().steering_angle));
142151

143152
EXPECT_TRUE(std::isnan(controller_->reference_interfaces_[0]));
144153
for (const auto & interface : controller_->reference_interfaces_)
@@ -157,17 +166,28 @@ TEST_F(SteeringControllersLibrarySteeringInputTest, test_both_update_methods_for
157166
// case 2 position_feedback = true
158167
controller_->params_.position_feedback = true;
159168

160-
// adjusting to achieve age_of_last_command > ref_timeout
169+
// First send a valid message for the position_feedback=true case
170+
msg->header.stamp = controller_->get_node()->now();
171+
msg->linear_velocity = TEST_LINEAR_VELOCITY_X;
172+
msg->steering_angle = TEST_STEERING_ANGLE;
173+
controller_->input_ref_steering_.set(*msg);
174+
175+
// Process the valid message
176+
ASSERT_EQ(
177+
controller_->update(controller_->get_node()->now(), rclcpp::Duration::from_seconds(0.01)),
178+
controller_interface::return_type::OK);
179+
180+
// Now send the timeout message to test timeout behavior with position_feedback=true
161181
msg->header.stamp = controller_->get_node()->now() - controller_->ref_timeout_ -
162182
rclcpp::Duration::from_seconds(0.1);
163183
msg->linear_velocity = TEST_LINEAR_VELOCITY_X;
164184
msg->steering_angle = TEST_STEERING_ANGLE;
165-
controller_->input_ref_steering_.writeFromNonRT(msg);
185+
controller_->input_ref_steering_.set(*msg);
166186

167187
// age_of_last_command > ref_timeout_
168188
ASSERT_FALSE(age_of_last_command <= controller_->ref_timeout_);
169189
ASSERT_EQ(
170-
(*(controller_->input_ref_steering_.readFromRT()))->linear_velocity, TEST_LINEAR_VELOCITY_X);
190+
controller_->input_ref_steering_.get().linear_velocity, TEST_LINEAR_VELOCITY_X);
171191
ASSERT_EQ(
172192
controller_->update(controller_->get_node()->now(), rclcpp::Duration::from_seconds(0.01)),
173193
controller_interface::return_type::OK);
@@ -178,10 +198,8 @@ TEST_F(SteeringControllersLibrarySteeringInputTest, test_both_update_methods_for
178198
{
179199
EXPECT_TRUE(std::isnan(interface));
180200
}
181-
ASSERT_EQ(
182-
(*(controller_->input_ref_steering_.readFromNonRT()))->linear_velocity, TEST_LINEAR_VELOCITY_X);
183-
ASSERT_EQ(
184-
(*(controller_->input_ref_steering_.readFromNonRT()))->steering_angle, TEST_STEERING_ANGLE);
201+
ASSERT_TRUE(std::isnan(controller_->input_ref_steering_.get().linear_velocity));
202+
ASSERT_TRUE(std::isnan(controller_->input_ref_steering_.get().steering_angle));
185203

186204
EXPECT_TRUE(std::isnan(controller_->reference_interfaces_[0]));
187205
for (const auto & interface : controller_->reference_interfaces_)

0 commit comments

Comments
 (0)