Skip to content
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
102 changes: 102 additions & 0 deletions forward_command_controller/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
cmake_minimum_required(VERSION 3.5)
project(forward_command_controller)

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(controller_interface REQUIRED)
find_package(hardware_interface REQUIRED)
find_package(pluginlib REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_lifecycle REQUIRED)
find_package(realtime_tools REQUIRED)
find_package(std_msgs REQUIRED)

add_library(forward_command_controller
SHARED
src/forward_command_controller.cpp
)
target_include_directories(forward_command_controller PRIVATE include)
ament_target_dependencies(forward_command_controller
builtin_interfaces
controller_interface
hardware_interface
pluginlib
rclcpp_lifecycle
rcutils
realtime_tools
std_msgs
)
# Causes the visibility macros to use dllexport rather than dllimport,
# which is appropriate when building the dll but not consuming it.
target_compile_definitions(forward_command_controller PRIVATE "FORWARD_COMMAND_CONTROLLER_BUILDING_DLL")

pluginlib_export_plugin_description_file(controller_interface forward_command_plugin.xml)

install(
DIRECTORY include/
DESTINATION include
)

install(
TARGETS
forward_command_controller
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)

if(BUILD_TESTING)
find_package(ament_cmake_gtest REQUIRED)
find_package(ament_lint_auto REQUIRED)
find_package(controller_manager REQUIRED)
find_package(test_robot_hardware REQUIRED)

ament_lint_auto_find_test_dependencies()

ament_add_gtest(
test_load_forward_command_controller
test/test_load_forward_command_controller.cpp
)
target_include_directories(test_load_forward_command_controller PRIVATE include)
ament_target_dependencies(test_load_forward_command_controller
controller_manager
test_robot_hardware
)

ament_add_gtest(
test_forward_command_controller
test/test_forward_command_controller.cpp
)
target_include_directories(test_forward_command_controller PRIVATE include)
target_link_libraries(test_forward_command_controller
forward_command_controller
)
ament_target_dependencies(test_forward_command_controller
test_robot_hardware
)
endif()

ament_export_dependencies(
controller_interface
hardware_interface
rclcpp
rclcpp_lifecycle
realtime_tools
std_msgs
)
ament_export_include_directories(
include
)
ament_export_libraries(
forward_command_controller
)
ament_package()
7 changes: 7 additions & 0 deletions forward_command_controller/forward_command_plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<library path="forward_command_controller">
<class name="forward_command_controller/ForwardCommandController" type="forward_command_controller::ForwardCommandController" base_class_type="controller_interface::ControllerInterface">
<description>
The forward command controller commands a group of joints in a given interface
</description>
</class>
</library>
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright 2020 PAL Robotics S.L.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef FORWARD_COMMAND_CONTROLLER__FORWARD_COMMAND_CONTROLLER_HPP_
#define FORWARD_COMMAND_CONTROLLER__FORWARD_COMMAND_CONTROLLER_HPP_

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

#include "controller_interface/controller_interface.hpp"
#include "forward_command_controller/visibility_control.h"
#include "hardware_interface/joint_handle.hpp"
#include "rclcpp_lifecycle/node_interfaces/lifecycle_node_interface.hpp"
#include "rclcpp_lifecycle/state.hpp"
#include "rclcpp/subscription.hpp"
#include "realtime_tools/realtime_buffer.h"
#include "std_msgs/msg/float64_multi_array.hpp"

namespace forward_command_controller
{

/**
* \brief Forward command controller for a set of joints.
*
* This class forwards the command signal down to a set of joints
* on the specified interface.
*
* \param joints Names of the joints to control.
* \param interface_name Name of the interface to command.
*
* Subscribes to:
* - \b commands (std_msgs::msg::Float64MultiArray) : The commands to apply.
*/
class ForwardCommandController : public controller_interface::ControllerInterface
{
public:
FORWARD_COMMAND_CONTROLLER_PUBLIC
ForwardCommandController();

FORWARD_COMMAND_CONTROLLER_PUBLIC
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn
on_configure(const rclcpp_lifecycle::State & previous_state) override;

FORWARD_COMMAND_CONTROLLER_PUBLIC
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn
on_activate(const rclcpp_lifecycle::State & previous_state) override;

FORWARD_COMMAND_CONTROLLER_PUBLIC
rclcpp_lifecycle::node_interfaces::LifecycleNodeInterface::CallbackReturn
on_deactivate(const rclcpp_lifecycle::State & previous_state) override;

FORWARD_COMMAND_CONTROLLER_PUBLIC
controller_interface::return_type
update() override;

protected:
using CmdType = std_msgs::msg::Float64MultiArray;

std::vector<hardware_interface::JointHandle> joint_cmd_handles_;
realtime_tools::RealtimeBuffer<std::shared_ptr<CmdType>> rt_command_ptr_;
rclcpp::Subscription<CmdType>::SharedPtr joints_command_subscriber_;

std::string logger_name_;
};

} // namespace forward_command_controller

