Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GPIO controller onn humble #1403

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/humble-semi-binary-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ROS_REPO: [main, testing]
ROS_REPO: [testing]
with:
ros_distro: humble
ros_repo: ${{ matrix.ROS_REPO }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/iron-semi-binary-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ROS_REPO: [main, testing]
ROS_REPO: [testing]
with:
ros_distro: iron
ros_repo: ${{ matrix.ROS_REPO }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/jazzy-semi-binary-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ROS_REPO: [main, testing]
ROS_REPO: [testing]
with:
ros_distro: jazzy
ros_repo: ${{ matrix.ROS_REPO }}
Expand Down
48 changes: 48 additions & 0 deletions .github/workflows/rolling-compatibility-humble-binary-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Check Rolling Compatibility on Humble
# author: Christoph Froehlich <[email protected]>
# description: 'Build & test the rolling version on Humble distro.'

on:
workflow_dispatch:
pull_request:
branches:
- master
- '*feature*'
- '*feature/**'
paths:
- '**.hpp'
- '**.h'
- '**.cpp'
- '**.py'
- '**.yaml'
- '.github/workflows/rolling-compatibility-humble-binary-build.yml'
- '**/package.xml'
- '**/CMakeLists.txt'
- 'ros2_controllers.rolling.repos'
push:
branches:
- master
paths:
- '**.hpp'
- '**.h'
- '**.cpp'
- '**.py'
- '**.yaml'
- '.github/workflows/rolling-compatibility-humble-binary-build.yml'
- '**/package.xml'
- '**/CMakeLists.txt'
- 'ros2_controllers.rolling.repos'

jobs:
build-on-humble:
uses: ros-controls/ros2_control_ci/.github/workflows/reusable-industrial-ci-with-cache.yml@master
strategy:
fail-fast: false
matrix:
ROS_DISTRO: [humble]
ROS_REPO: [testing]
with:
ros_distro: ${{ matrix.ROS_DISTRO }}
ros_repo: ${{ matrix.ROS_REPO }}
upstream_workspace: ros2_controllers.rolling.repos
ref_for_scheduled_build: master
48 changes: 48 additions & 0 deletions .github/workflows/rolling-compatibility-jazzy-binary-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Check Rolling Compatibility on Jazzy
# author: Christoph Froehlich <[email protected]>
# description: 'Build & test the rolling version on Jazzy distro.'

on:
workflow_dispatch:
pull_request:
branches:
- master
- '*feature*'
- '*feature/**'
paths:
- '**.hpp'
- '**.h'
- '**.cpp'
- '**.py'
- '**.yaml'
- '.github/workflows/rolling-compatibility-jazzy-binary-build.yml'
- '**/package.xml'
- '**/CMakeLists.txt'
- 'ros2_controllers.rolling.repos'
push:
branches:
- master
paths:
- '**.hpp'
- '**.h'
- '**.cpp'
- '**.py'
- '**.yaml'
- '.github/workflows/rolling-compatibility-jazzy-binary-build.yml'
- '**/package.xml'
- '**/CMakeLists.txt'
- 'ros2_controllers.rolling.repos'

jobs:
build-on-jazzy:
uses: ros-controls/ros2_control_ci/.github/workflows/reusable-industrial-ci-with-cache.yml@master
strategy:
fail-fast: false
matrix:
ROS_DISTRO: [jazzy]
ROS_REPO: [testing]
with:
ros_distro: ${{ matrix.ROS_DISTRO }}
ros_repo: ${{ matrix.ROS_REPO }}
upstream_workspace: ros2_controllers.rolling.repos
ref_for_scheduled_build: master
2 changes: 1 addition & 1 deletion .github/workflows/rolling-semi-binary-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
strategy:
fail-fast: false
matrix:
ROS_REPO: [main, testing]
ROS_REPO: [testing]
with:
ros_distro: rolling
ros_repo: ${{ matrix.ROS_REPO }}
Expand Down
3 changes: 1 addition & 2 deletions gpio_controllers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic -Werror=conversion -Werror=unused-but-set-variable
-Werror=return-type -Werror=shadow -Werror=format -Werror=range-loop-construct
-Werror=return-type -Werror=format -Werror=range-loop-construct
-Werror=missing-braces)
endif()

Expand Down Expand Up @@ -76,7 +76,6 @@ if(BUILD_TESTING)
target_include_directories(test_load_gpio_command_controller PRIVATE include)
ament_target_dependencies(test_load_gpio_command_controller
controller_manager
hardware_interface
ros2_control_test_assets
)

Expand Down
5 changes: 2 additions & 3 deletions gpio_controllers/doc/userdoc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ This controller uses the `generate_parameter_library <https://github.com/PickNik
.. generate_parameter_library_details::
../src/gpio_command_controller_parameters.yaml

The controller expects at least one GPIO interface and the corresponding command interface names or state interface. However, these Command and State interfaces are optional. The controller behaves as a broadcaster when no Command Interface is present, thereby publishing the configured GPIO state interfaces if set, else the one present in the URDF.
The controller expects at least one GPIO interface and the corresponding command interface names or state interface. However, these Command and State interfaces are optional. The controller behaves as a broadcaster when no Command Interface is present, thereby publishing the configured GPIO state interfaces if set.

.. note::

When no state interface is provided in the param file, the controller will try to use state_interfaces from ros2_control's config placed in the URDF for configured gpio interfaces.
However, command interfaces will not be configured based on the available URDF setup.
When no state or command interface is provided in the param file, the controller will fail during initialization.

.. code-block:: yaml

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "controller_interface/controller_interface.hpp"
#include "gpio_command_controller_parameters.hpp"
#include "gpio_controllers/visibility_control.h"
#include "hardware_interface/hardware_info.hpp"
#include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp"
#include "rclcpp_lifecycle/state.hpp"
#include "realtime_tools/realtime_buffer.h"
Expand Down Expand Up @@ -87,8 +88,6 @@ class GpioCommandController : public controller_interface::ControllerInterface
void apply_command(
const CmdType & gpio_commands, std::size_t gpio_index,
std::size_t command_interface_index) const;
bool should_broadcast_all_interfaces_of_configured_gpios() const;
void set_all_state_interfaces_of_configured_gpios();
InterfacesNames get_gpios_state_interfaces_names(const std::string & gpio_name) const;
bool update_dynamic_map_parameters();
std::vector<hardware_interface::ComponentInfo> get_gpios_from_urdf() const;
Expand Down
62 changes: 0 additions & 62 deletions gpio_controllers/src/gpio_command_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@ void print_interface(const rclcpp::Logger & logger, const T & command_interfaces
RCLCPP_ERROR(logger, "Got %s", interface_name.c_str());
}
}

std::vector<hardware_interface::ComponentInfo> extract_gpios_from_hardware_info(
const std::vector<hardware_interface::HardwareInfo> & hardware_infos)
{
std::vector<hardware_interface::ComponentInfo> result;
for (const auto & hardware_info : hardware_infos)
{
std::copy(
hardware_info.gpios.begin(), hardware_info.gpios.end(), std::back_insert_iterator(result));
}
return result;
}
} // namespace

namespace gpio_controllers
Expand Down Expand Up @@ -181,58 +169,8 @@ void GpioCommandController::store_command_interface_types()
}
}

bool GpioCommandController::should_broadcast_all_interfaces_of_configured_gpios() const
{
auto are_interfaces_empty = [](const auto & interfaces)
{ return interfaces.second.interfaces.empty(); };
return std::all_of(
params_.state_interfaces.gpios_map.cbegin(), params_.state_interfaces.gpios_map.cend(),
are_interfaces_empty);
}

std::vector<hardware_interface::ComponentInfo> GpioCommandController::get_gpios_from_urdf() const
try
{
return extract_gpios_from_hardware_info(
hardware_interface::parse_control_resources_from_urdf(get_robot_description()));
}
catch (const std::exception & e)
{
fprintf(stderr, "Exception thrown during extracting gpios info from urdf %s \n", e.what());
return {};
}

void GpioCommandController::set_all_state_interfaces_of_configured_gpios()
{
const auto gpios{get_gpios_from_urdf()};
for (const auto & gpio_name : params_.gpios)
{
for (const auto & gpio : gpios)
{
if (gpio_name == gpio.name)
{
std::transform(
gpio.state_interfaces.begin(), gpio.state_interfaces.end(),
std::back_insert_iterator(state_interface_types_),
[&gpio_name](const auto & interface_name)
{ return gpio_name + '/' + interface_name.name; });
}
}
}
}

void GpioCommandController::store_state_interface_types()
{
if (should_broadcast_all_interfaces_of_configured_gpios())
{
RCLCPP_INFO(
get_node()->get_logger(),
"State interfaces are not configured. All available interfaces of configured GPIOs will be "
"broadcasted.");
set_all_state_interfaces_of_configured_gpios();
return;
}

for (const auto & [gpio_name, interfaces] : params_.state_interfaces.gpios_map)
{
std::transform(
Expand Down
Loading