Skip to content

Commit

Permalink
Merge pull request #232 from husarion/ros2-manager-plugins
Browse files Browse the repository at this point in the history
ROS 2 manager plugins
  • Loading branch information
KmakD authored Mar 26, 2024
2 parents d94d475 + 115ddb7 commit 245429e
Show file tree
Hide file tree
Showing 32 changed files with 2,744 additions and 1 deletion.
4 changes: 4 additions & 0 deletions panther/panther_hardware.repos
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ repositories:
type: git
url: https://github.com/husarion/husarion_controllers
version: main
behaviortree_ros2:
type: git
url: https://github.com/BehaviorTree/BehaviorTree.ROS2
version: ce923e19c12d28f4734a41b1442c123f2d4a41d2
2 changes: 1 addition & 1 deletion panther_lights/test/test_image_animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class TestImageAnimation : public testing::Test
~TestImageAnimation();

protected:
std::string test_image_path = "/tmp/test_image.png";
std::string test_image_path = testing::TempDir() + "/test_image.png";
std::unique_ptr<ImageAnimationWrapper> animation_;
};

Expand Down
130 changes: 130 additions & 0 deletions panther_manager/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
cmake_minimum_required(VERSION 3.8)
project(panther_manager)

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

set(PACKAGE_INCLUDE_DEPENDS
ament_cmake
rclcpp
rclcpp_action
ament_index_cpp
behaviortree_cpp
std_srvs
panther_msgs
libssh
yaml-cpp
behaviortree_ros2
panther_utils)

foreach(Dependency IN ITEMS ${PACKAGE_INCLUDE_DEPENDS})
find_package(${Dependency} REQUIRED)
endforeach()

include_directories(include)

add_library(call_set_bool_service_node SHARED
plugins/action/call_set_bool_service_node.cpp)
list(APPEND plugin_libs call_set_bool_service_node)

add_library(call_trigger_service_node SHARED
plugins/action/call_trigger_service_node.cpp)
list(APPEND plugin_libs call_trigger_service_node)

add_library(call_set_led_animation_service_node SHARED
plugins/action/call_set_led_animation_service_node.cpp)
list(APPEND plugin_libs call_set_led_animation_service_node)

add_library(signal_shutdown_node SHARED plugins/action/signal_shutdown_node.cpp)
list(APPEND plugin_libs signal_shutdown_node)

add_library(shutdown_single_host_node SHARED
plugins/action/shutdown_single_host_node.cpp)
target_link_libraries(shutdown_single_host_node ssh)
list(APPEND plugin_libs shutdown_single_host_node)

add_library(shutdown_hosts_from_file_node SHARED
plugins/action/shutdown_hosts_from_file_node.cpp)
target_link_libraries(shutdown_hosts_from_file_node ssh yaml-cpp)
list(APPEND plugin_libs shutdown_hosts_from_file_node)

add_library(tick_after_timeout_node SHARED
plugins/decorator/tick_after_timeout_node.cpp)
list(APPEND plugin_libs tick_after_timeout_node)

foreach(bt_node ${plugin_libs})
target_compile_definitions(${bt_node} PRIVATE BT_PLUGIN_EXPORT)
ament_target_dependencies(${bt_node} ${PACKAGE_INCLUDE_DEPENDS})
endforeach()

if(BUILD_TESTING)
find_package(ament_cmake_gtest REQUIRED)

add_library(${PROJECT_NAME}_test_plugin_utils
test/plugins/src/plugin_test_utils.cpp)
target_include_directories(${PROJECT_NAME}_test_plugin_utils
PUBLIC test/plugins/include)

target_link_libraries(
${PROJECT_NAME}_test_plugin_utils
call_set_bool_service_node
call_trigger_service_node
call_set_led_animation_service_node
signal_shutdown_node
shutdown_single_host_node
shutdown_hosts_from_file_node
tick_after_timeout_node)

ament_target_dependencies(${PROJECT_NAME}_test_plugin_utils
${PACKAGE_INCLUDE_DEPENDS})

