Skip to content

Commit

Permalink
Set command buffers in test_controller when ALL interfaces are requested
Browse files Browse the repository at this point in the history
When only the controller_interface::InterfaceConfiguration.type == ALL is given,
but the names vector is empty, the command buffer vector is created with size 0
However, when writing the commands in update(), values for all command_interfaces
are being happily read from a vector with size 0, which is not very optimal.

With this commit, we resize the command buffer on on_activate when ALL interfaces
are requested, since at that point we know all available interfaces, as they
are set by the controller_manager's switch() method.
  • Loading branch information
fmauch committed Jul 27, 2023
1 parent ee8d1f7 commit 1987311
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
14 changes: 14 additions & 0 deletions controller_manager/test/test_controller/test_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ CallbackReturn TestController::on_configure(const rclcpp_lifecycle::State & /*pr
return CallbackReturn::SUCCESS;
}

CallbackReturn TestController::on_activate(const rclcpp_lifecycle::State & /*previous_state*/)
{
if (cmd_iface_cfg_.type == controller_interface::interface_configuration_type::ALL)
{
external_commands_for_testing_.resize(command_interfaces_.size(), 0.0);
cmd_iface_cfg_.names.resize(command_interfaces_.size());
for (size_t i = 0; i < command_interfaces_.size(); ++i)
{
cmd_iface_cfg_.names[i] = command_interfaces_[i].get_name();
}
}
return CallbackReturn::SUCCESS;
}

CallbackReturn TestController::on_cleanup(const rclcpp_lifecycle::State & /*previous_state*/)
{
if (simulate_cleanup_failure)
Expand Down
3 changes: 3 additions & 0 deletions controller_manager/test/test_controller/test_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class TestController : public controller_interface::ControllerInterface
CONTROLLER_MANAGER_PUBLIC
CallbackReturn on_configure(const rclcpp_lifecycle::State & previous_state) override;

CONTROLLER_MANAGER_PUBLIC
CallbackReturn on_activate(const rclcpp_lifecycle::State & previous_state) override;

CONTROLLER_MANAGER_PUBLIC
CallbackReturn on_cleanup(const rclcpp_lifecycle::State & previous_state) override;

Expand Down

0 comments on commit 1987311

Please sign in to comment.