Skip to content

Commit 43a3f13

Browse files
committed
Final fixes
* Switch to lambda instead of bind for timer callback * Handle no color by default so SRTM dataset works out of the box * Improve behavior of nullptr derefernece on publish Signed-off-by: Ryan Friedman <[email protected]>
1 parent b8ca7be commit 43a3f13

File tree

6 files changed

+29
-23
lines changed

6 files changed

+29
-23
lines changed

include/grid_map_geo/grid_map_geo.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636

3737
#include <grid_map_core/GridMap.hpp>
3838
#include <grid_map_core/iterators/GridMapIterator.hpp>
39+
40+
// Color map is optional. If left as this default value, color will not be loaded.
41+
static const std::string COLOR_MAP_DEFAULT_PATH{""};
42+
3943
#include <iostream>
4044

4145
#include "grid_map_geo/transform.hpp"

launch/load_tif.launch.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ def generate_launch_description():
2828
],
2929
)
3030

31-
# tif loader node
32-
tif_loader = Node(
31+
# map publisher node
32+
map_publisher = Node(
3333
package="grid_map_geo",
3434
namespace="grid_map_geo",
3535
executable="map_publisher",
36-
name="tif_loader",
36+
name="map_publisher",
3737
parameters=[
38-
{"tif_path": LaunchConfiguration("tif_path")},
39-
{"tif_color_path": LaunchConfiguration("tif_color_path")},
38+
{"gdal_dataset_path": LaunchConfiguration("gdal_dataset_path")},
39+
{"gdal_dataset_color_path": LaunchConfiguration("gdal_dataset_color_path")},
4040
],
4141
output="screen",
4242
emulate_tty=True,
@@ -51,8 +51,8 @@ def generate_launch_description():
5151
)
5252

5353
default_location = "sargans"
54-
default_tif_file = "sargans.tif"
55-
default_tif_color_file = "sargans_color.tif"
54+
default_gdal_dataset = "sargans.tif"
55+
default_gdal_color_dataset = "sargans_color.tif"
5656
return LaunchDescription(
5757
[
5858
DeclareLaunchArgument(
@@ -64,17 +64,19 @@ def generate_launch_description():
6464
description="Location.",
6565
),
6666
DeclareLaunchArgument(
67-
"tif_path",
68-
default_value=f'{Path(pkg_grid_map_geo) / "resources" / default_tif_file}',
67+
"gdal_dataset_path",
68+
default_value=f'{Path(pkg_grid_map_geo) / "resources" / default_gdal_dataset}',
6969
description="Full path to the elevation map file.",
7070
),
7171
DeclareLaunchArgument(
72-
"tif_color_path",
73-
default_value=f'{Path(pkg_grid_map_geo) / "resources" / default_tif_color_file}',
72+
"gdal_dataset_color_path",
73+
default_value=f'{Path(pkg_grid_map_geo) / "resources" / default_gdal_color_dataset}',
7474
description="Full path to the elevation texture file.",
7575
),
7676
static_transform_publisher,
77-
tif_loader,
77+
map_publisher,
7878
rviz,
7979
]
8080
)
81+
82+

launch/load_tif_launch.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
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="map_publisher" name="map_publisher" namespace="grid_map_geo" output="screen">
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"/>
7+
<param name="gdal_dataset_path" value="$(find-pkg-share grid_map_geo)/resources/sargans.tif"/>
8+
<param name="gdal_dataset_color_path" value="$(find-pkg-share grid_map_geo)/resources/sargans_color.tif"/>
99
</node>
1010

1111
<group if="$(var rviz)">

launch/load_vrt_launch.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
<arg name="rviz" default="false"/>
33
<node pkg="tf2_ros" exec="static_transform_publisher" name="world_map" args="--frame-id world --child-frame-id map"/>
44

5-
<node pkg="grid_map_geo" exec="map_publisher" name="map_publisher" output="screen" launch-prefix="gdb -ex run --args">
5+
<node pkg="grid_map_geo" exec="map_publisher" name="map_publisher" output="screen" launch-prefix="gdb -ex run --args" >
66
<param name="gdal_dataset_path" value="$(find-pkg-share grid_map_geo)/resources/ap_srtm1.vrt"/>
77
</node>
88

99
<group if="$(var rviz)">
10-
<node exec="rviz2" name="rviz2" pkg="rviz2" args="-d $(find-pkg-share grid_map_geo)/launch/config.rviz" />
10+
<node exec="rviz2" name="rviz2" pkg="rviz2" args="-d $(find-pkg-share grid_map_geo)/launch/config.rviz" />
1111
</group>
1212
</launch>

src/grid_map_geo.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void GridMapGeo::setMaxMapSizePixels(const int pixels_x, const int pixels_y) {
7373

7474
bool GridMapGeo::Load(const std::string &map_path, const std::string color_map_path) {
7575
bool loaded = initializeFromGdalDataset(map_path);
76-
if (!color_map_path.empty()) { // Load color layer if the color path is nonempty
76+
if (color_map_path != COLOR_MAP_DEFAULT_PATH) { // Load color layer if the color path is nonempty
7777
bool color_loaded = addColorFromGeotiff(color_map_path);
7878
}
7979
if (!loaded) return false;
@@ -84,7 +84,7 @@ bool GridMapGeo::initializeFromGdalDataset(const std::string &path) {
8484
GDALAllRegister();
8585
const auto dataset = GDALDatasetUniquePtr(GDALDataset::FromHandle(GDALOpen(path.c_str(), GA_ReadOnly)));
8686
if (!dataset) {
87-
std::cout << "Failed to open" << std::endl;
87+
std::cout << __func__ << "Failed to open '" << path << "'" << std::endl;
8888
return false;
8989
}
9090
std::cout << std::endl << "Loading GDAL Dataset for gridmap" << std::endl;
@@ -175,7 +175,7 @@ bool GridMapGeo::addColorFromGeotiff(const std::string &path) {
175175
GDALAllRegister();
176176
const auto dataset = GDALDatasetUniquePtr(GDALDataset::FromHandle(GDALOpen(path.c_str(), GA_ReadOnly)));
177177
if (!dataset) {
178-
std::cout << "Failed to open" << std::endl;
178+
std::cout << __func__ << "Failed to open '" << path << "'" << std::endl;
179179
return false;
180180
}
181181
std::cout << std::endl << "Loading color layer from GeoTIFF file for gridmap" << std::endl;
@@ -236,7 +236,7 @@ bool GridMapGeo::addLayerFromGeotiff(const std::string &layer_name, const std::s
236236
GDALAllRegister();
237237
const auto dataset = GDALDatasetUniquePtr(GDALDataset::FromHandle(GDALOpen(path.c_str(), GA_ReadOnly)));
238238
if (!dataset) {
239-
std::cout << "Failed to open" << std::endl;
239+
std::cout << __func__ << "Failed to open '" << path << "'" << std::endl;
240240
return false;
241241
}
242242
std::cout << std::endl << "Loading color layer from GeoTIFF file for gridmap" << std::endl;

src/map_publisher.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class MapPublisher : public rclcpp::Node {
5656
original_map_pub_ = this->create_publisher<grid_map_msgs::msg::GridMap>("elevation_map", 1);
5757
const std::string frame_id = this->declare_parameter("frame_id", "map");
5858
const std::string gdal_dataset_path = this->declare_parameter("gdal_dataset_path", ".");
59-
const std::string color_path = this->declare_parameter("tif_color_path", ".");
59+
const std::string color_path = this->declare_parameter("gdal_dataset_color_path", COLOR_MAP_DEFAULT_PATH);
6060
rcl_interfaces::msg::ParameterDescriptor max_map_descriptor;
6161
max_map_descriptor.read_only = true;
6262
max_map_descriptor.description =
@@ -76,8 +76,8 @@ class MapPublisher : public rclcpp::Node {
7676
std::clamp(this->declare_parameter("max_map_height", 1024, max_map_descriptor),
7777
max_map_descriptor_int_range.from_value, max_map_descriptor_int_range.to_value);
7878

79-
RCLCPP_INFO_STREAM(get_logger(), "file_path " << gdal_dataset_path);
80-
RCLCPP_INFO_STREAM(get_logger(), "color_path " << color_path);
79+
RCLCPP_INFO_STREAM(get_logger(), "gdal_dataset_path: '" << gdal_dataset_path << "'");
80+
RCLCPP_INFO_STREAM(get_logger(), "gdal_dataset_color_path: '" << color_path << "'");
8181
tf_broadcaster_ = std::make_shared<tf2_ros::StaticTransformBroadcaster>(this);
8282

8383
map_ = std::make_shared<GridMapGeo>(frame_id);

0 commit comments

Comments
 (0)