Skip to content

Commit e309a86

Browse files
authored
Merge pull request #1 from midemig/rgb_layer
feat:add RGB layer from point proyection in image
2 parents 0cc2d8f + 8009ac3 commit e309a86

10 files changed

Lines changed: 356 additions & 14 deletions

File tree

local_navigation/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ find_package(grid_map_msgs REQUIRED)
2020
find_package(pcl_conversions REQUIRED)
2121
find_package(pcl_ros REQUIRED)
2222
find_package(nav_msgs REQUIRED)
23+
find_package(OpenCV REQUIRED)
24+
find_package(image_geometry REQUIRED)
2325

2426
set(dependencies
2527
rclcpp
@@ -34,6 +36,8 @@ set(dependencies
3436
pcl_conversions
3537
pcl_ros
3638
nav_msgs
39+
image_geometry
40+
OpenCV
3741
)
3842

3943
include_directories(
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
gridmap_updater_node:
22
ros__parameters:
33
use_sim_time: true
4+
camera_info_topic: /camera/color/camera_info
5+
# camera_info_topic: /zed2/zed_node/rgb/camera_info
6+
camera_topic: /camera/color/image_raw
7+
# camera_topic: /camera/semseg/image
8+
map_frame: map
9+
robot_frame: base_link
10+
# robot_frame: robot_base_link
11+
camera_frame: camera_color_optical_frame
12+
# camera_frame: zed2_left_camera_optical_frame
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
gridmap_updater_node:
2+
ros__parameters:
3+
use_sim_time: true
4+
camera_info_topic: /camera/color/camera_info
5+
camera_topic: /camera/color/image_raw
6+
# camera_topic: /camera/semseg/image
7+
map_frame: map
8+
robot_frame: base_link
9+
camera_frame: camera_color_optical_frame
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
gridmap_updater_node:
2+
ros__parameters:
3+
use_sim_time: true
4+
camera_info_topic: /zed2/zed_node/rgb/camera_info
5+
camera_topic: /zed2/zed_node/rgb/image_rect_color
6+
lidar_topic: /robot/front_laser/points
7+
map_frame: map
8+
robot_frame: robot_base_link
9+
camera_frame: zed2_left_camera_optical_frame

local_navigation/include/local_navigation/GridmapUpdaterNode.hpp

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <string>
1919
#include <memory>
2020

21+
#include <tuple>
22+
2123
#include "tf2_ros/buffer.h"
2224
#include "tf2_ros/transform_listener.h"
2325
#include "tf2_ros/transform_broadcaster.h"
@@ -31,6 +33,11 @@
3133

3234
#include "nav_msgs/msg/path.hpp"
3335
#include "sensor_msgs/msg/point_cloud2.hpp"
36+
#include "sensor_msgs/msg/camera_info.hpp"
37+
#include "sensor_msgs/msg/image.hpp"
38+
#include "image_geometry/pinhole_camera_model.hpp"
39+
40+
#include "opencv2/opencv.hpp"
3441

3542
#include "rclcpp/rclcpp.hpp"
3643

@@ -45,24 +52,41 @@ class GridmapUpdaterNode : public rclcpp::Node
4552
explicit GridmapUpdaterNode(const rclcpp::NodeOptions & options = rclcpp::NodeOptions());
4653

4754
private:
55+
void get_params();
4856
void init_gridmap();
4957
void reset_gridmap();
5058
void update_gridmap(
5159
const pcl::PointCloud<pcl::PointXYZ> & pc_map,
52-
const pcl::PointCloud<pcl::PointXYZ> & pc_robot);
60+
const pcl::PointCloud<pcl::PointXYZ> & pc_robot,
61+
const pcl::PointCloud<pcl::PointXYZ> & pc_camera);
5362
void publish_gridmap(const builtin_interfaces::msg::Time & stamp);
5463

5564
void init_colors();
5665

5766
rclcpp::Subscription<sensor_msgs::msg::PointCloud2>::SharedPtr pc_sub_;
5867
rclcpp::Subscription<nav_msgs::msg::Path>::SharedPtr path_sub_;
68+
rclcpp::Subscription<sensor_msgs::msg::CameraInfo>::SharedPtr subscription_info_;
69+
rclcpp::Subscription<sensor_msgs::msg::Image>::SharedPtr subscription_img_;
5970
rclcpp::Publisher<grid_map_msgs::msg::GridMap>::SharedPtr gridmap_pub_;
71+
rclcpp::Publisher<sensor_msgs::msg::Image>::SharedPtr img_pub_;
6072

6173
void pc_callback(sensor_msgs::msg::PointCloud2::UniquePtr pc_in);
6274
void path_callback(nav_msgs::msg::Path::UniquePtr path_in);
75+
void topic_callback_info(sensor_msgs::msg::CameraInfo::UniquePtr msg);
76+
void image_callback(sensor_msgs::msg::Image::UniquePtr msg);
77+
78+
std::tuple<float, int, int> get_point_color(pcl::PointXYZ point);
79+
80+
std::string map_frame_id_;
81+
std::string robot_frame_id_;
82+
std::string camera_frame_id_;
83+
std::string camera_info_topic_;
84+
std::string camera_topic_;
85+
std::string lidar_topic_;
86+
std::string path_topic_;
87+
88+
bool camera_info_received_ {false};
6389

64-
std::string map_frame_id_ {"map"};
65-
std::string robot_frame_id_ {"robot_base_link"};
6690
double resolution_gridmap_ {0.2};
6791
double size_x_ {100.0};
6892
double size_y_ {100.0};
@@ -76,10 +100,15 @@ class GridmapUpdaterNode : public rclcpp::Node
76100
std::shared_ptr<grid_map::GridMap> gridmap_;
77101
Eigen::MatrixXf em_;
78102
Eigen::MatrixXf tm_;
103+
Eigen::MatrixXf cm_;
79104

80105
tf2_ros::Buffer tf_buffer_;
81106
tf2_ros::TransformListener tf_listener_;
82107

108+
std::shared_ptr<image_geometry::PinholeCameraModel> camera_model_;
109+
110+
cv::Mat image_rgb_raw_;
111+
83112
float color_unknown_;
84113
float color_free_;
85114
float color_obstacle_;

local_navigation/launch/local_navigation.launch.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ def generate_launch_description():
4040
# prefix=['xterm -e gdb -ex run --args'],
4141
# prefix=['perf record --call-graph dwarf -o perf.data'],
4242
arguments=[],
43-
remappings=[
44-
('input_pc', '/robot/front_laser/points'),
45-
('input_path', '/path'),
46-
])
43+
remappings=[])
4744

