From 87453bacf3979bc80f5fc62078d2b7d433edbf44 Mon Sep 17 00:00:00 2001 From: seanyen Date: Wed, 8 Apr 2020 17:12:30 -0700 Subject: [PATCH 1/3] Adding Windows bringup. --- gazebo_plugins/CMakeLists.txt | 13 +++++ gazebo_plugins/src/gazebo_ros_ray_sensor.cpp | 1 + gazebo_ros/CMakeLists.txt | 12 ++++ gazebo_ros/include/gazebo_ros/node.hpp | 3 +- .../gazebo_ros/node_visibility_control.h | 56 +++++++++++++++++++ gazebo_ros/include/gazebo_ros/utils.hpp | 7 ++- .../gazebo_ros/utils_visibility_control.h | 56 +++++++++++++++++++ 7 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 gazebo_ros/include/gazebo_ros/node_visibility_control.h create mode 100644 gazebo_ros/include/gazebo_ros/utils_visibility_control.h diff --git a/gazebo_plugins/CMakeLists.txt b/gazebo_plugins/CMakeLists.txt index 1ae4e78d3..cec19412a 100644 --- a/gazebo_plugins/CMakeLists.txt +++ b/gazebo_plugins/CMakeLists.txt @@ -11,6 +11,16 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic") endif() +if(WIN32) + add_compile_definitions( + # For math constants + _USE_MATH_DEFINES + # Minimize Windows namespace collision + NOMINMAX + WIN32_LEAN_AND_MEAN + ) +endif() + find_package(ament_cmake REQUIRED) find_package(camera_info_manager REQUIRED) find_package(gazebo_dev REQUIRED) @@ -221,6 +231,9 @@ ament_export_libraries(gazebo_ros_ft_sensor) add_library(gazebo_ros_bumper SHARED src/gazebo_ros_bumper.cpp ) +target_link_libraries(gazebo_ros_bumper + ContactPlugin +) ament_target_dependencies(gazebo_ros_bumper "gazebo_ros" "gazebo_msgs" diff --git a/gazebo_plugins/src/gazebo_ros_ray_sensor.cpp b/gazebo_plugins/src/gazebo_ros_ray_sensor.cpp index 6d0fc4c01..542c439b5 100644 --- a/gazebo_plugins/src/gazebo_ros_ray_sensor.cpp +++ b/gazebo_plugins/src/gazebo_ros_ray_sensor.cpp @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include #include #include diff --git a/gazebo_ros/CMakeLists.txt b/gazebo_ros/CMakeLists.txt index a51aa0903..b854e807b 100644 --- a/gazebo_ros/CMakeLists.txt +++ b/gazebo_ros/CMakeLists.txt @@ -11,6 +11,16 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic") endif() +if(WIN32) + add_compile_definitions( + # For math constants + _USE_MATH_DEFINES + # Minimize Windows namespace collision + NOMINMAX + WIN32_LEAN_AND_MEAN + ) +endif() + find_package(ament_cmake REQUIRED) find_package(builtin_interfaces REQUIRED) find_package(gazebo_dev REQUIRED) @@ -38,6 +48,7 @@ target_include_directories(gazebo_ros_node $ ${gazebo_dev_INCLUDE_DIRS} ) +target_compile_definitions(gazebo_ros_node PRIVATE "GAZEBO_ROS_NODE_BUILDING_DLL") ament_target_dependencies(gazebo_ros_node "gazebo_dev" @@ -55,6 +66,7 @@ target_include_directories(gazebo_ros_utils $ $ ) +target_compile_definitions(gazebo_ros_utils PRIVATE "GAZEBO_ROS_UTILS_BUILDING_DLL") ament_target_dependencies(gazebo_ros_utils "gazebo_dev" "rclcpp" diff --git a/gazebo_ros/include/gazebo_ros/node.hpp b/gazebo_ros/include/gazebo_ros/node.hpp index 31065f3ac..9d4f2bacd 100644 --- a/gazebo_ros/include/gazebo_ros/node.hpp +++ b/gazebo_ros/include/gazebo_ros/node.hpp @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -33,7 +34,7 @@ namespace gazebo_ros * Wrapper around an rclcpp::Node which ensures all instances share an executor. * \include gazebo_ros/node.hpp */ -class Node : public rclcpp::Node +class GAZEBO_ROS_NODE_PUBLIC Node : public rclcpp::Node { public: /// Shared pointer to a #gazebo_ros::Node diff --git a/gazebo_ros/include/gazebo_ros/node_visibility_control.h b/gazebo_ros/include/gazebo_ros/node_visibility_control.h new file mode 100644 index 000000000..a02a96d99 --- /dev/null +++ b/gazebo_ros/include/gazebo_ros/node_visibility_control.h @@ -0,0 +1,56 @@ +// Copyright 2020 Microsoft Corporation. +// +// 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 GAZEBO_ROS_NODE__VISIBILITY_CONTROL_H_ +#define GAZEBO_ROS_NODE__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 GAZEBO_ROS_NODE_EXPORT __attribute__ ((dllexport)) + #define GAZEBO_ROS_NODE_IMPORT __attribute__ ((dllimport)) + #else + #define GAZEBO_ROS_NODE_EXPORT __declspec(dllexport) + #define GAZEBO_ROS_NODE_IMPORT __declspec(dllimport) + #endif + #ifdef GAZEBO_ROS_NODE_BUILDING_DLL + #define GAZEBO_ROS_NODE_PUBLIC GAZEBO_ROS_NODE_EXPORT + #else + #define GAZEBO_ROS_NODE_PUBLIC GAZEBO_ROS_NODE_IMPORT + #endif + #define GAZEBO_ROS_NODE_PUBLIC_TYPE GAZEBO_ROS_NODE_PUBLIC + #define GAZEBO_ROS_NODE_LOCAL +#else + #define GAZEBO_ROS_NODE_EXPORT __attribute__ ((visibility("default"))) + #define GAZEBO_ROS_NODE_IMPORT + #if __GNUC__ >= 4 + #define GAZEBO_ROS_NODE_PUBLIC __attribute__ ((visibility("default"))) + #define GAZEBO_ROS_NODE_LOCAL __attribute__ ((visibility("hidden"))) + #else + #define GAZEBO_ROS_NODE_PUBLIC + #define GAZEBO_ROS_NODE_LOCAL + #endif + #define GAZEBO_ROS_NODE_PUBLIC_TYPE +#endif + +#endif // GAZEBO_ROS_NODE__VISIBILITY_CONTROL_H_ diff --git a/gazebo_ros/include/gazebo_ros/utils.hpp b/gazebo_ros/include/gazebo_ros/utils.hpp index fbf33eb8a..eb519c2ba 100644 --- a/gazebo_ros/include/gazebo_ros/utils.hpp +++ b/gazebo_ros/include/gazebo_ros/utils.hpp @@ -18,6 +18,7 @@ #include #include #include +#include #include @@ -37,12 +38,14 @@ namespace gazebo_ros /// \return If the model is Gaussian, return the square of the standard deviation. /// \return If the model is no noise, return 0. /// \return If the model is custom, return -1 +GAZEBO_ROS_UTILS_PUBLIC double NoiseVariance(const gazebo::sensors::Noise & _noise); /// Get the variance of a gazebo sensor noise model /// \param[in] _noise_ptr Shared pointer to the gazebo noise model /// \return If the pointer is nullptr, return 0. /// \return Otherwise, returns the same as @ref NoiseVariance(const gazebo::sensors::Noise &). +GAZEBO_ROS_UTILS_PUBLIC double NoiseVariance(const gazebo::sensors::NoisePtr & _noise_ptr); /// Gets the base name of a gazebo scoped name @@ -51,6 +54,7 @@ double NoiseVariance(const gazebo::sensors::NoisePtr & _noise_ptr); /// \return Input string with all base scopes removed, see example /// \todo Deprecate once with is implemented in gazebo/ignition/sdf. /// See: https://bitbucket.org/osrf/gazebo/issues/1735/add-helper-functions-to-handle-scoped +GAZEBO_ROS_UTILS_PUBLIC std::string ScopedNameBase(const std::string & str); /// Selects an appropriate tf frame id for a gazebo sensor @@ -62,10 +66,11 @@ std::string ScopedNameBase(const std::string & str); /// \param[in] _sensor The gazebo sensor which the frame should be in /// \param[in] _sdf SDF pointer which may contain a tag to override the frame id /// \return The string representing the tf frame of the sensor +GAZEBO_ROS_UTILS_PUBLIC std::string SensorFrameID(const gazebo::sensors::Sensor & _sensor, const sdf::Element & _sdf); /// Helper class used to throttle something to a given rate -class Throttler +class GAZEBO_ROS_UTILS_PUBLIC Throttler { public: /// Create a throttler with a frequency diff --git a/gazebo_ros/include/gazebo_ros/utils_visibility_control.h b/gazebo_ros/include/gazebo_ros/utils_visibility_control.h new file mode 100644 index 000000000..cb7f40c02 --- /dev/null +++ b/gazebo_ros/include/gazebo_ros/utils_visibility_control.h @@ -0,0 +1,56 @@ +// Copyright 2020 Microsoft Corporation. +// +// 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 GAZEBO_ROS_UTILS__VISIBILITY_CONTROL_H_ +#define GAZEBO_ROS_UTILS__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 GAZEBO_ROS_UTILS_EXPORT __attribute__ ((dllexport)) + #define GAZEBO_ROS_UTILS_IMPORT __attribute__ ((dllimport)) + #else + #define GAZEBO_ROS_UTILS_EXPORT __declspec(dllexport) + #define GAZEBO_ROS_UTILS_IMPORT __declspec(dllimport) + #endif + #ifdef GAZEBO_ROS_UTILS_BUILDING_DLL + #define GAZEBO_ROS_UTILS_PUBLIC GAZEBO_ROS_UTILS_EXPORT + #else + #define GAZEBO_ROS_UTILS_PUBLIC GAZEBO_ROS_UTILS_IMPORT + #endif + #define GAZEBO_ROS_UTILS_PUBLIC_TYPE GAZEBO_ROS_UTILS_PUBLIC + #define GAZEBO_ROS_UTILS_LOCAL +#else + #define GAZEBO_ROS_UTILS_EXPORT __attribute__ ((visibility("default"))) + #define GAZEBO_ROS_UTILS_IMPORT + #if __GNUC__ >= 4 + #define GAZEBO_ROS_UTILS_PUBLIC __attribute__ ((visibility("default"))) + #define GAZEBO_ROS_UTILS_LOCAL __attribute__ ((visibility("hidden"))) + #else + #define GAZEBO_ROS_UTILS_PUBLIC + #define GAZEBO_ROS_UTILS_LOCAL + #endif + #define GAZEBO_ROS_UTILS_PUBLIC_TYPE +#endif + +#endif // GAZEBO_ROS_UTILS__VISIBILITY_CONTROL_H_ From d004a2baf020f70e130dc6aff314cd016dd8c541 Mon Sep 17 00:00:00 2001 From: seanyen Date: Wed, 8 Apr 2020 17:33:22 -0700 Subject: [PATCH 2/3] fix lint. --- gazebo_ros/include/gazebo_ros/node_visibility_control.h | 6 +++--- gazebo_ros/include/gazebo_ros/utils_visibility_control.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gazebo_ros/include/gazebo_ros/node_visibility_control.h b/gazebo_ros/include/gazebo_ros/node_visibility_control.h index a02a96d99..36401578e 100644 --- a/gazebo_ros/include/gazebo_ros/node_visibility_control.h +++ b/gazebo_ros/include/gazebo_ros/node_visibility_control.h @@ -19,8 +19,8 @@ * library cannot have, but the consuming code must have inorder to link. */ -#ifndef GAZEBO_ROS_NODE__VISIBILITY_CONTROL_H_ -#define GAZEBO_ROS_NODE__VISIBILITY_CONTROL_H_ +#ifndef GAZEBO_ROS__NODE_VISIBILITY_CONTROL_H_ +#define GAZEBO_ROS__NODE_VISIBILITY_CONTROL_H_ // This logic was borrowed (then namespaced) from the examples on the gcc wiki: // https://gcc.gnu.org/wiki/Visibility @@ -53,4 +53,4 @@ #define GAZEBO_ROS_NODE_PUBLIC_TYPE #endif -#endif // GAZEBO_ROS_NODE__VISIBILITY_CONTROL_H_ +#endif // GAZEBO_ROS__NODE_VISIBILITY_CONTROL_H_ diff --git a/gazebo_ros/include/gazebo_ros/utils_visibility_control.h b/gazebo_ros/include/gazebo_ros/utils_visibility_control.h index cb7f40c02..90d88dc7d 100644 --- a/gazebo_ros/include/gazebo_ros/utils_visibility_control.h +++ b/gazebo_ros/include/gazebo_ros/utils_visibility_control.h @@ -19,8 +19,8 @@ * library cannot have, but the consuming code must have inorder to link. */ -#ifndef GAZEBO_ROS_UTILS__VISIBILITY_CONTROL_H_ -#define GAZEBO_ROS_UTILS__VISIBILITY_CONTROL_H_ +#ifndef GAZEBO_ROS__UTILS_VISIBILITY_CONTROL_H_ +#define GAZEBO_ROS__UTILS_VISIBILITY_CONTROL_H_ // This logic was borrowed (then namespaced) from the examples on the gcc wiki: // https://gcc.gnu.org/wiki/Visibility @@ -53,4 +53,4 @@ #define GAZEBO_ROS_UTILS_PUBLIC_TYPE #endif -#endif // GAZEBO_ROS_UTILS__VISIBILITY_CONTROL_H_ +#endif // GAZEBO_ROS__UTILS_VISIBILITY_CONTROL_H_ From a1d2331f2b7cbca562b7024747600aeb98b67a6c Mon Sep 17 00:00:00 2001 From: Sean Yen Date: Tue, 14 Apr 2020 08:54:30 -0700 Subject: [PATCH 3/3] address the feedback. --- gazebo_ros/CMakeLists.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gazebo_ros/CMakeLists.txt b/gazebo_ros/CMakeLists.txt index b854e807b..37354da0a 100644 --- a/gazebo_ros/CMakeLists.txt +++ b/gazebo_ros/CMakeLists.txt @@ -48,7 +48,9 @@ target_include_directories(gazebo_ros_node $ ${gazebo_dev_INCLUDE_DIRS} ) -target_compile_definitions(gazebo_ros_node PRIVATE "GAZEBO_ROS_NODE_BUILDING_DLL") +if(WIN32) + target_compile_definitions(gazebo_ros_node PRIVATE "GAZEBO_ROS_NODE_BUILDING_DLL") +endif() ament_target_dependencies(gazebo_ros_node "gazebo_dev" @@ -66,7 +68,9 @@ target_include_directories(gazebo_ros_utils $ $ ) -target_compile_definitions(gazebo_ros_utils PRIVATE "GAZEBO_ROS_UTILS_BUILDING_DLL") +if(WIN32) + target_compile_definitions(gazebo_ros_utils PRIVATE "GAZEBO_ROS_UTILS_BUILDING_DLL") +endif() ament_target_dependencies(gazebo_ros_utils "gazebo_dev" "rclcpp"