Skip to content

Commit 47746fa

Browse files
Ryanf55srmainwaring
authored andcommitted
ros2: updates to cmake and launch files to support build on macOS
Port to ROS 2 Signed-off-by: Ryan Friedman <[email protected]> Get launch file running aside from resources * Update docs * Remove ROS1 cruft Signed-off-by: Ryan Friedman <[email protected]> - update gdal include path if __APPLE__ - consolidate cmake files and install executable - update rviz to rviz2 in launch file - add arguments and rename python launch file - link directory workaround for yaml-cpp on aarch64. - update launch files to use correct param name for tif_color_path. - CMakeLists.txt improvements. - remove target_include_directories for test_tif_loader. - add dependency on yaml_cpp_vendor. - restore namespace to tif_loader node in launch file. - exclude executable from target exports and fix header install directory. Signed-off-by: Rhys Mainwaring <[email protected]> Co-authored-by: Ryan Friedman <[email protected]> Co-authored-by: Rhys Mainwaring <[email protected]>
1 parent 6eea0ef commit 47746fa

File tree

10 files changed

+175
-75
lines changed

10 files changed

+175
-75
lines changed

CMakeLists.txt

Lines changed: 61 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,54 +15,91 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
1515
add_compile_options(-Wall -Wextra -Wpedantic)
1616
endif()
1717

18-
find_package(GDAL 3 REQUIRED)
1918
find_package(ament_cmake REQUIRED)
19+
find_package(grid_map_msgs REQUIRED)
2020
find_package(grid_map_ros REQUIRED)
2121
find_package(grid_map_core REQUIRED)
22+
find_package(rclcpp REQUIRED)
23+
2224
find_package(Eigen3 REQUIRED)
25+
find_package(GDAL 3 REQUIRED)
2326

24-
add_library(${PROJECT_NAME})
25-
add_subdirectory(src)
26-
27-
target_include_directories(${PROJECT_NAME}
28-
PUBLIC
29-
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
30-
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>"
31-
)
27+
find_package(yaml_cpp_vendor REQUIRED)
28+
link_directories(${yaml_cpp_vendor_LIBRARY_DIRS})
3229

3330
# Reverse compatability for GDAL<3.5
3431
# https://gdal.org/development/cmake.html
3532
if(NOT TARGET GDAL::GDAL)
36-
add_library(GDAL::GDAL ALIAS ${GDAL_LIBRARY})
33+
add_library(GDAL::GDAL ALIAS ${GDAL_LIBRARY})
3734
endif()
3835

39-
target_link_libraries(${PROJECT_NAME} Eigen3::Eigen GDAL::GDAL grid_map_core::grid_map_core)
36+
# Build
37+
add_library(${PROJECT_NAME}
38+
src/grid_map_geo.cpp
39+
)
40+
41+
target_include_directories(${PROJECT_NAME}
42+
PUBLIC
43+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
44+
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>"
45+
)
4046

41-
ament_export_targets(${PROJECT_NAME}Targets HAS_LIBRARY_TARGET)
42-
ament_export_dependencies(GDAL)
47+
target_link_libraries(${PROJECT_NAME} Eigen3::Eigen GDAL::GDAL)
48+
49+
ament_target_dependencies(${PROJECT_NAME} SYSTEM
50+
grid_map_core
51+
grid_map_ros
52+
)
53+
54+
add_executable(test_tif_loader
55+
src/test_tif_loader.cpp
56+
)
57+
58+
target_link_libraries(test_tif_loader
59+
${PROJECT_NAME}
60+
)
4361

62+
# Install
4463
install(
4564
DIRECTORY include/
46-
DESTINATION include
65+
DESTINATION include/${PROJECT_NAME}
4766
)
4867

