diff --git a/ros_babel_fish/CMakeLists.txt b/ros_babel_fish/CMakeLists.txt index 70d66e7..7705dc3 100644 --- a/ros_babel_fish/CMakeLists.txt +++ b/ros_babel_fish/CMakeLists.txt @@ -23,7 +23,6 @@ find_package(rcpputils REQUIRED) find_package(rosidl_runtime_cpp REQUIRED) find_package(rosidl_typesupport_cpp REQUIRED) find_package(rosidl_typesupport_introspection_cpp REQUIRED) -find_package(ros_babel_fish_test_msgs REQUIRED) ########### ## Build ## @@ -54,18 +53,10 @@ target_include_directories(${PROJECT_NAME} PUBLIC ) ament_target_dependencies(${PROJECT_NAME} ament_index_cpp rclcpp rclcpp_action rcpputils rosidl_runtime_cpp rosidl_typesupport_cpp rosidl_typesupport_introspection_cpp) -add_executable(test_node src/test_node.cpp) -target_link_libraries(test_node ${PROJECT_NAME}) -ament_target_dependencies(test_node rclcpp ros_babel_fish_test_msgs) -target_include_directories(test_node PRIVATE - $ - $ -) # Examples add_executable(any_publisher examples/any_publisher.cpp) target_link_libraries(any_publisher ${PROJECT_NAME}) -ament_target_dependencies(any_publisher rclcpp) target_include_directories(any_publisher PRIVATE $ $ @@ -73,7 +64,6 @@ target_include_directories(any_publisher PRIVATE add_executable(any_subscriber examples/any_subscriber.cpp) target_link_libraries(any_subscriber ${PROJECT_NAME}) -ament_target_dependencies(any_subscriber rclcpp) target_include_directories(any_subscriber PRIVATE $ $ @@ -81,7 +71,6 @@ target_include_directories(any_subscriber PRIVATE add_executable(troll_node examples/troll_node.cpp) target_link_libraries(troll_node ${PROJECT_NAME}) -ament_target_dependencies(troll_node rclcpp) target_include_directories(troll_node PRIVATE $ $ @@ -89,7 +78,6 @@ target_include_directories(troll_node PRIVATE add_executable(service_server examples/service_server.cpp) target_link_libraries(service_server ${PROJECT_NAME}) -ament_target_dependencies(service_server rclcpp) target_include_directories(service_server PRIVATE $ $ @@ -97,22 +85,18 @@ target_include_directories(service_server PRIVATE add_executable(service_client examples/service_client.cpp) target_link_libraries(service_client ${PROJECT_NAME}) -ament_target_dependencies(service_client rclcpp) target_include_directories(service_client PRIVATE $ $ ) -find_package(action_tutorials_interfaces REQUIRED) add_executable(action_client examples/action_client.cpp) target_link_libraries(action_client ${PROJECT_NAME}) -ament_target_dependencies(action_client rclcpp rclcpp_action action_tutorials_interfaces) target_include_directories(action_client PRIVATE $ $ ) - ############# ## Install ## ############# @@ -128,9 +112,9 @@ install( INCLUDES DESTINATION include ) -# Mark test_node and examples for installation +# Mark examples for installation install( - TARGETS test_node action_client any_publisher any_subscriber service_client service_server troll_node + TARGETS action_client any_publisher any_subscriber service_client service_server troll_node DESTINATION lib/${PROJECT_NAME} ) @@ -150,6 +134,7 @@ if (BUILD_TESTING) find_package(action_tutorials_interfaces REQUIRED) find_package(example_interfaces REQUIRED) find_package(geometry_msgs REQUIRED) + find_package(ros_babel_fish_test_msgs REQUIRED) include_directories(include) ament_add_gtest(test_message test/message.cpp) diff --git a/ros_babel_fish/package.xml b/ros_babel_fish/package.xml index 4739a0b..8961d59 100644 --- a/ros_babel_fish/package.xml +++ b/ros_babel_fish/package.xml @@ -19,8 +19,12 @@ rclcpp rclcpp_action rcpputils + rosidl_runtime_cpp + rosidl_typesupport_cpp + rosidl_typesupport_introspection_cpp action_tutorials_interfaces geometry_msgs + ament_cmake_gtest ament_cmake_clang_format ament_cmake_cppcheck ament_lint_auto diff --git a/ros_babel_fish/src/test_node.cpp b/ros_babel_fish/src/test_node.cpp deleted file mode 100644 index 130efd4..0000000 --- a/ros_babel_fish/src/test_node.cpp +++ /dev/null @@ -1,153 +0,0 @@ -// -// Created by stefan on 21.05.21. -// - -#include "test_messages.h" -#include -#include -#include - -using std::placeholders::_1; -using namespace std::chrono_literals; // For 3s etc. -using namespace ros_babel_fish; - -#define DECLARE_PUB( MSG_TYPE, NAME ) rclcpp::Publisher::SharedPtr NAME##_pub_ -#define DEFINE_PUB( MSG_TYPE, NAME ) \ - template<> \ - rclcpp::Publisher::SharedPtr TestNode::getPublisher() \ - { \ - return NAME##_pub_; \ - } \ - template<> \ - std::string TestNode::getTopic() \ - { \ - return "~/" #NAME; \ - } -#define INIT_PUB( MSG_TYPE, NAME ) NAME##_pub_ = this->create_publisher( "~/" #NAME, 1 ) - -class TestNode : public rclcpp::Node -{ -public: - TestNode() : Node( "ros_babel_fish_test" ) - { - INIT_PUB( geometry_msgs::msg::PoseStamped, pose_stamped ); - INIT_PUB( ros_babel_fish_test_msgs::msg::TestMessage, test_message ); - } - - template - bool testMessage() - { - rclcpp::GuardCondition::SharedPtr cond = std::make_shared(); - rclcpp::WaitSet set; - set.add_guard_condition( cond ); - ros_babel_fish::CompoundMessage::SharedPtr message = nullptr; - auto message_sub = fish.create_subscription( - *this, getTopic(), 10, - [&message, &cond]( ros_babel_fish::CompoundMessage::SharedPtr msg ) { - message = msg; - cond->trigger(); - } ); - MessageType test_message; - initMessage( test_message ); - getPublisher()->publish( test_message ); - if ( set.wait( 5s ).kind() != rclcpp::WaitResultKind::Ready ) { - std::cerr << "Timeout while waiting for message!" << std::endl; - return false; - } - return messagesAreEqual( test_message, *message ); - } - -private: - template - typename rclcpp::Publisher::SharedPtr getPublisher(); - - template - std::string getTopic(); - - DECLARE_PUB( geometry_msgs::msg::PoseStamped, pose_stamped ); - DECLARE_PUB( ros_babel_fish_test_msgs::msg::TestMessage, test_message ); - - ros_babel_fish::BabelFish fish; -}; - -// Workaround until GCC supports them in the class again (part of C++17 but should be applied retroactively) -DEFINE_PUB( geometry_msgs::msg::PoseStamped, pose_stamped ) - -DEFINE_PUB( ros_babel_fish_test_msgs::msg::TestMessage, test_message ) - -std::ostream &print( const std::string &txt, size_t width = 60, char fill_character = ' ' ) -{ - std::cout << txt; - if ( txt.length() >= width ) - return std::cout; - std::cout << std::string( width - txt.length(), fill_character ); - return std::cout; -} - -int printResult( bool failed ) -{ - print( "", 80, '-' ); - std::cout << std::endl; - if ( failed ) { - std::cerr << "It seems like the middleware you are using is not supported by ROS2 Babel Fish!" - << std::endl; - std::cerr << "Feel free to make a PR or create an issue on GitHub if this middleware is " - "officially supported by ROS2 Babel Fish." - << std::endl; - } else { - std::cout << "Everything is looking good! ROS2 Babel Fish should work for your setup!" - << std::endl; - } - rclcpp::shutdown(); - return failed ? 1 : 0; -} - -template -bool test( const std::shared_ptr &node, const std::string &type ) -{ - std::cout << std::endl << ">>> Testing " << type << std::endl; - std::shared_future message_result = - std::async( std::launch::async, &TestNode::testMessage, node.get() ); - rclcpp::spin_until_future_complete( node, message_result ); - print( type + "...", 60, '.' ); - if ( !message_result.get() ) { - std::cout << "FAIL" << std::endl; - return false; - } else { - std::cout << ".OK " << std::endl; - } - return true; -} - -int main( int argc, char *argv[] ) -{ - rclcpp::init( argc, argv ); - std::cout << R"( ______ ______ ______ _______ -/\ == \/\ __ \/\ ___\ /\____ \ -\ \ __<\ \ \/\ \ \___ \ \/____/\ \ - \ \_\ \_\ \_____\/\_____\ /\ ____\ - \/_/ /_/\/_____/\/_____/ \ \ \___/_ - \ \______\ - \/______/ - ______ ______ ______ ______ __ ______ __ ______ __ __ -/\ == \/\ __ \/\ == \/\ ___\/\ \ /\ ___/\ \/\ ___\/\ \_\ \ -\ \ __<\ \ __ \ \ __<\ \ __\\ \ \____ \ \ __\ \ \ \___ \ \ __ \ - \ \_____\ \_\ \_\ \_____\ \_____\ \_____\ \ \_\ \ \_\/\_____\ \_\ \_\ - \/_____/\/_/\/_/\/_____/\/_____/\/_____/ \/_/ \/_/\/_____/\/_/\/_/ - by Stefan Fabian --------------------------------------------------------------------------------- -Test Node - Checks if ROS2 Babel Fish works with the middleware you are using. - -)"; - print( "Creating node...", 60, '.' ); - auto node = std::make_shared(); - std::cout << ".OK" << std::endl; - // Test message - if ( !test( node, "geometry_msgs/msg/PoseStamped" ) ) - return printResult( true ); - if ( !test( - node, "ros_babel_fish_test_msgs/msg/TestMessage" ) ) - return printResult( true ); - - return printResult( false ); -}