#endif // FORWARD_COMMAND_CONTROLLER__FORWARD_COMMAND_CONTROLLER_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2020 PAL Robotics S.L.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/* This header must be included by all rclcpp headers which declare symbols
* which are defined in the rclcpp library. When not building the rclcpp
* library, i.e. when using the headers in other package's code, the contents
* of this header change the visibility of certain symbols which the rclcpp
* library cannot have, but the consuming code must have inorder to link.
*/

#ifndef FORWARD_COMMAND_CONTROLLER__VISIBILITY_CONTROL_H_
#define FORWARD_COMMAND_CONTROLLER__VISIBILITY_CONTROL_H_

// This logic was borrowed (then namespaced) from the examples on the gcc wiki:
// https://gcc.gnu.org/wiki/Visibility

#if defined _WIN32 || defined __CYGWIN__
#ifdef __GNUC__
#define FORWARD_COMMAND_CONTROLLER_EXPORT __attribute__ ((dllexport))
#define FORWARD_COMMAND_CONTROLLER_IMPORT __attribute__ ((dllimport))
#else
#define FORWARD_COMMAND_CONTROLLER_EXPORT __declspec(dllexport)
#define FORWARD_COMMAND_CONTROLLER_IMPORT __declspec(dllimport)
#endif
#ifdef FORWARD_COMMAND_CONTROLLER_BUILDING_DLL
#define FORWARD_COMMAND_CONTROLLER_PUBLIC FORWARD_COMMAND_CONTROLLER_EXPORT
#else
#define FORWARD_COMMAND_CONTROLLER_PUBLIC FORWARD_COMMAND_CONTROLLER_IMPORT
#endif
#define FORWARD_COMMAND_CONTROLLER_PUBLIC_TYPE FORWARD_COMMAND_CONTROLLER_PUBLIC
#define FORWARD_COMMAND_CONTROLLER_LOCAL
#else
#define FORWARD_COMMAND_CONTROLLER_EXPORT __attribute__ ((visibility("default")))
#define FORWARD_COMMAND_CONTROLLER_IMPORT
#if __GNUC__ >= 4
#define FORWARD_COMMAND_CONTROLLER_PUBLIC __attribute__ ((visibility("default")))
#define FORWARD_COMMAND_CONTROLLER_LOCAL __attribute__ ((visibility("hidden")))
#else
#define FORWARD_COMMAND_CONTROLLER_PUBLIC
#define FORWARD_COMMAND_CONTROLLER_LOCAL
#endif
#define FORWARD_COMMAND_CONTROLLER_PUBLIC_TYPE
#endif

#endif // FORWARD_COMMAND_CONTROLLER__VISIBILITY_CONTROL_H_
31 changes: 31 additions & 0 deletions forward_command_controller/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0"?>
<package format="3">
<name>forward_command_controller</name>
<version>0.0.0</version>
<description>Generic controller for forwarding commands.</description>
<maintainer email="bence.magyar.robotics@gmail.com">Bence Magyar</maintainer>
<maintainer email="jordan.palacios@pal-robotics.com">Jordan Palacios</maintainer>

<license>Apache License 2.0</license>

<buildtool_depend>ament_cmake</buildtool_depend>

<depend>controller_interface</depend>
<depend>hardware_interface</depend>
<depend>rclcpp</depend>
<depend>rclcpp_lifecycle</depend>
<depend>realtime_tools</depend>
<depend>std_msgs</depend>

<build_depend>pluginlib</build_depend>

<test_depend>ament_cmake_gtest</test_depend>
<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<test_depend>controller_manager</test_depend>
<test_depend>test_robot_hardware</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Loading