49-
install(DIRECTORY
50-
launch
51-
DESTINATION share/${PROJECT_NAME}/
68+
install(
69+
TARGETS
70+
${PROJECT_NAME}
71+
EXPORT export_${PROJECT_NAME}
72+
ARCHIVE DESTINATION lib/${PROJECT_NAME}
73+
LIBRARY DESTINATION lib/${PROJECT_NAME}
74+
RUNTIME DESTINATION bin/${PROJECT_NAME}
5275
)
5376

77+
ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
78+
ament_export_dependencies(GDAL)
79+
80+
# NOTE: if RUNTIME DESTINATION is set to bin/${PROJECT_NAME} the executable
81+
# is not found by ros2 launch:
82+
#
83+
# Caught exception in launch (see debug for traceback): executable
84+
# 'test_tif_loader' not found on the libexec directory
85+
# '<ws_path>/ros2-aerial/install/grid_map_geo/lib/grid_map_geo'
5486
install(
55-
TARGETS ${PROJECT_NAME}
56-
EXPORT ${PROJECT_NAME}Targets
57-
LIBRARY DESTINATION lib
58-
ARCHIVE DESTINATION lib
59-
RUNTIME DESTINATION bin
60-
INCLUDES DESTINATION include
87+
TARGETS
88+
test_tif_loader
89+
ARCHIVE DESTINATION lib/${PROJECT_NAME}
90+
LIBRARY DESTINATION lib/${PROJECT_NAME}
91+
RUNTIME DESTINATION lib/${PROJECT_NAME}
92+
)
93+
94+
install(DIRECTORY
95+
launch
96+
DESTINATION share/${PROJECT_NAME}/
6197
)
6298

99+
# Test
63100
include(CTest)
64101
if(BUILD_TESTING)
65-
add_subdirectory(test)
102+
add_subdirectory(test)
66103
endif()
67104

68105
ament_package()

include/grid_map_geo/grid_map_geo.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,20 @@
3939
#include <grid_map_core/GridMap.hpp>
4040
#include <grid_map_core/iterators/GridMapIterator.hpp>
4141

42+
#if __APPLE__
43+
#include <cpl_string.h>
44+
#include <gdal.h>
45+
#include <gdal_priv.h>
46+
#include <ogr_p.h>
47+
#include <ogr_spatialref.h>
48+
#else
4249
#include <gdal/cpl_string.h>
4350
#include <gdal/gdal.h>
4451
#include <gdal/gdal_priv.h>
4552
#include <gdal/ogr_p.h>
4653
#include <gdal/ogr_spatialref.h>
54+
#endif
55+
4756
#include <iostream>
4857
struct Location {
4958
ESPG espg{ESPG::WGS84};

include/grid_map_geo/transform.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,17 @@
3434
#ifndef GRID_MAP_GEO_TRANSFORM_H
3535
#define GRID_MAP_GEO_TRANSFORM_H
3636

37+
#if __APPLE__
38+
#include <gdal.h>
39+
#include <gdal_priv.h>
40+
#include <ogr_p.h>
41+
#include <ogr_spatialref.h>
42+
#else
3743
#include <gdal/gdal.h>
3844
#include <gdal/gdal_priv.h>
3945
#include <gdal/ogr_p.h>
4046
#include <gdal/ogr_spatialref.h>
47+
#endif
4148

4249
#include <Eigen/Dense>
4350

launch/load_tif.launch.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import os
2+
3+
from ament_index_python.packages import get_package_share_directory
4+
5+
from launch import LaunchDescription
6+
from launch.actions import DeclareLaunchArgument
7+
from launch.conditions import IfCondition
8+
from launch.substitutions import LaunchConfiguration
9+
10+
from launch_ros.actions import Node
11+
12+
13+
def generate_launch_description():
14+
"""Generate a launch description."""
15+
16+
pkg_grid_map_geo = get_package_share_directory("grid_map_geo")
17+
18+
# static transform node
19+
static_transform_publisher = Node(
20+
package="tf2_ros",
21+
executable="static_transform_publisher",
22+
name="world_map",
23+
arguments=[
24+
"--frame-id",
25+
"world",
26+
"--child-frame-id",
27+
"map",
28+
],
29+
)
30+
31+
# tif loader node
32+
tif_loader = Node(
33+
package="grid_map_geo",
34+
namespace="grid_map_geo",
35+
executable="test_tif_loader",
36+
name="tif_loader",
37+
parameters=[
38+
{"tif_path": LaunchConfiguration("tif_path")},
39+
{"tif_color_path": LaunchConfiguration("tif_color_path")},
40+
],
41+
output="screen",
42+
emulate_tty=True,
43+
)
44+
45+
# rviz node
46+
rviz = Node(
47+
package="rviz2",
48+
executable="rviz2",
49+
arguments=["-d", os.path.join(pkg_grid_map_geo, "launch", "config.rviz")],
50+
condition=IfCondition(LaunchConfiguration("rviz")),
51+
)
52+
53+
default_location = "sargans"
54+
default_tif_file = "sargans.tif"
55+
default_tif_color_file = "sargans_color.tif"
56+
return LaunchDescription(
57+
[
58+
DeclareLaunchArgument(
59+
"rviz", default_value="true", description="Open RViz."
60+
),
61+
DeclareLaunchArgument(
62+
"location",
63+
default_value=default_location,
64+
description="Location.",
65+
),
66+
DeclareLaunchArgument(
67+
"tif_path",
68+
default_value=os.path.join(
69+
pkg_grid_map_geo, "resources", default_tif_file
70+
),
71+
description="Full path to the elevation map file.",
72+
),
73+
DeclareLaunchArgument(
74+
"tif_color_path",
75+
default_value=os.path.join(
76+
pkg_grid_map_geo, "resources", default_tif_color_file
77+
),
78+
description="Full path to the elevation texture file.",
79+
),
80+
static_transform_publisher,
81+
tif_loader,
82+
rviz,
83+
]
84+
)

launch/load_tif_launch.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<launch>
2-
<arg name="visualization" default="true"/>
2+
<arg name="rviz" default="true"/>
33
<arg name="location" default="sargans"/>
44
<node pkg="tf2_ros" exec="static_transform_publisher" name="world_map" args="--frame-id world --child-frame-id map"/>
55

66
<node pkg="grid_map_geo" exec="test_tif_loader" name="test_tif_loader" output="screen">
7-
<param name="tif_path" value="$(find-pkg-share grid_map_geo)/resources/sertig.tif"/>
8-
<param name="color_path" value="$(find-pkg-share grid_map_geo)/resources/sertig_color.tif"/>
7+
<param name="tif_path" value="$(find-pkg-share grid_map_geo)/resources/sargans.tif"/>
8+
<param name="tif_color_path" value="$(find-pkg-share grid_map_geo)/resources/sargans_color.tif"/>
99
</node>
1010

11-
<group if="$(var visualization)">
12-
<node exec="rviz" name="rviz" pkg="rviz" args="-d $(find-pkg-share grid_map_geo)/launch/config.rviz" />
11+
<group if="$(var rviz)">
12+
<node exec="rviz2" name="rviz2" pkg="rviz2" args="-d $(find-pkg-share grid_map_geo)/launch/config.rviz" />
1313
</group>
1414
</launch>

launch/run.launch.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<depend>grid_map_ros</depend>
1919
<depend>libgdal-dev</depend>
2020
<depend>rclcpp</depend>
21+
<depend>yaml_cpp_vendor</depend>
2122
<exec_depend>ros2launch</exec_depend>
2223

2324
<export>

src/CMakeLists.txt

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/test_tif_loader.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ class MapPublisher : public rclcpp::Node {
5555
std::string file_path = this->declare_parameter("tif_path", ".");
5656
std::string color_path = this->declare_parameter("tif_color_path", ".");
5757

58+
RCLCPP_INFO_STREAM(get_logger(), "file_path " << file_path);
59+
RCLCPP_INFO_STREAM(get_logger(), "color_path " << color_path);
60+
5861
map_ = std::make_shared<GridMapGeo>();
5962
map_->Load(file_path, false, color_path);
6063
timer_ = this->create_wall_timer(5s, std::bind(&MapPublisher::timer_callback, this));

test/CMakeLists.txt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# Add gtest based cpp test target and link libraries
22
find_package(ament_cmake_gtest)
33
ament_add_gtest(${PROJECT_NAME}-test
4-
main.cpp
5-
test_grid_map_geo.cpp
4+
main.cpp
5+
test_grid_map_geo.cpp
66
)
77

8-
98
target_link_libraries(${PROJECT_NAME}-test
10-
${PROJECT_NAME}
11-
# ${YAML_CPP_LIBRARIES}
12-
# ${GDAL_LIBRARY}
9+
${PROJECT_NAME}
10+
# ${YAML_CPP_LIBRARIES}
11+
# ${GDAL_LIBRARY}
1312
)

0 commit comments

Comments
 (0)