Skip to content

Commit

Permalink
Generate params for ForwardCommandController (ros-controls#396)
Browse files Browse the repository at this point in the history
* Generate params for ForwardCommandController

Signed-off-by: Tyler Weaver <[email protected]>

* Clean up CMake

Signed-off-by: Tyler Weaver <[email protected]>
Co-authored-by: Denis Štogl <[email protected]>
Co-authored-by: Bence Magyar <[email protected]>
  • Loading branch information
3 people authored Oct 13, 2022
1 parent eecb7f7 commit eccea9c
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 45 deletions.
39 changes: 26 additions & 13 deletions forward_command_controller/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ endif()

set(THIS_PACKAGE_INCLUDE_DEPENDS
controller_interface
generate_parameter_library
hardware_interface
pluginlib
rclcpp
Expand All @@ -26,17 +27,30 @@ foreach(Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS})
find_package(${Dependency} REQUIRED)
endforeach()

add_library(${PROJECT_NAME}
generate_parameter_library(
forward_command_controller_parameters
src/forward_command_controller_parameters.yaml
)
generate_parameter_library(
multi_interface_forward_command_controller_parameters
src/multi_interface_forward_command_controller_parameters.yaml
)

add_library(forward_command_controller
SHARED
src/forward_controllers_base.cpp
src/forward_command_controller.cpp
src/multi_interface_forward_command_controller.cpp
)
target_include_directories(${PROJECT_NAME} PRIVATE include)
ament_target_dependencies(${PROJECT_NAME} ${THIS_PACKAGE_INCLUDE_DEPENDS})
target_include_directories(forward_command_controller PRIVATE include)
ament_target_dependencies(forward_command_controller ${THIS_PACKAGE_INCLUDE_DEPENDS})
target_link_libraries(forward_command_controller
forward_command_controller_parameters
multi_interface_forward_command_controller_parameters
)
# Causes the visibility macros to use dllexport rather than dllimport,
# which is appropriate when building the dll but not consuming it.
target_compile_definitions(${PROJECT_NAME} PRIVATE "FORWARD_COMMAND_CONTROLLER_BUILDING_DLL")
target_compile_definitions(forward_command_controller PRIVATE "FORWARD_COMMAND_CONTROLLER_BUILDING_DLL")
pluginlib_export_plugin_description_file(controller_interface forward_command_plugin.xml)

install(
Expand All @@ -46,10 +60,14 @@ install(

install(
TARGETS
${PROJECT_NAME}
forward_command_controller
forward_command_controller_parameters
multi_interface_forward_command_controller_parameters
EXPORT export_forward_command_controller
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
INCLUDES DESTINATION include
)

if(BUILD_TESTING)
Expand All @@ -75,7 +93,7 @@ if(BUILD_TESTING)
)
target_include_directories(test_forward_command_controller PRIVATE include)
target_link_libraries(test_forward_command_controller
${PROJECT_NAME}
forward_command_controller
)

ament_add_gmock(
Expand All @@ -96,15 +114,10 @@ if(BUILD_TESTING)
)
target_include_directories(test_multi_interface_forward_command_controller PRIVATE include)
target_link_libraries(test_multi_interface_forward_command_controller
${PROJECT_NAME}
forward_command_controller
)
endif()

ament_export_targets(export_forward_command_controller HAS_LIBRARY_TARGET)
ament_export_dependencies(${THIS_PACKAGE_INCLUDE_DEPENDS})
ament_export_include_directories(
include
)
ament_export_libraries(
${PROJECT_NAME}
)
ament_package()
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
#ifndef FORWARD_COMMAND_CONTROLLER__FORWARD_COMMAND_CONTROLLER_HPP_
#define FORWARD_COMMAND_CONTROLLER__FORWARD_COMMAND_CONTROLLER_HPP_

#include <memory>
#include <string>
#include <vector>

#include "forward_command_controller/forward_controllers_base.hpp"
#include "forward_command_controller/visibility_control.h"
#include "forward_command_controller_parameters.hpp"

namespace forward_command_controller
{
Expand All @@ -44,8 +46,8 @@ class ForwardCommandController : public ForwardControllersBase
void declare_parameters() override;
controller_interface::CallbackReturn read_parameters() override;

std::vector<std::string> joint_names_;
std::string interface_name_;
std::shared_ptr<ParamListener> param_listener_;
Params params_;
};

} // namespace forward_command_controller
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
#ifndef FORWARD_COMMAND_CONTROLLER__MULTI_INTERFACE_FORWARD_COMMAND_CONTROLLER_HPP_
#define FORWARD_COMMAND_CONTROLLER__MULTI_INTERFACE_FORWARD_COMMAND_CONTROLLER_HPP_

#include <memory>
#include <string>
#include <vector>

#include "forward_command_controller/forward_controllers_base.hpp"
#include "forward_command_controller/visibility_control.h"
#include "multi_interface_forward_command_controller_parameters.hpp"

namespace forward_command_controller
{
Expand All @@ -45,8 +47,11 @@ class MultiInterfaceForwardCommandController
void declare_parameters() override;
controller_interface::CallbackReturn read_parameters() override;

std::string joint_name_;
std::vector<std::string> interface_names_;
using Params = multi_interface_forward_command_controller::Params;
using ParamListener = multi_interface_forward_command_controller::ParamListener;

std::shared_ptr<ParamListener> param_listener_;
Params params_;
};

} // namespace forward_command_controller
Expand Down
1 change: 1 addition & 0 deletions forward_command_controller/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<buildtool_depend>ament_cmake</buildtool_depend>

<depend>controller_interface</depend>
<depend>generate_parameter_library</depend>
<depend>hardware_interface</depend>
<depend>rclcpp</depend>
<depend>rclcpp_lifecycle</depend>
Expand Down
22 changes: 10 additions & 12 deletions forward_command_controller/src/forward_command_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,33 @@ ForwardCommandController::ForwardCommandController() : ForwardControllersBase()

void ForwardCommandController::declare_parameters()
{
auto_declare("joints", std::vector<std::string>());
auto_declare("interface_name", std::string());
param_listener_ = std::make_shared<ParamListener>(get_node());
}

controller_interface::CallbackReturn ForwardCommandController::read_parameters()
{
joint_names_ = get_node()->get_parameter("joints").as_string_array();

if (joint_names_.empty())
if (!param_listener_)
{
RCLCPP_ERROR(get_node()->get_logger(), "'joints' parameter was empty");
RCLCPP_ERROR(get_node()->get_logger(), "Error encountered during init");
return controller_interface::CallbackReturn::ERROR;
}
params_ = param_listener_->get_params();

// Specialized, child controllers set interfaces before calling configure function.
if (interface_name_.empty())
if (params_.joints.empty())
{
interface_name_ = get_node()->get_parameter("interface_name").as_string();
RCLCPP_ERROR(get_node()->get_logger(), "'joints' parameter was empty");
return controller_interface::CallbackReturn::ERROR;
}

if (interface_name_.empty())
if (params_.interface_name.empty())
{
RCLCPP_ERROR(get_node()->get_logger(), "'interface_name' parameter was empty");
return controller_interface::CallbackReturn::ERROR;
}

for (const auto & joint : joint_names_)
for (const auto & joint : params_.joints)
{
command_interface_types_.push_back(joint + "/" + interface_name_);
command_interface_types_.push_back(joint + "/" + params_.interface_name);
}

return controller_interface::CallbackReturn::SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
forward_command_controller:
joints: {
type: string_array,
default_value: [],
description: "Name of the joints to control",
}
interface_name: {
type: string,
default_value: "",
description: "Name of the interface to command",
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "forward_command_controller/multi_interface_forward_command_controller.hpp"

#include <memory>
#include <string>
#include <vector>

Expand All @@ -26,30 +27,33 @@ MultiInterfaceForwardCommandController::MultiInterfaceForwardCommandController()

void MultiInterfaceForwardCommandController::declare_parameters()
{
auto_declare("joint", joint_name_);
auto_declare("interface_names", interface_names_);
param_listener_ = std::make_shared<ParamListener>(get_node());
}

controller_interface::CallbackReturn MultiInterfaceForwardCommandController::read_parameters()
{
joint_name_ = get_node()->get_parameter("joint").as_string();
interface_names_ = get_node()->get_parameter("interface_names").as_string_array();
if (!param_listener_)
{
RCLCPP_ERROR(get_node()->get_logger(), "Error encountered during init");
return controller_interface::CallbackReturn::ERROR;
}
params_ = param_listener_->get_params();

if (joint_name_.empty())
if (params_.joint.empty())
{
RCLCPP_ERROR(get_node()->get_logger(), "'joint' parameter is empty");
return controller_interface::CallbackReturn::ERROR;
}

if (interface_names_.empty())
if (params_.interface_names.empty())
{
RCLCPP_ERROR(get_node()->get_logger(), "'interfaces' parameter is empty");
return controller_interface::CallbackReturn::ERROR;
}

for (const auto & interface : interface_names_)
for (const auto & interface : params_.interface_names)
{
command_interface_types_.push_back(joint_name_ + "/" + interface);
command_interface_types_.push_back(params_.joint + "/" + interface);
}

return controller_interface::CallbackReturn::SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
multi_interface_forward_command_controller:
joint: {
type: string,
default_value: "",
description: "Name of the joint to control",
}
interface_names: {
type: string_array,
default_value: [],
description: "Names of the interfaces to command",
}
11 changes: 3 additions & 8 deletions ros2_controllers-not-released.rolling.repos
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
repositories:
## EXAMPLE DEPENDENCY
# <some_ros_package>:
# type: git
# url: [email protected]:<some_github_namespace>/<some_ros_package>.git
# version: master
control_msgs:
generate_parameter_library:
type: git
url: https://github.com/ros-controls/control_msgs.git
version: humble
url: https://github.com/picknikrobotics/generate_parameter_library.git
version: main
8 changes: 8 additions & 0 deletions ros2_controllers.rolling.repos
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,11 @@ repositories:
type: git
url: https://github.com/ros-controls/kinematics_interface.git
version: master
angles:
type: git
url: https://github.com/ros/angles.git
version: ros2
generate_parameter_library:
type: git
url: https://github.com/picknikrobotics/generate_parameter_library.git
version: main

0 comments on commit eccea9c

Please sign in to comment.