From a7af591957efcd375df92a318752fa4597435d71 Mon Sep 17 00:00:00 2001 From: Kevin Allen Date: Tue, 17 Jul 2018 14:12:09 -0700 Subject: [PATCH 1/3] Create base Node class for gazebo plugins with ROS2 --- gazebo_ros/CMakeLists.txt | 145 ++++--------------- gazebo_ros/include/gazebo_ros/executor.hpp | 52 +++++++ gazebo_ros/include/gazebo_ros/node.hpp | 153 +++++++++++++++++++++ gazebo_ros/package.xml | 30 ++-- gazebo_ros/src/executor.cpp | 46 +++++++ gazebo_ros/src/node.cpp | 51 +++++++ 6 files changed, 337 insertions(+), 140 deletions(-) create mode 100644 gazebo_ros/include/gazebo_ros/executor.hpp create mode 100644 gazebo_ros/include/gazebo_ros/node.hpp create mode 100644 gazebo_ros/src/executor.cpp create mode 100644 gazebo_ros/src/node.cpp diff --git a/gazebo_ros/CMakeLists.txt b/gazebo_ros/CMakeLists.txt index 8494db6a9..8508a9b1d 100644 --- a/gazebo_ros/CMakeLists.txt +++ b/gazebo_ros/CMakeLists.txt @@ -1,132 +1,37 @@ -cmake_minimum_required(VERSION 3.6.3) +cmake_minimum_required(VERSION 3.5) project(gazebo_ros) -find_package(catkin REQUIRED COMPONENTS - gazebo_dev - cmake_modules - roslib - roscpp - geometry_msgs - std_srvs - tf - rosgraph_msgs - dynamic_reconfigure - std_msgs - gazebo_msgs -) -# Through transitive dependencies in the packages above, gazebo_ros depends -# on Simbody. There is a bug in the Ubuntu Artful (17.10) version of the -# Simbody package where it includes /usr/lib/libblas.so and -# /usr/lib/liblapack.so in the CMake list of libraries even though neither of -# those two paths exist (they both really live in /usr/lib/-linux-gnu). -# We remove these two during build-time on artful below; this works because -# they both will get resolved to the proper paths during runtime linking. -find_program(LSB_RELEASE_EXEC lsb_release) -if(NOT LSB_RELEASE_EXEC STREQUAL "LSB_RELEASE_EXEC-NOTFOUND") - execute_process(COMMAND ${LSB_RELEASE_EXEC} -cs - OUTPUT_VARIABLE OS_CODENAME - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - if(OS_CODENAME STREQUAL "artful") - list(FILTER catkin_LIBRARIES EXCLUDE REGEX "/usr/lib/libblas.so") - list(FILTER catkin_LIBRARIES EXCLUDE REGEX "/usr/lib/liblapack.so") - endif() +# Default to C++14 +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 14) endif() - -include (FindPkgConfig) -if (PKG_CONFIG_FOUND) - pkg_check_modules(XML libxml-2.0) -else() - message(FATAL_ERROR "pkg-config is required; please install it") +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + # we dont use add_compile_options with pedantic in message packages + # because the Python C extensions dont comply with it + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic") endif() -find_package(Boost REQUIRED COMPONENTS thread) - -find_package(TinyXML REQUIRED) - -catkin_python_setup() - -generate_dynamic_reconfigure_options(cfg/Physics.cfg) - -catkin_package( - LIBRARIES - gazebo_ros_api_plugin - gazebo_ros_paths_plugin - - CATKIN_DEPENDS - roslib - roscpp - geometry_msgs - std_srvs - tf - rosgraph_msgs - dynamic_reconfigure - std_msgs - gazebo_msgs - - DEPENDS - TinyXML -) - -include_directories( - include - ${Boost_INCLUDE_DIRS} - ${catkin_INCLUDE_DIRS} - ${TinyXML_INCLUDE_DIRS}) - -link_directories(${catkin_LIBRARY_DIRS}) - -set(cxx_flags) -foreach (item ${GAZEBO_CFLAGS}) - set(cxx_flags "${cxx_flags} ${item}") -endforeach () - -set(ld_flags) -foreach (item ${GAZEBO_LDFLAGS}) - set(ld_flags "${ld_flags} ${item}") -endforeach () - -## Plugins -add_library(gazebo_ros_api_plugin src/gazebo_ros_api_plugin.cpp) -add_dependencies(gazebo_ros_api_plugin ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) -set_target_properties(gazebo_ros_api_plugin PROPERTIES LINK_FLAGS "${ld_flags}") -set_target_properties(gazebo_ros_api_plugin PROPERTIES COMPILE_FLAGS "${cxx_flags}") -target_link_libraries(gazebo_ros_api_plugin ${catkin_LIBRARIES} ${Boost_LIBRARIES} ${TinyXML_LIBRARIES}) - -add_library(gazebo_ros_paths_plugin src/gazebo_ros_paths_plugin.cpp) -add_dependencies(gazebo_ros_paths_plugin ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) -set_target_properties(gazebo_ros_paths_plugin PROPERTIES COMPILE_FLAGS "${cxx_flags}") -set_target_properties(gazebo_ros_paths_plugin PROPERTIES LINK_FLAGS "${ld_flags}") -target_link_libraries(gazebo_ros_paths_plugin ${catkin_LIBRARIES} ${Boost_LIBRARIES}) +find_package(ament_cmake REQUIRED) +find_package(rclcpp REQUIRED) +find_package(gazebo_dev REQUIRED) -## Tests +include_directories(include) -add_subdirectory(test) +add_library(gazebo_ros_node SHARED src/node.cpp src/executor.cpp) +ament_target_dependencies(gazebo_ros_node rclcpp gazebo_dev) -# Install Gazebo System Plugins -install(TARGETS gazebo_ros_api_plugin gazebo_ros_paths_plugin - LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} - ) +ament_export_include_directories(include) +ament_export_libraries(gazebo_ros_node) +ament_export_dependencies(rclcpp) +ament_export_dependencies(gazebo_dev) -# Install Gazebo Scripts -install(PROGRAMS scripts/gazebo - scripts/debug - scripts/gzclient - scripts/gzserver - scripts/gdbrun - scripts/perf - scripts/libcommon.sh - DESTINATION - ${CATKIN_PACKAGE_BIN_DESTINATION} -) +ament_package() -# This one is a Python program, not a shell script, so install it separately -catkin_install_python(PROGRAMS scripts/spawn_model - DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} -) +install(DIRECTORY include/ + DESTINATION include) -# Install Gazebo launch files -install(DIRECTORY launch/ - DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}/launch -) +install(TARGETS gazebo_ros_node + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin) diff --git a/gazebo_ros/include/gazebo_ros/executor.hpp b/gazebo_ros/include/gazebo_ros/executor.hpp new file mode 100644 index 000000000..750ec240e --- /dev/null +++ b/gazebo_ros/include/gazebo_ros/executor.hpp @@ -0,0 +1,52 @@ +// Copyright 2018 Open Source Robotics Foundation, Inc. +// +// 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 GAZEBO_ROS_EXECUTOR_HPP +#define GAZEBO_ROS_EXECUTOR_HPP + +#include +#include + +namespace gazebo_ros +{ + +/// Executor run in a seperate thread to handle events from all #gazebo_ros::Node instances +/** + * \class Executor executor.hpp + */ +class Executor : public rclcpp::executors::MultiThreadedExecutor +{ +public: + /// Create an instance and start the internal thread + Executor(); + + /// Stops the internal exeuctor and joins with the internal thread + virtual ~Executor(); + +private: + /// Thread where the exeuctor spins until destruction + std::thread spin_thread_; + + /// Spin executor, called in #spin_thread_ + void run(); + + /// Shutdown ROS, called when gazebo sigint handle arrives so ROS is shutdown cleanly + void shutdown(); + + /// Connection to gazebo sigint event + gazebo::event::ConnectionPtr sigint_handle_; +}; + +} // namespace gazebo_ros +#endif diff --git a/gazebo_ros/include/gazebo_ros/node.hpp b/gazebo_ros/include/gazebo_ros/node.hpp new file mode 100644 index 000000000..7693b222a --- /dev/null +++ b/gazebo_ros/include/gazebo_ros/node.hpp @@ -0,0 +1,153 @@ +// Copyright 2018 Open Source Robotics Foundation, Inc. +// +// 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 GAZEBO_ROS_NODE_HPP +#define GAZEBO_ROS_NODE_HPP + +#include +#include +#include + +#include +#include + +#include + +namespace gazebo_ros +{ + +/// ROS Node for gazebo plugins +/** + * \class Node node.hpp + * Wrapper around an rclcpp::Node which ensures all instances share an exeuctor. + * \include gazebo_ros/node.hpp + */ +class Node : public rclcpp::Node +{ +public: + /// Exception thrown when a #Create is called for a Node before #InitROS has ever been called + class NotInitializedException : public std::runtime_error + { + public: + NotInitializedException(); + }; + + /// Shared pointer to a #gazebo_ros::Node + typedef std::shared_ptr SharedPtr; + + /// Destructor + virtual ~Node(); + + /// Create a #gazebo_ros::Node and add it to the global #gazebo_ros::Executor. + /** + * \note Must NOT called until #InitROS has been called + * \param[in] node_name Name for the new node to create + * \return A shared pointer to a new #gazebo_ros::Node + */ + static SharedPtr Create(const std::string& node_name); + + /// Create a #gazebo_ros::Node and add it to the global #gazebo_ros::Executor. + /** + * \todo Implement + * \note Must NOT called until #InitROS has been called + * \details Sets namespace, remappings, and parameters from SDF. + * SDF is in the form: + * \code{.xml} + * + * + * + * + * + * + * + * + * my_topic:=new_topic + * __name:=super_cool_node + * + * + * + * 55 + * True + * + * + * \endcode + * \param[in] node_name Name of node to create + * \param[in] _sdf An SDF element which either is a element or contains a element + * \return A shared pointer to a new #gazebo_ros::Node + */ + static SharedPtr Create(const std::string& node_name, sdf::ElementPtr _sdf); + + /// Create a #gazebo_ros::Node and add it to the global #gazebo_ros::Executor. + /** + * \note Must NOT called until #InitROS has been called + * \details Forwards arguments to the contructor for rclcpp::Node + * \param[in] args List of arguments to pass to rclcpp::Node + * \return A shared pointer to a new #gazebo_ros::Node + */ + template + static SharedPtr Create(Args && ...args); + + /// Initialize ROS with the command line arguments. + /** + * \note Must be called ONCE before any #gazebo_ros::Node instances are created. Subsequent calls are ignored. + * \param[in] argc Number of arguments + * \param[in] argv Vector of c-strings of length \a argc + */ + static void InitROS(int argc, char** argv); + +private: + /// Inherit constructor + using rclcpp::Node::Node; + + /// Points to #static_executor_, so that when all #gazebo_ros::Node instances are destroyed, the executor thread is too + std::shared_ptr executor_; + + /// true if #InitROS has been called and future calls will be ignored + static std::atomic_bool initialized_; + + /// Locks #initialized_ and #executor_ + static std::mutex lock_; + + /// Points to an #gazebo_ros::Executor shared between all #gazebo_ros::Node instances + static std::weak_ptr static_executor_; +}; + +template +Node::SharedPtr Node::Create(Args && ...args) +{ + // Throw exception is Node is created before ROS is initialized + if (!initialized_) + throw NotInitializedException(); + + // Contruct Node by forwarding arguments + Node::SharedPtr node = std::make_shared(std::forward(args)...); + + std::lock_guard l(lock_); + // Store shared pointer to static executor in this object + node->executor_ = static_executor_.lock(); + // If executor has not been contructed yet, do so now + if (!node->executor_) + { + node->executor_ = std::make_shared(); + static_executor_ = node->executor_; + } + + // Add new node to the exeuctor so its callbacks are called + node->executor_->add_node(node); + return node; +} + + +} // namespace gazebo_ros +#endif diff --git a/gazebo_ros/package.xml b/gazebo_ros/package.xml index 471c0b03d..b05bfb82c 100644 --- a/gazebo_ros/package.xml +++ b/gazebo_ros/package.xml @@ -1,10 +1,10 @@ - + + gazebo_ros 2.8.4 - Provides ROS plugins that offer message and service publishers for interfacing with Gazebo through ROS. - Formally simulator_gazebo/gazebo + Utilities to interface with Gazebo through ROS. Jose Luis Rivero @@ -19,25 +19,15 @@ Nate Koenig Dave Coleman - catkin + ament_cmake - cmake_modules + rclcpp gazebo_dev - + + rclcpp gazebo_dev - gazebo_msgs - roslib - roscpp - tf - std_srvs - rosgraph_msgs - dynamic_reconfigure - std_msgs - geometry_msgs - tinyxml - python-argparse + + ament_cmake + diff --git a/gazebo_ros/src/executor.cpp b/gazebo_ros/src/executor.cpp new file mode 100644 index 000000000..27efecac0 --- /dev/null +++ b/gazebo_ros/src/executor.cpp @@ -0,0 +1,46 @@ +// Copyright 2018 Open Source Robotics Foundation, Inc. +// +// 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. + +#include + +#include + +namespace gazebo_ros +{ + +Executor::Executor() : + spin_thread_(std::bind(&Executor::run, this)) +{ + sigint_handle_ = gazebo::event::Events::ConnectSigInt(std::bind(&Executor::shutdown, this)); +} + +Executor::~Executor() +{ + // If ros was not already shutdown by SIGINT handler, do it now + if (rclcpp::ok()) + rclcpp::shutdown(); + spin_thread_.join(); +} + +void Executor::run() +{ + spin(); +} + +void Executor::shutdown() +{ + rclcpp::shutdown(); +} + +} // namespace gazebo_ros diff --git a/gazebo_ros/src/node.cpp b/gazebo_ros/src/node.cpp new file mode 100644 index 000000000..d62f0cb93 --- /dev/null +++ b/gazebo_ros/src/node.cpp @@ -0,0 +1,51 @@ +// Copyright 2018 Open Source Robotics Foundation, Inc. +// +// 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. + +#include + +namespace gazebo_ros +{ + +std::weak_ptr Node::static_executor_; +std::mutex Node::lock_; +std::atomic_bool Node::initialized_(false); + +Node::NotInitializedException::NotInitializedException() : + std::runtime_error("Called LoadNode before InitROS. Be sure to load the ros_api plugin first") +{ +} + +Node::~Node() +{ +} + +void Node::InitROS(int argc, char** argv) +{ + std::lock_guard l(lock_); + if (initialized_) + { + RCLCPP_WARN(rclcpp::get_logger("gazebo_ros_node"), "Called Node::InitROS twice, ignoring second call."); + return; + } + + rclcpp::init(argc, argv); + initialized_ = true; +} + +Node::SharedPtr Node::Create(const std::string& node_name) +{ + return Create(node_name); +} + +} // namespace gazebo_ros From 3772a83b4f1a4aea60f5db4a1b856252ae042809 Mon Sep 17 00:00:00 2001 From: Kevin Allen Date: Tue, 17 Jul 2018 14:14:23 -0700 Subject: [PATCH 2/3] Move gazebo_plugins files for porting --- {.ros1_unported/gazebo_plugins => gazebo_plugins}/CHANGELOG.rst | 0 {.ros1_unported/gazebo_plugins => gazebo_plugins}/CMakeLists.txt | 0 {.ros1_unported/gazebo_plugins => gazebo_plugins}/package.xml | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename {.ros1_unported/gazebo_plugins => gazebo_plugins}/CHANGELOG.rst (100%) rename {.ros1_unported/gazebo_plugins => gazebo_plugins}/CMakeLists.txt (100%) rename {.ros1_unported/gazebo_plugins => gazebo_plugins}/package.xml (100%) diff --git a/.ros1_unported/gazebo_plugins/CHANGELOG.rst b/gazebo_plugins/CHANGELOG.rst similarity index 100% rename from .ros1_unported/gazebo_plugins/CHANGELOG.rst rename to gazebo_plugins/CHANGELOG.rst diff --git a/.ros1_unported/gazebo_plugins/CMakeLists.txt b/gazebo_plugins/CMakeLists.txt similarity index 100% rename from .ros1_unported/gazebo_plugins/CMakeLists.txt rename to gazebo_plugins/CMakeLists.txt diff --git a/.ros1_unported/gazebo_plugins/package.xml b/gazebo_plugins/package.xml similarity index 100% rename from .ros1_unported/gazebo_plugins/package.xml rename to gazebo_plugins/package.xml From 83eb4fc37b65f2f0747b5416d1dd8455d77ba88b Mon Sep 17 00:00:00 2001 From: Kevin Allen Date: Tue, 17 Jul 2018 14:15:45 -0700 Subject: [PATCH 3/3] Add simple gazebo_ros plugin example --- gazebo_plugins/CMakeLists.txt | 439 +----------------- .../include/gazebo_plugins/node_example.hpp | 40 ++ gazebo_plugins/package.xml | 48 +- gazebo_plugins/src/node_example.cpp | 51 ++ 4 files changed, 123 insertions(+), 455 deletions(-) create mode 100644 gazebo_plugins/include/gazebo_plugins/node_example.hpp create mode 100644 gazebo_plugins/src/node_example.cpp diff --git a/gazebo_plugins/CMakeLists.txt b/gazebo_plugins/CMakeLists.txt index 475ad22a0..1142e44d4 100644 --- a/gazebo_plugins/CMakeLists.txt +++ b/gazebo_plugins/CMakeLists.txt @@ -1,430 +1,31 @@ -cmake_minimum_required(VERSION 3.6.3) +cmake_minimum_required(VERSION 3.5) project(gazebo_plugins) -option(ENABLE_DISPLAY_TESTS "Enable the building of tests that requires a display" OFF) - -find_package(catkin REQUIRED COMPONENTS - gazebo_dev - message_generation - gazebo_msgs - roscpp - rospy - nodelet - angles - std_srvs - geometry_msgs - sensor_msgs - nav_msgs - urdf - tf - tf2_ros - dynamic_reconfigure - rosgraph_msgs - trajectory_msgs - image_transport - rosconsole - cv_bridge - polled_camera - diagnostic_updater - camera_info_manager - std_msgs -) - -# Through transitive dependencies in the packages above, gazebo_plugins depends -# on Simbody. There is a bug in the Ubuntu Artful (17.10) version of the -# Simbody package where it includes /usr/lib/libblas.so and -# /usr/lib/liblapack.so in the CMake list of libraries even though neither of -# those two paths exist (they both really live in /usr/lib/-linux-gnu). -# We remove these two during build-time on artful below; this works because -# they both will get resolved to the proper paths during runtime linking. -find_program(LSB_RELEASE_EXEC lsb_release) -if(NOT LSB_RELEASE_EXEC STREQUAL "LSB_RELEASE_EXEC-NOTFOUND") - execute_process(COMMAND ${LSB_RELEASE_EXEC} -cs - OUTPUT_VARIABLE OS_CODENAME - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - if(OS_CODENAME STREQUAL "artful") - list(FILTER catkin_LIBRARIES EXCLUDE REGEX "/usr/lib/libblas.so") - list(FILTER catkin_LIBRARIES EXCLUDE REGEX "/usr/lib/liblapack.so") - list(FILTER GAZEBO_LIBRARIES EXCLUDE REGEX "/usr/lib/libblas.so") - list(FILTER GAZEBO_LIBRARIES EXCLUDE REGEX "/usr/lib/liblapack.so") - endif() +# Default to C++14 +if(NOT CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 14) endif() - -include (FindPkgConfig) -if (PKG_CONFIG_FOUND) - pkg_check_modules(XML libxml-2.0) - pkg_check_modules(OGRE OGRE) - pkg_check_modules(OGRE-Terrain OGRE-Terrain) - pkg_check_modules(OGRE-Paging OGRE-Paging) -else() - message(FATAL_ERROR "pkg-config is required; please install it") -endif() - -find_package(Boost REQUIRED COMPONENTS thread) - -execute_process(COMMAND - pkg-config --variable=plugindir OGRE - OUTPUT_VARIABLE OGRE_PLUGIN_PATH - OUTPUT_STRIP_TRAILING_WHITESPACE -) - -catkin_python_setup() - -generate_dynamic_reconfigure_options( - cfg/CameraSynchronizer.cfg - cfg/GazeboRosCamera.cfg - cfg/GazeboRosOpenniKinect.cfg - cfg/Hokuyo.cfg -) - -include_directories(include - ${Boost_INCLUDE_DIRS} - ${catkin_INCLUDE_DIRS} - ${OGRE_INCLUDE_DIRS} - ${OGRE-Terrain_INCLUDE_DIRS} - ${OGRE-Paging_INCLUDE_DIRS} -) - -link_directories( - ${catkin_LIBRARY_DIRS} - ${OGRE_LIBRARY_DIRS} - ${OGRE-Terrain_LIBRARY_DIRS} - ${OGRE-Paging_LIBRARY_DIRS} -) - -if (NOT GAZEBO_VERSION VERSION_LESS 6.0) - catkin_package( INCLUDE_DIRS include LIBRARIES gazebo_ros_elevator) -endif() - -if (NOT GAZEBO_VERSION VERSION_LESS 7.3) - catkin_package(INCLUDE_DIRS include LIBRARIES gazebo_ros_harness) -endif() - -catkin_package( - INCLUDE_DIRS include - LIBRARIES - vision_reconfigure - gazebo_ros_utils - gazebo_ros_camera_utils - gazebo_ros_camera - gazebo_ros_triggered_camera - gazebo_ros_multicamera - gazebo_ros_triggered_multicamera - gazebo_ros_depth_camera - gazebo_ros_openni_kinect - gazebo_ros_gpu_laser - gazebo_ros_laser - gazebo_ros_block_laser - gazebo_ros_p3d - gazebo_ros_imu - gazebo_ros_imu_sensor - gazebo_ros_f3d - gazebo_ros_ft_sensor - gazebo_ros_bumper - gazebo_ros_template - gazebo_ros_projector - gazebo_ros_prosilica - gazebo_ros_force - gazebo_ros_joint_state_publisher - gazebo_ros_joint_pose_trajectory - gazebo_ros_diff_drive - gazebo_ros_tricycle_drive - gazebo_ros_skid_steer_drive - gazebo_ros_video - gazebo_ros_planar_move - gazebo_ros_range - gazebo_ros_vacuum_gripper - - CATKIN_DEPENDS - message_runtime - gazebo_msgs - roscpp - rospy - nodelet - angles - std_srvs - geometry_msgs - sensor_msgs - nav_msgs - urdf - tf - tf2_ros - dynamic_reconfigure - rosgraph_msgs - trajectory_msgs - image_transport - rosconsole - camera_info_manager - std_msgs -) -add_dependencies(${PROJECT_NAME}_gencfg ${catkin_EXPORTED_TARGETS}) - -## Executables -add_executable(hokuyo_node src/hokuyo_node.cpp) -add_dependencies(hokuyo_node ${PROJECT_NAME}_gencfg) -target_link_libraries(hokuyo_node - ${catkin_LIBRARIES} -) - -add_library(gazebo_ros_utils src/gazebo_ros_utils.cpp) -target_link_libraries(gazebo_ros_utils ${catkin_LIBRARIES} ${Boost_LIBRARIES}) - -add_library(vision_reconfigure src/vision_reconfigure.cpp) -add_dependencies(vision_reconfigure ${PROJECT_NAME}_gencfg) -target_link_libraries(vision_reconfigure ${catkin_LIBRARIES}) - -add_executable(camera_synchronizer src/camera_synchronizer.cpp) -add_dependencies(camera_synchronizer ${PROJECT_NAME}_gencfg) -target_link_libraries(camera_synchronizer vision_reconfigure ${catkin_LIBRARIES}) - -add_executable(pub_joint_trajectory_test test/pub_joint_trajectory_test.cpp) -target_link_libraries(pub_joint_trajectory_test ${catkin_LIBRARIES} ${Boost_LIBRARIES}) -add_dependencies(pub_joint_trajectory_test ${catkin_EXPORTED_TARGETS}) # don't build until gazebo_msgs is done - -add_definitions(-fPIC) # what is this for? - -## Plugins -add_library(gazebo_ros_camera_utils src/gazebo_ros_camera_utils.cpp) -add_dependencies(gazebo_ros_camera_utils ${PROJECT_NAME}_gencfg) -target_link_libraries(gazebo_ros_camera_utils ${catkin_LIBRARIES} ${Boost_LIBRARIES}) - -add_library(MultiCameraPlugin src/MultiCameraPlugin.cpp) -target_link_libraries(MultiCameraPlugin ${catkin_LIBRARIES} ${Boost_LIBRARIES}) - -add_library(gazebo_ros_camera src/gazebo_ros_camera.cpp) -add_dependencies(gazebo_ros_camera ${PROJECT_NAME}_gencfg) -target_link_libraries(gazebo_ros_camera gazebo_ros_camera_utils CameraPlugin ${catkin_LIBRARIES}) - -add_library(gazebo_ros_triggered_camera src/gazebo_ros_triggered_camera.cpp) -add_dependencies(gazebo_ros_triggered_camera ${PROJECT_NAME}_gencfg) -target_link_libraries(gazebo_ros_triggered_camera gazebo_ros_camera_utils ${GAZEBO_LIBRARIES} CameraPlugin ${catkin_LIBRARIES}) - - -if (NOT GAZEBO_VERSION VERSION_LESS 6.0) - add_library(gazebo_ros_elevator src/gazebo_ros_elevator.cpp) - add_dependencies(gazebo_ros_elevator ${PROJECT_NAME}_gencfg) - target_link_libraries(gazebo_ros_elevator ElevatorPlugin ${catkin_LIBRARIES}) -endif() - -add_library(gazebo_ros_multicamera src/gazebo_ros_multicamera.cpp) -add_dependencies(gazebo_ros_multicamera ${PROJECT_NAME}_gencfg) -target_link_libraries(gazebo_ros_multicamera gazebo_ros_camera_utils MultiCameraPlugin ${catkin_LIBRARIES}) - -add_library(gazebo_ros_triggered_multicamera src/gazebo_ros_triggered_multicamera.cpp) -add_dependencies(gazebo_ros_triggered_multicamera ${PROJECT_NAME}_gencfg) -target_link_libraries(gazebo_ros_triggered_multicamera gazebo_ros_camera_utils gazebo_ros_triggered_camera ${GAZEBO_LIBRARIES} MultiCameraPlugin ${catkin_LIBRARIES}) - -add_library(gazebo_ros_depth_camera src/gazebo_ros_depth_camera.cpp) -add_dependencies(gazebo_ros_depth_camera ${PROJECT_NAME}_gencfg) -target_link_libraries(gazebo_ros_depth_camera gazebo_ros_camera_utils DepthCameraPlugin ${catkin_LIBRARIES}) - -add_library(gazebo_ros_openni_kinect src/gazebo_ros_openni_kinect.cpp) -add_dependencies(gazebo_ros_openni_kinect ${PROJECT_NAME}_gencfg) -target_link_libraries(gazebo_ros_openni_kinect gazebo_ros_camera_utils DepthCameraPlugin ${catkin_LIBRARIES}) - -add_library(gazebo_ros_gpu_laser src/gazebo_ros_gpu_laser.cpp) -target_link_libraries(gazebo_ros_gpu_laser ${catkin_LIBRARIES} GpuRayPlugin) - -if (NOT GAZEBO_VERSION VERSION_LESS 7.3) - add_library(gazebo_ros_harness src/gazebo_ros_harness.cpp) - add_dependencies(gazebo_ros_harness ${catkin_EXPORTED_TARGETS}) - target_link_libraries(gazebo_ros_harness - ${Boost_LIBRARIES} HarnessPlugin ${catkin_LIBRARIES}) +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + # we dont use add_compile_options with pedantic in message packages + # because the Python C extensions dont comply with it + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic") endif() -add_library(gazebo_ros_laser src/gazebo_ros_laser.cpp) -target_link_libraries(gazebo_ros_laser RayPlugin ${catkin_LIBRARIES}) - -add_library(gazebo_ros_block_laser src/gazebo_ros_block_laser.cpp) -target_link_libraries(gazebo_ros_block_laser RayPlugin ${catkin_LIBRARIES}) - -add_library(gazebo_ros_p3d src/gazebo_ros_p3d.cpp) -target_link_libraries(gazebo_ros_p3d ${catkin_LIBRARIES} ${Boost_LIBRARIES}) - -add_library(gazebo_ros_imu src/gazebo_ros_imu.cpp) -target_link_libraries(gazebo_ros_imu ${catkin_LIBRARIES} ${Boost_LIBRARIES}) - -add_library(gazebo_ros_imu_sensor src/gazebo_ros_imu_sensor.cpp) -target_link_libraries(gazebo_ros_imu_sensor ${GAZEBO_LIBRARIES} ${catkin_LIBRARIES} ${Boost_LIBRARIES}) - -add_library(gazebo_ros_f3d src/gazebo_ros_f3d.cpp) -target_link_libraries(gazebo_ros_f3d ${catkin_LIBRARIES} ${Boost_LIBRARIES}) - -add_library(gazebo_ros_bumper src/gazebo_ros_bumper.cpp) -add_dependencies(gazebo_ros_bumper ${catkin_EXPORTED_TARGETS}) -target_link_libraries(gazebo_ros_bumper ${Boost_LIBRARIES} ContactPlugin ${catkin_LIBRARIES}) - -add_library(gazebo_ros_projector src/gazebo_ros_projector.cpp) -target_link_libraries(gazebo_ros_projector ${Boost_LIBRARIES} ${catkin_LIBRARIES}) - -add_library(gazebo_ros_prosilica src/gazebo_ros_prosilica.cpp) -add_dependencies(gazebo_ros_prosilica ${PROJECT_NAME}_gencfg) -target_link_libraries(gazebo_ros_prosilica gazebo_ros_camera_utils CameraPlugin ${catkin_LIBRARIES}) - -add_library(gazebo_ros_force src/gazebo_ros_force.cpp) -target_link_libraries(gazebo_ros_force ${catkin_LIBRARIES} ${Boost_LIBRARIES}) - -add_library(gazebo_ros_joint_state_publisher src/gazebo_ros_joint_state_publisher.cpp) -set_target_properties(gazebo_ros_joint_state_publisher PROPERTIES LINK_FLAGS "${ld_flags}") -set_target_properties(gazebo_ros_joint_state_publisher PROPERTIES COMPILE_FLAGS "${cxx_flags}") -add_dependencies(gazebo_ros_joint_state_publisher ${catkin_EXPORTED_TARGETS}) -target_link_libraries(gazebo_ros_joint_state_publisher ${catkin_LIBRARIES} ${Boost_LIBRARIES}) - -add_library(gazebo_ros_joint_pose_trajectory src/gazebo_ros_joint_pose_trajectory.cpp) -add_dependencies(gazebo_ros_joint_pose_trajectory ${catkin_EXPORTED_TARGETS}) -target_link_libraries(gazebo_ros_joint_pose_trajectory ${catkin_LIBRARIES} ${Boost_LIBRARIES}) - -add_library(gazebo_ros_diff_drive src/gazebo_ros_diff_drive.cpp) -target_link_libraries(gazebo_ros_diff_drive gazebo_ros_utils ${catkin_LIBRARIES} ${Boost_LIBRARIES}) - -add_library(gazebo_ros_tricycle_drive src/gazebo_ros_tricycle_drive.cpp) -target_link_libraries(gazebo_ros_tricycle_drive gazebo_ros_utils ${Boost_LIBRARIES} ${catkin_LIBRARIES}) - -add_library(gazebo_ros_skid_steer_drive src/gazebo_ros_skid_steer_drive.cpp) -target_link_libraries(gazebo_ros_skid_steer_drive ${catkin_LIBRARIES} ${Boost_LIBRARIES}) - -add_library(gazebo_ros_video src/gazebo_ros_video.cpp) -target_link_libraries(gazebo_ros_video ${catkin_LIBRARIES} ${Boost_LIBRARIES} ${OGRE_LIBRARIES}) +find_package(ament_cmake REQUIRED) +find_package(gazebo_ros REQUIRED) +find_package(std_msgs REQUIRED) -add_library(gazebo_ros_planar_move src/gazebo_ros_planar_move.cpp) -target_link_libraries(gazebo_ros_planar_move ${catkin_LIBRARIES} ${Boost_LIBRARIES}) +include_directories(include) -add_library(gazebo_ros_hand_of_god src/gazebo_ros_hand_of_god.cpp) -set_target_properties(gazebo_ros_hand_of_god PROPERTIES LINK_FLAGS "${ld_flags}") -set_target_properties(gazebo_ros_hand_of_god PROPERTIES COMPILE_FLAGS "${cxx_flags}") -target_link_libraries(gazebo_ros_hand_of_god ${catkin_LIBRARIES} ${Boost_LIBRARIES}) +add_library(gazebo_ros_node_example SHARED src/node_example.cpp) +ament_target_dependencies(gazebo_ros_node_example gazebo_ros std_msgs) -add_library(gazebo_ros_ft_sensor src/gazebo_ros_ft_sensor.cpp) -target_link_libraries(gazebo_ros_ft_sensor ${catkin_LIBRARIES} ${Boost_LIBRARIES}) - -add_library(gazebo_ros_range src/gazebo_ros_range.cpp) -target_link_libraries(gazebo_ros_range ${catkin_LIBRARIES} ${Boost_LIBRARIES} RayPlugin) - -add_library(gazebo_ros_vacuum_gripper src/gazebo_ros_vacuum_gripper.cpp) -target_link_libraries(gazebo_ros_vacuum_gripper ${catkin_LIBRARIES} ${Boost_LIBRARIES}) - -## -## Add your new plugin here -## - -## Template -add_library(gazebo_ros_template src/gazebo_ros_template.cpp) -target_link_libraries(gazebo_ros_template ${catkin_LIBRARIES} ${Boost_LIBRARIES}) - -install(TARGETS - hokuyo_node - vision_reconfigure - camera_synchronizer - gazebo_ros_utils - gazebo_ros_camera_utils - gazebo_ros_camera - gazebo_ros_triggered_camera - gazebo_ros_multicamera - MultiCameraPlugin - gazebo_ros_triggered_multicamera - gazebo_ros_depth_camera - gazebo_ros_openni_kinect - gazebo_ros_laser - gazebo_ros_block_laser - gazebo_ros_p3d - gazebo_ros_imu - gazebo_ros_imu_sensor - gazebo_ros_f3d - gazebo_ros_ft_sensor - gazebo_ros_bumper - gazebo_ros_hand_of_god - gazebo_ros_template - gazebo_ros_projector - gazebo_ros_prosilica - gazebo_ros_force - gazebo_ros_joint_state_publisher - gazebo_ros_joint_pose_trajectory - gazebo_ros_diff_drive - gazebo_ros_tricycle_drive - gazebo_ros_skid_steer_drive - gazebo_ros_video - gazebo_ros_planar_move - gazebo_ros_vacuum_gripper - pub_joint_trajectory_test - gazebo_ros_gpu_laser - gazebo_ros_range - DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} - LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} - ) - -if (NOT GAZEBO_VERSION VERSION_LESS 6.0) - install(TARGETS gazebo_ros_elevator - DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} - LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} - ) -endif() - -if (NOT GAZEBO_VERSION VERSION_LESS 7.3) - install(TARGETS gazebo_ros_harness - DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} - LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} - ) -endif() +ament_package() install(DIRECTORY include/ - DESTINATION ${CATKIN_GLOBAL_INCLUDE_DESTINATION} - FILES_MATCHING PATTERN "*.h" -) - -install(PROGRAMS scripts/set_wrench.py scripts/set_pose.py scripts/gazebo_model - DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} - ) - -install(DIRECTORY Media - DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} - ) - -install(DIRECTORY test - DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} - ) + DESTINATION include) -# Tests -# These need to be run with -j1 flag because gazebo can't be run -# in parallel. -if (CATKIN_ENABLE_TESTING) - find_package(rostest REQUIRED) - - add_rostest_gtest(set_model_state-test - test/set_model_state_test/set_model_state_test.test - test/set_model_state_test/set_model_state_test.cpp) - target_link_libraries(set_model_state-test ${catkin_LIBRARIES}) - - add_rostest(test/range/range_plugin.test) - - if (ENABLE_DISPLAY_TESTS) - add_rostest_gtest(depth_camera-test - test/camera/depth_camera.test - test/camera/depth_camera.cpp) - target_link_libraries(depth_camera-test ${catkin_LIBRARIES}) - add_rostest_gtest(multicamera-test - test/camera/multicamera.test - test/camera/multicamera.cpp) - target_link_libraries(multicamera-test ${catkin_LIBRARIES}) - add_rostest_gtest(camera-test - test/camera/camera.test - test/camera/camera.cpp) - target_link_libraries(camera-test ${catkin_LIBRARIES}) - add_rostest_gtest(camera16bit-test - test/camera/camera16bit.test - test/camera/camera16bit.cpp) - target_link_libraries(camera16bit-test ${catkin_LIBRARIES}) - add_rostest_gtest(distortion_barrel_test - test/camera/distortion_barrel.test - test/camera/distortion_barrel.cpp) - target_link_libraries(distortion_barrel_test ${catkin_LIBRARIES}) - add_rostest_gtest(distortion_pincushion_test - test/camera/distortion_pincushion.test - test/camera/distortion_pincushion.cpp) - target_link_libraries(distortion_pincushion_test ${catkin_LIBRARIES}) - add_rostest_gtest(triggered-camera-test - test/camera/triggered_camera.test - test/camera/triggered_camera.cpp) - target_link_libraries(triggered-camera-test ${catkin_LIBRARIES}) - endif() -endif() +install(TARGETS gazebo_ros_node_example + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + RUNTIME DESTINATION bin) diff --git a/gazebo_plugins/include/gazebo_plugins/node_example.hpp b/gazebo_plugins/include/gazebo_plugins/node_example.hpp new file mode 100644 index 000000000..46ca35ff8 --- /dev/null +++ b/gazebo_plugins/include/gazebo_plugins/node_example.hpp @@ -0,0 +1,40 @@ +// Copyright 2018 Open Source Robotics Foundation, Inc. +// +// 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 GAZEBO_PLUGINS_NODE_EXAMPLE_HPP +#define GAZEBO_PLUGINS_NODE_EXAMPLE_HPP + +#include +#include +#include + + +/// Simple example of a gazebo plugin which uses a ROS2 node with gazebo_ros::Node +class GazeboRosNodeExample : public gazebo::SystemPlugin +{ +public: + GazeboRosNodeExample(); + virtual ~GazeboRosNodeExample(); + /// Called by gazebo to load plugin. Creates #node_, #timer_, and #pub_ + void Load(int argc, char** argv); +private: + /// ROS node used for publisher and timer + gazebo_ros::Node::SharedPtr node_; + /// Timer called to publish a message every second + std::shared_ptr timer_; + /// Example publisher + std::shared_ptr > pub_; +}; + +#endif diff --git a/gazebo_plugins/package.xml b/gazebo_plugins/package.xml index 58ad49c4e..8a5e04696 100644 --- a/gazebo_plugins/package.xml +++ b/gazebo_plugins/package.xml @@ -1,5 +1,6 @@ - + + gazebo_plugins 2.8.4 @@ -16,40 +17,15 @@ John Hsu - catkin - - gazebo_dev - - gazebo_dev - - gazebo_msgs - geometry_msgs - sensor_msgs - trajectory_msgs - std_srvs - roscpp - rospy - nodelet - angles - nav_msgs - urdf - tf - tf2_ros - dynamic_reconfigure - rosgraph_msgs - image_transport - rosconsole - message_generation - message_runtime - cv_bridge - polled_camera - diagnostic_updater - camera_info_manager - std_msgs - - rostest + ament_cmake + gazebo_ros + std_msgs + + gazebo_ros + std_msgs + + + ament_cmake + diff --git a/gazebo_plugins/src/node_example.cpp b/gazebo_plugins/src/node_example.cpp new file mode 100644 index 000000000..9e331c97f --- /dev/null +++ b/gazebo_plugins/src/node_example.cpp @@ -0,0 +1,51 @@ +// Copyright 2018 Open Source Robotics Foundation, Inc. +// +// 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. + +#include + +GazeboRosNodeExample::GazeboRosNodeExample() +{ +} + +GazeboRosNodeExample::~GazeboRosNodeExample() +{ +} + +void GazeboRosNodeExample::Load(int argc, char** argv) +{ + // Initialize ROS with arguments + gazebo_ros::Node::InitROS(argc, argv); + + // Create the ROS node + node_ = gazebo_ros::Node::Create("gazebo_ros_node_example"); + + // Create a publisher + pub_ = node_->create_publisher("test"); + + // Run lambda every 1 second + using namespace std::chrono_literals; + timer_ = node_->create_wall_timer(1s, [this] () { + // Create string message + auto msg = std_msgs::msg::String(); + msg.data = "Hello world"; + + // Warn with this node's name (to test logging) + RCLCPP_WARN(node_->get_logger(), "Publishing"); + + // Publish message + this->pub_->publish(msg); + }); +} + +GZ_REGISTER_SYSTEM_PLUGIN(GazeboRosNodeExample)