ament_add_gtest(${PROJECT_NAME}_test_call_set_bool_service_node
test/plugins/test_call_set_bool_service_node.cpp)
list(APPEND plugin_tests ${PROJECT_NAME}_test_call_set_bool_service_node)

ament_add_gtest(${PROJECT_NAME}_test_call_trigger_service_node
test/plugins/test_call_trigger_service_node.cpp)
list(APPEND plugin_tests ${PROJECT_NAME}_test_call_trigger_service_node)

ament_add_gtest(${PROJECT_NAME}_test_call_set_led_animation_service_node
test/plugins/test_call_set_led_animation_service_node.cpp)
list(APPEND plugin_tests
${PROJECT_NAME}_test_call_set_led_animation_service_node)

ament_add_gtest(${PROJECT_NAME}_test_signal_shutdown_node
test/plugins/test_signal_shutdown_node.cpp)
list(APPEND plugin_tests ${PROJECT_NAME}_test_signal_shutdown_node)

ament_add_gtest(${PROJECT_NAME}_test_shutdown_single_host_node
test/plugins/test_shutdown_single_host_node.cpp)
list(APPEND plugin_tests ${PROJECT_NAME}_test_shutdown_single_host_node)

ament_add_gtest(${PROJECT_NAME}_test_shutdown_hosts_from_file_node
test/plugins/test_shutdown_hosts_from_file_node.cpp)
list(APPEND plugin_tests ${PROJECT_NAME}_test_shutdown_hosts_from_file_node)

ament_add_gtest(${PROJECT_NAME}_test_tick_after_timeout_node
test/plugins/test_tick_after_timeout_node.cpp)
list(APPEND plugin_tests ${PROJECT_NAME}_test_tick_after_timeout_node)

ament_add_gtest(${PROJECT_NAME}_test_shutdown_host
test/plugins/test_shutdown_host.cpp)
list(APPEND plugin_tests ${PROJECT_NAME}_test_shutdown_host)

ament_add_gtest(${PROJECT_NAME}_test_shutdown_hosts_node
test/plugins/test_shutdown_hosts_node.cpp)
list(APPEND plugin_tests ${PROJECT_NAME}_test_shutdown_hosts_node)

foreach(bt_node_test ${plugin_tests})
target_link_libraries(${bt_node_test} ${PROJECT_NAME}_test_plugin_utils)
ament_target_dependencies(${bt_node_test} ${PACKAGE_INCLUDE_DEPENDS})
endforeach()
endif()

install(TARGETS DESTINATION lib/${PROJECT_NAME})

ament_export_include_directories(include)
ament_export_dependencies(${PACKAGE_INCLUDE_DEPENDS})

ament_package()
7 changes: 7 additions & 0 deletions panther_manager/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Testing

For testing you have to copy authenticate ssh key on the localhost:

