-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from WATonomous/j89leung/depth-estimation-star…
…ter-node Add depth estimation ROS 2 node starter code
- Loading branch information
Showing
10 changed files
with
220 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
docker/perception/depth_estimation/depth_estimation.Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
ARG BASE_IMAGE=ghcr.io/watonomous/wato_monorepo/base:humble-ubuntu22.04 | ||
|
||
################################ Source ################################ | ||
FROM ${BASE_IMAGE} as source | ||
|
||
WORKDIR ${AMENT_WS}/src | ||
|
||
# Copy in source code | ||
COPY src/perception/depth_estimation depth_estimation | ||
|
||
# Scan for rosdeps | ||
RUN apt-get -qq update && rosdep update && \ | ||
rosdep install --from-paths . --ignore-src -r -s \ | ||
| grep 'apt-get install' \ | ||
| awk '{print $3}' \ | ||
| sort > /tmp/colcon_install_list | ||
|
||
################################# Dependencies ################################ | ||
FROM ${BASE_IMAGE} as dependencies | ||
|
||
# Install Rosdep requirements | ||
COPY --from=source /tmp/colcon_install_list /tmp/colcon_install_list | ||
RUN apt-fast install -qq -y --no-install-recommends $(cat /tmp/colcon_install_list) | ||
|
||
# Copy in source code from source stage | ||
WORKDIR ${AMENT_WS} | ||
COPY --from=source ${AMENT_WS}/src src | ||
|
||
# Dependency Cleanup | ||
WORKDIR / | ||
RUN apt-get -qq autoremove -y && apt-get -qq autoclean && apt-get -qq clean && \ | ||
rm -rf /root/* /root/.ros /tmp/* /var/lib/apt/lists/* /usr/share/doc/* | ||
|
||
################################ Build ################################ | ||
FROM dependencies as build | ||
|
||
# Build ROS2 packages | ||
WORKDIR ${AMENT_WS} | ||
RUN . /opt/ros/$ROS_DISTRO/setup.sh && \ | ||
colcon build \ | ||
--cmake-args -DCMAKE_BUILD_TYPE=Release | ||
|
||
# Entrypoint will run before any CMD on launch. Sources ~/opt/<ROS_DISTRO>/setup.bash and ~/ament_ws/install/setup.bash | ||
COPY docker/wato_ros_entrypoint.sh ${AMENT_WS}/wato_ros_entrypoint.sh | ||
ENTRYPOINT ["./wato_ros_entrypoint.sh"] | ||
|
||
################################ Prod ################################ | ||
FROM build as deploy | ||
|
||
# Source Cleanup and Security Setup | ||
RUN chown -R $USER:$USER ${AMENT_WS} | ||
RUN rm -rf src/* | ||
|
||
USER ${USER} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
project(depth_estimation) | ||
|
||
# Default to C++14 | ||
if(NOT CMAKE_CXX_STANDARD) | ||
set(CMAKE_CXX_STANDARD 14) | ||
endif() | ||
|
||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") | ||
add_compile_options(-Wall -Wextra -Wpedantic) | ||
endif() | ||
|
||
find_package(ament_cmake REQUIRED) | ||
find_package(rclcpp REQUIRED) | ||
find_package(sensor_msgs REQUIRED) | ||
|
||
include_directories(include) | ||
|
||
add_executable(depth_estimation_node src/depth_estimation_node.cpp) | ||
ament_target_dependencies(depth_estimation_node rclcpp sensor_msgs) | ||
|
||
install(TARGETS | ||
depth_estimation_node | ||
DESTINATION lib/${PROJECT_NAME}) | ||
|
||
install(DIRECTORY | ||
launch | ||
DESTINATION share/${PROJECT_NAME} | ||
) | ||
|
||
install(DIRECTORY | ||
config | ||
DESTINATION share/${PROJECT_NAME} | ||
) | ||
|
||
ament_package() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
depth_estimation_node: | ||
ros__parameters: | ||
camera_topic: "/camera/left/image_color" | ||
depth_map_topic: "/depth_map" | ||
debug_node: false |
22 changes: 22 additions & 0 deletions
22
src/perception/depth_estimation/include/depth_estimation_node.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#ifndef DEPTH_ESTIMATION_NODE_HPP_ | ||
#define DEPTH_ESTIMATION_NODE_HPP_ | ||
|
||
#include "rclcpp/rclcpp.hpp" | ||
#include "sensor_msgs/msg/image.hpp" | ||
|
||
class DepthEstimationNode : public rclcpp::Node { | ||
public: | ||
DepthEstimationNode(); | ||
|
||
private: | ||
void image_callback(const sensor_msgs::msg::Image::SharedPtr msg); | ||
|
||
std::string camera_topic_; | ||
std::string depth_map_topic_; | ||
bool debug_node_; | ||
|
||
rclcpp::Subscription<sensor_msgs::msg::Image>::SharedPtr image_subscription_; | ||
rclcpp::Publisher<sensor_msgs::msg::Image>::SharedPtr depth_image_publisher_; | ||
}; | ||
|
||
#endif // DEPTH_ESTIMATION_NODE_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from launch import LaunchDescription | ||
from launch_ros.actions import Node | ||
from ament_index_python.packages import get_package_share_directory | ||
import os | ||
|
||
|
||
def generate_launch_description(): | ||
ld = LaunchDescription() | ||
config = os.path.join( | ||
get_package_share_directory('depth_estimation'), | ||
'config', | ||
'config.yaml' | ||
) | ||
|
||
depth_estimation_node = Node( | ||
package='depth_estimation', | ||
executable='depth_estimation_node', | ||
name='depth_estimation_node', | ||
parameters=[config], | ||
arguments=['--ros-args', '--log-level', 'info'] | ||
) | ||
|
||
ld.add_action(depth_estimation_node) | ||
|
||
return ld |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0"?> | ||
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
<package format="3"> | ||
<name>depth_estimation</name> | ||
<version>0.0.0</version> | ||
<description>Depth estimation ROS 2 node</description> | ||
<maintainer email="[email protected]">TBD</maintainer> | ||
<license>TODO: License declaration</license> | ||
|
||
<buildtool_depend>ament_cmake</buildtool_depend> | ||
|
||
|
||
<export> | ||
<build_type>ament_cmake</build_type> | ||
</export> | ||
</package> |
39 changes: 39 additions & 0 deletions
39
src/perception/depth_estimation/src/depth_estimation_node.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "depth_estimation_node.hpp" | ||
#include "sensor_msgs/msg/image.hpp" | ||
|
||
DepthEstimationNode::DepthEstimationNode() : Node("depth_estimation_node") { | ||
this->declare_parameter<std::string>("camera_topic", "/camera/image_raw"); | ||
this->declare_parameter<std::string>("depth_map_topic", "/depth/image_raw"); | ||
this->declare_parameter<bool>("deubg_node", false); | ||
|
||
this->get_parameter("camera_topic", camera_topic_); | ||
this->get_parameter("depth_map_topic", depth_map_topic_); | ||
this->get_parameter("debug_node", debug_node_); | ||
|
||
RCLCPP_INFO(this->get_logger(), "debug_node: %s", debug_node_ ? "true" : "false"); | ||
|
||
RCLCPP_INFO(this->get_logger(), "Subscribing to camera topic '%s'", camera_topic_.c_str()); | ||
image_subscription_ = this->create_subscription<sensor_msgs::msg::Image>( | ||
camera_topic_, 10, | ||
std::bind(&DepthEstimationNode::image_callback, this, std::placeholders::_1)); | ||
|
||
RCLCPP_INFO(this->get_logger(), "Publishing depth map to topic '%s'", depth_map_topic_.c_str()); | ||
depth_image_publisher_ = this->create_publisher<sensor_msgs::msg::Image>(depth_map_topic_, 10); | ||
} | ||
|
||
void DepthEstimationNode::image_callback(const sensor_msgs::msg::Image::SharedPtr msg) { | ||
RCLCPP_INFO(this->get_logger(), "Received sensor image on '%s'", camera_topic_.c_str()); | ||
|
||
// TODO: Process the incoming image and estimate depth | ||
// Replace this empty image with the actual depth map | ||
auto depth_map_image = sensor_msgs::msg::Image(); | ||
depth_image_publisher_->publish(depth_map_image); | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
rclcpp::init(argc, argv); | ||
auto node = std::make_shared<DepthEstimationNode>(); | ||
rclcpp::spin(node); | ||
rclcpp::shutdown(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters