Skip to content

Commit

Permalink
Fix Windows build (#258)
Browse files Browse the repository at this point in the history
* Fix Windows build

* ID is not a member anymore

* Export C++ libController

* Fix libController

* Update module

* Fix controller spawner

* Update robot_launch.py
  • Loading branch information
lukicdarkoo authored Jul 30, 2021
1 parent dfe630b commit 091357a
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 26 deletions.
73 changes: 53 additions & 20 deletions webots_ros2_driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,6 @@ project(webots_ros2_driver)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if (UNIX)
set(WEBOTS_LIB_BASE webots/lib/linux-gnu)
endif (UNIX)
if (WIN32)
set(WEBOTS_LIB_BASE webots/lib/msys)
endif (WIN32)
if (MSVC)
set(WEBOTS_LIB_BASE webots/lib/darwin19)
endif (MSVC)
link_directories(${WEBOTS_LIB_BASE})
set(WEBOTS_LIB
${CMAKE_SHARED_LIBRARY_PREFIX}Controller${CMAKE_SHARED_LIBRARY_SUFFIX}
${CMAKE_SHARED_LIBRARY_PREFIX}CppController${CMAKE_SHARED_LIBRARY_SUFFIX}
)
include_directories(
include
webots/include/c
webots/include/cpp
)

# ROS2 Packages
find_package(ament_cmake REQUIRED)
find_package(rosgraph_msgs REQUIRED)
Expand All @@ -38,6 +18,52 @@ find_package(webots_ros2_msgs REQUIRED)
find_package(tinyxml2_vendor REQUIRED)
find_package(TinyXML2 REQUIRED)

if (UNIX AND NOT APPLE)
set(WEBOTS_LIB_BASE webots/lib/linux-gnu)
endif ()
if (APPLE)
set(WEBOTS_LIB_BASE webots/lib/darwin19)
endif ()
if (MSVC OR MSYS OR MINGW OR WIN32)
set(WEBOTS_LIB_BASE webots/lib/msys)
endif ()

include_directories(
include
webots/include/c
webots/include/cpp
)
link_directories(${WEBOTS_LIB_BASE})

if (MSVC OR MSYS OR MINGW OR WIN32)
# Windows requires the libController C++ part to be compiled.
# See more here: https://cyberbotics.com/doc/guide/using-your-ide#visual-studio

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
file(GLOB CppController_SRC CONFIGURE_DEPENDS "webots/source/cpp/*.cpp")
add_library(
CppController
SHARED
${CppController_SRC}
)
target_link_libraries(CppController
${CMAKE_SHARED_LIBRARY_PREFIX}Controller${CMAKE_SHARED_LIBRARY_SUFFIX}
)
install(TARGETS CppController
LIBRARY DESTINATION lib
)
set(WEBOTS_LIB
${CMAKE_SHARED_LIBRARY_PREFIX}Controller${CMAKE_SHARED_LIBRARY_SUFFIX}
CppController
)
ament_export_libraries(CppController)
else()
set(WEBOTS_LIB
${CMAKE_SHARED_LIBRARY_PREFIX}Controller${CMAKE_SHARED_LIBRARY_SUFFIX}
${CMAKE_SHARED_LIBRARY_PREFIX}CppController${CMAKE_SHARED_LIBRARY_SUFFIX}
)
endif()

add_executable(driver
src/Driver.cpp
src/WebotsNode.cpp
Expand Down Expand Up @@ -116,6 +142,13 @@ install(
DIRECTORY ${WEBOTS_LIB_BASE}/
DESTINATION lib/
)
if (MSVC OR MSYS OR MINGW OR WIN32)
# Windows requires the library to be placed with executable
install(
FILES "${WEBOTS_LIB_BASE}/${CMAKE_SHARED_LIBRARY_PREFIX}Controller${CMAKE_SHARED_LIBRARY_SUFFIX}"
DESTINATION lib/${PROJECT_NAME}
)
endif()

# Prevent pluginlib from using boost
target_compile_definitions(driver PUBLIC "PLUGINLIB__DISABLE_BOOST_FUNCTIONS")
Expand Down
1 change: 0 additions & 1 deletion webots_ros2_driver/src/plugins/static/Ros2Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ namespace webots_ros2_driver
// Object Info -> Detection2D
vision_msgs::msg::Detection2D detection;
vision_msgs::msg::ObjectHypothesisWithPose hypothesis;
hypothesis.id = std::string(objects[i].model);
hypothesis.pose.pose.position = position;
hypothesis.pose.pose.orientation = orientation;
detection.results.push_back(hypothesis);
Expand Down
2 changes: 1 addition & 1 deletion webots_ros2_driver/webots
Submodule webots updated 119 files
12 changes: 8 additions & 4 deletions webots_ros2_turtlebot/launch/robot_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,24 @@ def generate_launch_description():
world=PathJoinSubstitution([package_dir, 'worlds', world])
)

# TODO: Revert once the https://github.com/ros-controls/ros2_control/pull/444 PR gets into the release
controller_manager_timeout = ['--controller-manager-timeout', '50'] if os.name == 'nt' else []
controller_manager_prefix = 'python.exe' if os.name == 'nt' else "bash -c 'sleep 10; $0 $@' "

diffdrive_controller_spawner = Node(
package='controller_manager',
executable='spawner.py',
output='screen',
prefix="bash -c 'sleep 10; $0 $@' ",
arguments=['diffdrive_controller'],
prefix=controller_manager_prefix,
arguments=['diffdrive_controller'] + controller_manager_timeout,
)

joint_state_broadcaster_spawner = Node(
package='controller_manager',
executable='spawner.py',
output='screen',
prefix="bash -c 'sleep 10; $0 $@' ",
arguments=['joint_state_broadcaster'],
prefix=controller_manager_prefix,
arguments=['joint_state_broadcaster'] + controller_manager_timeout,
)

turtlebot_driver = Node(
Expand Down

0 comments on commit 091357a

Please sign in to comment.