4845
ld = LaunchDescription()
4946
ld.add_action(local_navigation_cmd)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Copyright 2024 Intelligent Robotics Lab
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import os
16+
17+
from ament_index_python.packages import get_package_share_directory
18+
19+
from launch import LaunchDescription
20+
from launch.actions import IncludeLaunchDescription
21+
from launch.launch_description_sources import PythonLaunchDescriptionSource
22+
23+
from launch_ros.actions import Node
24+
25+
26+
def generate_launch_description():
27+
pkg_dir = get_package_share_directory('local_navigation')
28+
param_file = os.path.join(pkg_dir, 'config', 'params_perro.yaml')
29+
30+
lidarslam_cmd = IncludeLaunchDescription(
31+
PythonLaunchDescriptionSource(os.path.join(
32+
get_package_share_directory('lidarslam'),
33+
'launch',
34+
'lidarslam_perro.launch.py')))
35+
36+
statictf_cmd = IncludeLaunchDescription(
37+
PythonLaunchDescriptionSource(os.path.join(
38+
get_package_share_directory('go2_description'),
39+
'launch',
40+
'robot.launch.py')))
41+
42+
43+
44+
local_navigation_cmd = Node(package='local_navigation',
45+
executable='local_navigation_program',
46+
output='screen',
47+
parameters=[param_file],
48+
# prefix=['xterm -e gdb -ex run --args'],
49+
# prefix=['perf record --call-graph dwarf -o perf.data'],
50+
arguments=[],
51+
remappings=[])
52+
53+
ld = LaunchDescription()
54+
ld.add_action(local_navigation_cmd)
55+
ld.add_action(lidarslam_cmd)
56+
ld.add_action(statictf_cmd)
57+
58+
return ld
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Copyright 2024 Intelligent Robotics Lab
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import os
16+
17+
from ament_index_python.packages import get_package_share_directory
18+
19+
from launch import LaunchDescription
20+
from launch.actions import IncludeLaunchDescription
21+
from launch.launch_description_sources import PythonLaunchDescriptionSource
22+
23+
from launch_ros.actions import Node
24+
25+
26+
def generate_launch_description():
27+
pkg_dir = get_package_share_directory('local_navigation')
28+
param_file = os.path.join(pkg_dir, 'config', 'params_summit.yaml')
29+
30+
lidarslam_cmd = IncludeLaunchDescription(
31+
PythonLaunchDescriptionSource(os.path.join(
32+
get_package_share_directory('lidarslam'),
33+
'launch',
34+
'lidarslam_summit.launch.py')))
35+
36+
local_navigation_cmd = Node(package='local_navigation',
37+
executable='local_navigation_program',
38+
output='screen',
39+
parameters=[param_file],
40+
# prefix=['xterm -e gdb -ex run --args'],
41+
# prefix=['perf record --call-graph dwarf -o perf.data'],
42+
arguments=[],
43+
remappings=[])
44+
45+
ld = LaunchDescription()
46+
ld.add_action(local_navigation_cmd)
47+
ld.add_action(lidarslam_cmd)
48+
49+
return ld

local_navigation/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<depend>pcl_conversions</depend>
2121
<depend>pcl_ros</depend>
2222
<depend>nav_msgs</depend>
23+
<depend>image_geometry</depend>
2324

2425
<test_depend>ament_lint_auto</test_depend>
2526
<test_depend>ament_lint_common</test_depend>

0 commit comments

Comments
 (0)