Skip to content

Commit 97bca55

Browse files
committed
Add an outline for the "passthrough controller"
1 parent 82a4e24 commit 97bca55

File tree

7 files changed

+303
-0
lines changed

7 files changed

+303
-0
lines changed

passthrough_controller/CMakeLists.txt

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
project(passthrough_controller LANGUAGES CXX)
3+
4+
if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
5+
add_compile_options(-Wall -Wextra)
6+
endif()
7+
8+
set(THIS_PACKAGE_INCLUDE_DEPENDS
9+
control_msgs
10+
controller_interface
11+
hardware_interface
12+
parameter_traits
13+
pluginlib
14+
rclcpp
15+
rclcpp_lifecycle
16+
realtime_tools
17+
)
18+
19+
find_package(ament_cmake REQUIRED)
20+
find_package(backward_ros REQUIRED)
21+
foreach(Dependency IN ITEMS ${THIS_PACKAGE_INCLUDE_DEPENDS})
22+
find_package(${Dependency} REQUIRED)
23+
endforeach()
24+
25+
add_library(passthrough_controller SHARED
26+
src/passthrough_controller.cpp
27+
)
28+
target_compile_features(passthrough_controller PUBLIC cxx_std_17)
29+
target_include_directories(passthrough_controller PUBLIC
30+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
31+
$<INSTALL_INTERFACE:include/passthrough_controller>
32+
)
33+
# target_link_libraries(passthrough_controller PUBLIC
34+
# passthrough_controller_parameters
35+
# )
36+
ament_target_dependencies(passthrough_controller PUBLIC ${THIS_PACKAGE_INCLUDE_DEPENDS})
37+
38+
# Causes the visibility macros to use dllexport rather than dllimport,
39+
# which is appropriate when building the dll but not consuming it.
40+
target_compile_definitions(passthrough_controller PRIVATE "passthrough_controller_BUILDING_DLL")
41+
42+
pluginlib_export_plugin_description_file(controller_interface passthrough_controller.xml)
43+
44+
if(BUILD_TESTING)
45+
find_package(ament_cmake_gmock REQUIRED)
46+
find_package(controller_manager REQUIRED)
47+
find_package(ros2_control_test_assets REQUIRED)
48+
49+
ament_add_gmock(test_load_controller test/test_load_controller.cpp)
50+
target_include_directories(test_load_controller PRIVATE include)
51+
ament_target_dependencies(
52+
test_load_controller
53+
controller_manager
54+
ros2_control_test_assets
55+
)
56+
endif()
57+
58+
install(
59+
DIRECTORY include/
60+
DESTINATION include/passthrough_controller
61+
)
62+
63+
install(TARGETS
64+
passthrough_controller
65+
EXPORT export_passthrough_controller
66+
RUNTIME DESTINATION bin
67+
ARCHIVE DESTINATION lib
68+
LIBRARY DESTINATION lib
69+
)
70+
71+
ament_export_targets(export_passthrough_controller HAS_LIBRARY_TARGET)
72+
ament_export_dependencies(${THIS_PACKAGE_INCLUDE_DEPENDS})
73+
ament_package()
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright (c) 2023, PAL Robotics
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef PASSTHROUGH_CONTROLLER__PASSTHROUGH_CONTROLLER_HPP_
16+
#define PASSTHROUGH_CONTROLLER__PASSTHROUGH_CONTROLLER_HPP_
17+
18+
#include <controller_interface/chainable_controller_interface.hpp>
19+
20+
#include "passthrough_controller/visibility_control.h"
21+
22+
namespace passthrough_controller
23+
{
24+
class PassthroughController : public controller_interface::ChainableControllerInterface
25+
{
26+
public:
27+
PASSTHROUGH_CONTROLLER__VISIBILITY_PUBLIC
28+
PassthroughController(){}
29+
30+
PASSTHROUGH_CONTROLLER__VISIBILITY_PUBLIC
31+
controller_interface::CallbackReturn on_init() override
32+
{
33+
return controller_interface::CallbackReturn::SUCCESS;
34+
}
35+
36+
PASSTHROUGH_CONTROLLER__VISIBILITY_PUBLIC
37+
controller_interface::InterfaceConfiguration command_interface_configuration() const override
38+
{
39+
controller_interface::InterfaceConfiguration command_interfaces_config;
40+
return command_interfaces_config;
41+
}
42+
43+
PASSTHROUGH_CONTROLLER__VISIBILITY_PUBLIC
44+
controller_interface::InterfaceConfiguration state_interface_configuration() const override
45+
{
46+
controller_interface::InterfaceConfiguration state_interfaces_config;
47+
return state_interfaces_config;
48+
}
49+
50+
PASSTHROUGH_CONTROLLER__VISIBILITY_PUBLIC
51+
controller_interface::return_type update_reference_from_subscribers(const rclcpp::Time & /* time */, const rclcpp::Duration & /* period */) override
52+
{
53+
return controller_interface::return_type::OK;
54+
}
55+
56+
protected:
57+
std::vector<hardware_interface::CommandInterface> on_export_reference_interfaces() override
58+
{
59+
return std::vector<hardware_interface::CommandInterface>();
60+
}
61+
62+
PASSTHROUGH_CONTROLLER__VISIBILITY_PUBLIC
63+
bool on_set_chained_mode(bool /* chained_mode */) override
64+
{
65+
return true;
66+
}
67+
68+
PASSTHROUGH_CONTROLLER__VISIBILITY_PUBLIC
69+
controller_interface::return_type update_and_write_commands(
70+
const rclcpp::Time & /* time */, const rclcpp::Duration & /* period */) override
71+
{
72+
return controller_interface::return_type::OK;
73+
}
74+
};
75+
76+
} // namespace passthrough_controller
77+
78+
#endif // PASSTHROUGH_CONTROLLER__PASSTHROUGH_CONTROLLER_HPP_
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) 2023, PAL Robotics
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef PASSTHROUGH_CONTROLLER__VISIBILITY_CONTROL_H_
16+
#define PASSTHROUGH_CONTROLLER__VISIBILITY_CONTROL_H_
17+
18+
// This logic was borrowed (then namespaced) from the examples on the gcc wiki:
19+
// https://gcc.gnu.org/wiki/Visibility
20+
21+
#if defined _WIN32 || defined __CYGWIN__
22+
#ifdef __GNUC__
23+
#define PASSTHROUGH_CONTROLLER__VISIBILITY_EXPORT __attribute__((dllexport))
24+
#define PASSTHROUGH_CONTROLLER__VISIBILITY_IMPORT __attribute__((dllimport))
25+
#else
26+
#define PASSTHROUGH_CONTROLLER__VISIBILITY_EXPORT __declspec(dllexport)
27+
#define PASSTHROUGH_CONTROLLER__VISIBILITY_IMPORT __declspec(dllimport)
28+
#endif
29+
#ifdef PASSTHROUGH_CONTROLLER__VISIBILITY_BUILDING_DLL
30+
#define PASSTHROUGH_CONTROLLER__VISIBILITY_PUBLIC PASSTHROUGH_CONTROLLER__VISIBILITY_EXPORT
31+
#else
32+
#define PASSTHROUGH_CONTROLLER__VISIBILITY_PUBLIC PASSTHROUGH_CONTROLLER__VISIBILITY_IMPORT
33+
#endif
34+
#define PASSTHROUGH_CONTROLLER__VISIBILITY_PUBLIC_TYPE PASSTHROUGH_CONTROLLER__VISIBILITY_PUBLIC
35+
#define PASSTHROUGH_CONTROLLER__VISIBILITY_LOCAL
36+
#else
37+
#define PASSTHROUGH_CONTROLLER__VISIBILITY_EXPORT __attribute__((visibility("default")))
38+
#define PASSTHROUGH_CONTROLLER__VISIBILITY_IMPORT
39+
#if __GNUC__ >= 4
40+
#define PASSTHROUGH_CONTROLLER__VISIBILITY_PUBLIC __attribute__((visibility("default")))
41+
#define PASSTHROUGH_CONTROLLER__VISIBILITY_LOCAL __attribute__((visibility("hidden")))
42+
#else
43+
#define PASSTHROUGH_CONTROLLER__VISIBILITY_PUBLIC
44+
#define PASSTHROUGH_CONTROLLER__VISIBILITY_LOCAL
45+
#endif
46+
#define PASSTHROUGH_CONTROLLER__VISIBILITY_PUBLIC_TYPE
47+
#endif
48+
49+
#endif // PASSTHROUGH_CONTROLLER__VISIBILITY_CONTROL_H_

