Skip to content

Commit 210358b

Browse files
Use new handles API in diff_drive_controller (#1565)
Co-authored-by: Christoph Fröhlich <[email protected]>
1 parent b6417a4 commit 210358b

File tree

2 files changed

+104
-75
lines changed

2 files changed

+104
-75
lines changed

diff_drive_controller/src/diff_drive_controller.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,19 @@ controller_interface::return_type DiffDriveController::update_and_write_commands
167167
double right_feedback_mean = 0.0;
168168
for (size_t index = 0; index < static_cast<size_t>(wheels_per_side_); ++index)
169169
{
170-
const double left_feedback = registered_left_wheel_handles_[index].feedback.get().get_value();
171-
const double right_feedback =
172-
registered_right_wheel_handles_[index].feedback.get().get_value();
170+
const auto left_feedback_op =
171+
registered_left_wheel_handles_[index].feedback.get().get_optional();
172+
const auto right_feedback_op =
173+
registered_right_wheel_handles_[index].feedback.get().get_optional();
174+
175+
if (!left_feedback_op.has_value() || !right_feedback_op.has_value())
176+
{
177+
RCLCPP_DEBUG(logger, "Unable to retrieve the data from the left or right wheels feedback!");
178+
return controller_interface::return_type::OK;
179+
}
180+
181+
const double left_feedback = left_feedback_op.value();
182+
const double right_feedback = right_feedback_op.value();
173183

174184
if (std::isnan(left_feedback) || std::isnan(right_feedback))
175185
{
@@ -278,12 +288,18 @@ controller_interface::return_type DiffDriveController::update_and_write_commands
278288
(linear_command + angular_command * wheel_separation / 2.0) / right_wheel_radius;
279289

280290
// Set wheels velocities:
291+
bool set_command_result = true;
281292
for (size_t index = 0; index < static_cast<size_t>(wheels_per_side_); ++index)
282293
{
283-
registered_left_wheel_handles_[index].velocity.get().set_value(velocity_left);
284-
registered_right_wheel_handles_[index].velocity.get().set_value(velocity_right);
294+
set_command_result &=
295+
registered_left_wheel_handles_[index].velocity.get().set_value(velocity_left);
296+
set_command_result &=
297+
registered_right_wheel_handles_[index].velocity.get().set_value(velocity_right);
285298
}
286299

300+
RCLCPP_DEBUG_EXPRESSION(
301+
logger, !set_command_result, "Unable to set the command to one of the command handles!");
302+
287303
return controller_interface::return_type::OK;
288304
}
289305

0 commit comments

Comments
 (0)