```bash
ssh-copy-id -f husarion@localhost
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2024 Husarion sp. z o.o.
//
// 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 PANTHER_MANAGER_CALL_SET_BOOL_SERVICE_NODE_HPP_
#define PANTHER_MANAGER_CALL_SET_BOOL_SERVICE_NODE_HPP_

#include <string>

#include <behaviortree_ros2/bt_service_node.hpp>
#include <rclcpp/rclcpp.hpp>

#include <std_srvs/srv/set_bool.hpp>

namespace panther_manager
{

class CallSetBoolService : public BT::RosServiceNode<std_srvs::srv::SetBool>
{
public:
CallSetBoolService(
const std::string & name, const BT::NodeConfig & conf, const BT::RosNodeParams & params)
: BT::RosServiceNode<std_srvs::srv::SetBool>(name, conf, params)
{
}

static BT::PortsList providedPorts()
{
return providedBasicPorts({BT::InputPort<bool>("data", "true / false value")});
}

virtual bool setRequest(typename Request::SharedPtr & request) override;
virtual BT::NodeStatus onResponseReceived(const typename Response::SharedPtr & response) override;
};

} // namespace panther_manager

#endif // PANTHER_MANAGER_CALL_SET_BOOL_SERVICE_NODE_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2024 Husarion sp. z o.o.
//
// 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 PANTHER_MANAGER_CALL_SET_LED_ANIMATION_SERVICE_NODE_HPP_
#define PANTHER_MANAGER_CALL_SET_LED_ANIMATION_SERVICE_NODE_HPP_

#include <string>

#include <behaviortree_ros2/bt_service_node.hpp>
#include <rclcpp/rclcpp.hpp>

#include <panther_msgs/srv/set_led_animation.hpp>

namespace panther_manager
{

class CallSetLedAnimationService : public BT::RosServiceNode<panther_msgs::srv::SetLEDAnimation>
{
public:
CallSetLedAnimationService(
const std::string & name, const BT::NodeConfig & conf, const BT::RosNodeParams & params)
: BT::RosServiceNode<panther_msgs::srv::SetLEDAnimation>(name, conf, params)
{
}

static BT::PortsList providedPorts()
{
return providedBasicPorts({
BT::InputPort<unsigned>("id", "animation ID"),
BT::InputPort<std::string>("param", "optional parameter"),
BT::InputPort<bool>("repeating", "indicates if animation should repeat"),
});
}

virtual bool setRequest(typename Request::SharedPtr & request) override;
virtual BT::NodeStatus onResponseReceived(const typename Response::SharedPtr & response) override;
};

} // namespace panther_manager

#endif // PANTHER_MANAGER_CALL_SET_LED_ANIMATION_SERVICE_NODE_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2024 Husarion sp. z o.o.
//
// 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 PANTHER_MANAGER_CALL_TRIGGER_SERVICE_NODE_HPP_
#define PANTHER_MANAGER_CALL_TRIGGER_SERVICE_NODE_HPP_

#include <string>

#include <behaviortree_ros2/bt_service_node.hpp>
#include <rclcpp/rclcpp.hpp>

#include <std_srvs/srv/trigger.hpp>

namespace panther_manager
{

class CallTriggerService : public BT::RosServiceNode<std_srvs::srv::Trigger>
{
public:
CallTriggerService(
const std::string & name, const BT::NodeConfig & conf, const BT::RosNodeParams & params)
: BT::RosServiceNode<std_srvs::srv::Trigger>(name, conf, params)
{
}

static BT::PortsList providedPorts() { return providedBasicPorts({}); }

virtual bool setRequest(typename Request::SharedPtr & /*request*/) override;
virtual BT::NodeStatus onResponseReceived(const typename Response::SharedPtr & response) override;
};

} // namespace panther_manager

#endif // PANTHER_MANAGER_CALL_SET_BOOL_SERVICE_NODE_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2024 Husarion sp. z o.o.
//
// 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 PANTHER_MANAGER_SHUTDOWN_HOST_FROM_FILE_NODE_HPP_
#define PANTHER_MANAGER_SHUTDOWN_HOST_FROM_FILE_NODE_HPP_

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

#include <behaviortree_cpp/basic_types.h>
#include <yaml-cpp/yaml.h>

#include <panther_manager/plugins/shutdown_host.hpp>
#include <panther_manager/plugins/shutdown_hosts_node.hpp>
#include <panther_utils/yaml_utils.hpp>

namespace panther_manager
{

class ShutdownHostsFromFile : public ShutdownHosts
{
public:
ShutdownHostsFromFile(const std::string & name, const BT::NodeConfig & conf)
: ShutdownHosts(name, conf)
{
}

static BT::PortsList providedPorts()
{
return {
BT::InputPort<std::string>(
"shutdown_hosts_file", "global path to YAML file with hosts to shutdown"),
};
}

private:
bool UpdateHosts(std::vector<std::shared_ptr<ShutdownHost>> & hosts) override;
};

} // namespace panther_manager

#endif // PANTHER_MANAGER_SHUTDOWN_HOST_FROM_FILE_NODE_HPP_
Loading

0 comments on commit 245429e

Please sign in to comment.