passthrough_controller/package.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>passthrough_controller</name>
5+
<version>0.0.0</version>
6+
<description>A simple demo of chainable controllers. It passes commands through without change.</description>
7+
<maintainer email="TODO@TODO.com">Sai Kishor Kothakota</maintainer>
8+
<maintainer email="zelenak@picknik.ai">Andy Zelenak</maintainer>
9+
<license>Apache-2.0</license>
10+
11+
<buildtool_depend>ament_cmake</buildtool_depend>
12+
13+
<depend>control_msgs</depend>
14+
<depend>controller_interface</depend>
15+
<depend>hardware_interface</depend>
16+
<depend>parameter_traits</depend>
17+
<depend>pluginlib</depend>
18+
<depend>rclcpp</depend>
19+
<depend>rclcpp_lifecycle</depend>
20+
<depend>realtime_tools</depend>
21+
22+
<test_depend>ament_cmake_gmock</test_depend>
23+
<test_depend>controller_manager</test_depend>
24+
<test_depend>ros2_control_test_assets</test_depend>
25+
26+
<export>
27+
<build_type>ament_cmake</build_type>
28+
</export>
29+
</package>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<library path="passthrough_controller">
2+
<class name="passthrough_controller/PassthroughController"
3+
type="passthrough_controller::PassthroughController"
4+
base_class_type="controller_interface::ChainableControllerInterface">
5+
<description>
6+
A simple demo of chainable controllers. It passes commands through without change.
7+
</description>
8+
</class>
9+
</library>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) 2023, PAL Robotics
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "passthrough_controller/passthrough_controller.hpp"
16+
17+
namespace passthrough_controller
18+
{
19+
20+
} // namespace passthrough_controller
21+
22+
#include "pluginlib/class_list_macros.hpp"
23+
24+
PLUGINLIB_EXPORT_CLASS(
25+
passthrough_controller::PassthroughController, controller_interface::ChainableControllerInterface)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) 2023, PAL Robotics
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <gmock/gmock.h>
16+
#include <memory>
17+
18+
#include "controller_manager/controller_manager.hpp"
19+
#include "hardware_interface/resource_manager.hpp"
20+
#include "rclcpp/executor.hpp"
21+
#include "rclcpp/executors/single_threaded_executor.hpp"
22+
#include "rclcpp/utilities.hpp"
23+
#include "ros2_control_test_assets/descriptions.hpp"
24+
25+
TEST(TestLoadPidController, load_controller)
26+
{
27+
rclcpp::init(0, nullptr);
28+
29+
std::shared_ptr<rclcpp::Executor> executor =
30+
std::make_shared<rclcpp::executors::SingleThreadedExecutor>();
31+
32+
controller_manager::ControllerManager cm(
33+
std::make_unique<hardware_interface::ResourceManager>(
34+
ros2_control_test_assets::minimal_robot_urdf),
35+
executor, "test_controller_manager");
36+
37+
ASSERT_NO_THROW(cm.load_controller("test_passthrough_controller", "passthrough_controller/PassthroughController"));
38+
39+
rclcpp::shutdown();
40+
}

0 commit comments

Comments
 (0)