Skip to content

Commit 45761cb

Browse files
authored
Merge pull request #2 from Yadunund/yadu/update_interfaces
Update interfaces
2 parents b461c68 + 33e17fe commit 45761cb

File tree

12 files changed

+198
-88
lines changed

12 files changed

+198
-88
lines changed

.github/workflows/build.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: build
2+
on:
3+
pull_request:
4+
push:
5+
branches: [ main ]
6+
defaults:
7+
run:
8+
shell: bash
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
timeout-minutes: 30
13+
steps:
14+
-
15+
name: Checkout
16+
uses: actions/checkout@v4
17+
-
18+
name: Set up Docker Buildx
19+
uses: docker/setup-buildx-action@v3
20+
-
21+
name: Build
22+
uses: docker/build-push-action@v6
23+
with:
24+
file: Dockerfile.estimator
25+
load: true
26+
tags: ${{ env.TEST_TAG }}

.github/workflows/style.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: style
2+
on:
3+
pull_request:
4+
push:
5+
branches: [ main ]
6+
defaults:
7+
run:
8+
shell: bash
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
distro: ['jazzy']
16+
container:
17+
image: ros:${{ matrix.distro }}-ros-base
18+
timeout-minutes: 30
19+
steps:
20+
- uses: actions/checkout@v4
21+
- name: uncrustify
22+
run: /ros_entrypoint.sh ament_uncrustify ./
23+
- name: cpplint
24+
run: /ros_entrypoint.sh ament_cpplint ./

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
models/

Dockerfile.estimator

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ ENV RMW_IMPLEMENTATION=rmw_zenoh_cpp
1010
# underlay stage: base + dependencies built
1111
FROM base AS underlay
1212

13+
ARG MODEL_DIR=models
14+
1315
ADD ibpc_interfaces /opt/ros/underlay/src/ibpc_interfaces
1416

1517
RUN . /opt/ros/jazzy/setup.sh \
@@ -20,6 +22,8 @@ RUN . /opt/ros/jazzy/setup.sh \
2022
--event-handlers=console_direct+ \
2123
--merge-install
2224

25+
ADD ${MODEL_DIR} /opt/ros/underlay/install/models
26+
2327
FROM underlay AS overlay
2428

2529
# TODO(Yadunund): Remove this step after next Jazzy sync.
@@ -47,7 +51,6 @@ FROM base
4751

4852
ARG SERVICE_PACKAGE=ibpc_pose_estimator
4953
ARG SERVICE_EXECUTABLE_NAME=ibpc_pose_estimator
50-
ARG MODEL_PATH=/tmp
5154
ARG SERVICE_NAME=/get_pose_estimates
5255

5356
RUN apt update \
@@ -65,15 +68,12 @@ COPY --from=overlay /opt/ros/overlay/install /opt/ros/overlay/install
6568
RUN sed --in-place \
6669
--expression '$isource "/opt/ros/overlay/install/setup.bash"' \
6770
/ros_entrypoint.sh
68-
# && sed --in-place \
69-
# --expression '$isource "/opt/ros/overlay/install/setup.bash"' \
70-
# /ros_entrypoint.sh
7171

7272
ENV SERVICE_PACKAGE=${SERVICE_PACKAGE}
7373
ENV SERVICE_EXECUTABLE_NAME=${SERVICE_EXECUTABLE_NAME}
74-
ENV MODEL_PATH=${MODEL_PATH}
74+
ENV MODEL_DIR=/opt/ros/underlay/install/models
7575
ENV SERVICE_NAME=${SERVICE_NAME}
7676

7777
CMD exec /opt/ros/overlay/install/lib/${SERVICE_PACKAGE}/${SERVICE_EXECUTABLE_NAME} \
78-
--ros-args -p model_path:=${MODEL_PATH} \
78+
--ros-args -p model_dir:=${MODEL_DIR} \
7979
-p service_name:=${SERVICE_NAME}

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Industrial Bin Picking Challenge (IBPC)
22

3+
[![build](https://github.com/Yadunund/ibpc/actions/workflows/build.yaml/badge.svg?branch=main)](https://github.com/Yadunund/ibpc/actions/workflows/build.yaml)
4+
[![style](https://github.com/Yadunund/ibpc/actions/workflows/style.yaml/badge.svg?branch=main)](https://github.com/Yadunund/ibpc/actions/workflows/style.yaml)
5+
36
For more details on the challenge, [click here](https://bpc.opencv.org/).
47

58
## Design
@@ -26,6 +29,7 @@ git clone https://github.com/Yadunund/ibpc.git
2629
### On Ubuntu 24.04
2730
```bash
2831
cd ~/ws_ibpc/
32+
sudo apt update && sudo apt install ros-jazzy-rmw-zenoh-cpp
2933
rosdep update
3034
rosdep install --from-paths src --ignore-src --rosdistro jazzy -y
3135
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release
@@ -34,7 +38,15 @@ colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release
3438
### With Docker
3539
```bash
3640
cd ~/ws_ibpc/src/ibpc
37-
docker buildx build -t ibpc:pose_estimator --file ./Dockerfile.estimator .
41+
docker buildx build -t ibpc:pose_estimator \
42+
--file ./Dockerfile.estimator \
43+
--build-arg="MODEL_DIR=models" \
44+
.
45+
```
46+
47+
## Start the Zenoh router
48+
```bash
49+
docker run --init --rm --net host eclipse/zenoh:1.1.1 --no-multicast-scouting
3850
```
3951

4052
## Run the pose estimator
@@ -43,17 +55,19 @@ docker buildx build -t ibpc:pose_estimator --file ./Dockerfile.estimator .
4355
```bash
4456
cd ~/ws_ibpc/
4557
source install/setup.bash
46-
ros2 run ibpc_pose_estimator ibpc_pose_estimator --ros-args -p model_path:=<PATH>
58+
export RMW_IMPLEMENTATION=rmw_zenoh_cpp
59+
ros2 run ibpc_pose_estimator ibpc_pose_estimator --ros-args -p model_dir:=<PATH>
4760
```
4861

4962
### With Docker
5063
```bash
51-
docker run --network=host ibpc:pose_estimator -e MODEL_PATH=<PATH>
64+
docker run --network=host ibpc:pose_estimator
5265
```
5366

5467
## Query the pose estimator
5568
```bash
5669
cd ~/ws_ibpc/
5770
source install/setup.bash
71+
export RMW_IMPLEMENTATION=rmw_zenoh_cpp
5872
ros2 service call /get_pose_estimates ibpc_interfaces/srv/GetPoseEstimates '{}'
5973
```
Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
# ID of the scene.
2-
uint64 scene_id
3-
4-
# ID of the image.
5-
uint64 im_id
6-
71
# ID of the object.
82
uint64 obj_id
93

@@ -18,10 +12,3 @@ float64 score
1812

1913
# 6D pose of object.
2014
geometry_msgs/PoseStamped pose
21-
22-
# The time the method took to estimate poses for all objects in image im_id
23-
# from scene scene_id. All estimates with the same scene_id and im_id must have
24-
# the same value of time. Report the wall time from the point right after the
25-
# raw data (the image, 3D object models etc.) is loaded to the point when the
26-
# final pose estimates are available.
27-
builtin_interfaces/Time time

ibpc_interfaces/srv/GetPoseEstimates.srv

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
# Request
22

3-
sensor_msgs/CameraInfo camera_info
4-
sensor_msgs/Image rgb_image
5-
sensor_msgs/Image depth_image
3+
# List of object IDs to look for in the scene.
4+
uint64[] object_ids
5+
6+
# Scene images.
7+
sensor_msgs/CameraInfo rgb_info
8+
sensor_msgs/Image rgb
9+
sensor_msgs/CameraInfo depth_info
10+
sensor_msgs/Image depth
11+
sensor_msgs/CameraInfo polarized_info
12+
sensor_msgs/Image polarized
613

714
---
815

ibpc_pose_estimator/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ endif()
77

88
# find packages.
99
find_package(ament_cmake REQUIRED)
10+
find_package(cv_bridge REQUIRED)
1011
find_package(ibpc_interfaces REQUIRED)
12+
find_package(image_geometry REQUIRED)
1113
find_package(rclcpp REQUIRED)
1214
find_package(rclcpp_components REQUIRED)
1315

@@ -16,6 +18,8 @@ add_library(ibpc_pose_estimator_component SHARED src/ibpc_pose_estimator.cpp)
1618

1719
target_link_libraries(ibpc_pose_estimator_component
1820
PUBLIC
21+
cv_bridge::cv_bridge
22+
image_geometry::image_geometry
1923
rclcpp::rclcpp
2024
rclcpp_components::component
2125
${ibpc_interfaces_TARGETS}

ibpc_pose_estimator/package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
<buildtool_depend>ament_cmake</buildtool_depend>
1111

12+
<depend>cv_bridge</depend>
1213
<depend>ibpc_interfaces</depend>
14+
<depend>image_geometry</depend>
1315
<depend>rclcpp</depend>
1416
<depend>rclcpp_components</depend>
1517

Lines changed: 65 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,93 @@
1-
// TODO: Copyright.
1+
// TODO(Yadunund): Copyright.
22

33
#include "ibpc_pose_estimator.hpp"
44

5+
#include <exception>
6+
#include <string>
7+
#include <utility>
8+
59
#include "rclcpp/rclcpp.hpp"
610

7-
#include <exception>
11+
#include "sensor_msgs/msg/camera_info.hpp"
812

9-
namespace ibpc {
13+
namespace ibpc
14+
{
1015

1116
//==================================================================================================
1217
PoseEstimator::PoseEstimator(const rclcpp::NodeOptions & options)
1318
: Node("ibpc_pose_estimator", options)
1419
{
15-
RCLCPP_INFO(
16-
this->get_logger(),
17-
"Starting ibpc_pose_estimator..."
18-
);
19-
// Get the path to the model.
20-
std::string path_str = this->declare_parameter("model_path", "");
21-
if (path_str.empty()) {
22-
throw std::runtime_error("ROS param model_path cannot be empty!");
23-
}
24-
RCLCPP_INFO(
25-
this->get_logger(),
26-
"Loading model from path [ %s ].",
27-
path_str.c_str()
28-
);
29-
std::filesystem::path model_path{std::move(path_str)};
30-
// Load the model.
31-
if (!this->load_model(model_path)) {
32-
throw std::runtime_error("Failed to load model.");
33-
} else {
34-
RCLCPP_INFO(
35-
this->get_logger(),
36-
"Model successfully loaded!"
37-
);
38-
}
39-
std::string srv_name =
40-
this->declare_parameter("service_name", "/get_pose_estimates");
41-
RCLCPP_INFO(
42-
this->get_logger(),
43-
"Pose estimates can be queried at %s.",
44-
srv_name.c_str()
45-
);
46-
srv_ = this->create_service<GetPoseEstimates>(
47-
std::move(srv_name),
48-
[this](std::shared_ptr<const GetPoseEstimates::Request> request,
49-
std::shared_ptr<GetPoseEstimates::Response> response)
50-
{
51-
response->pose_estimates = this->get_pose_estimates(std::move(request));
52-
}
53-
);
20+
RCLCPP_INFO(
21+
this->get_logger(),
22+
"Starting ibpc_pose_estimator..."
23+
);
24+
// Get the path to the model.
25+
std::string path_str = this->declare_parameter("model_dir", "");
26+
if (path_str.empty()) {
27+
throw std::runtime_error("ROS param model_dir cannot be empty!");
28+
}
29+
RCLCPP_INFO(
30+
this->get_logger(),
31+
"Model directory set to [ %s ].",
32+
path_str.c_str()
33+
);
34+
model_dir_ = std::filesystem::path(std::move(path_str));
35+
36+
std::string srv_name =
37+
this->declare_parameter("service_name", "/get_pose_estimates");
38+
RCLCPP_INFO(
39+
this->get_logger(),
40+
"Pose estimates can be queried over srv %s.",
41+
srv_name.c_str()
42+
);
43+
srv_ = this->create_service<GetPoseEstimates>(
44+
std::move(srv_name),
45+
[this](std::shared_ptr<const GetPoseEstimates::Request> request,
46+
std::shared_ptr<GetPoseEstimates::Response> response)
47+
{
48+
cv_bridge::CvImageConstPtr rgb = cv_bridge::toCvShare(request->rgb, request);
49+
this->rgb_camera_model_.fromCameraInfo(request->rgb_info);
50+
cv_bridge::CvImageConstPtr depth = cv_bridge::toCvShare(request->depth, request);
51+
this->depth_camera_model_.fromCameraInfo(request->depth_info);
52+
cv_bridge::CvImageConstPtr polarized = cv_bridge::toCvShare(request->polarized, request);
53+
this->polarized_camera_model_.fromCameraInfo(request->polarized_info);
54+
response->pose_estimates = this->get_pose_estimates(
55+
request->object_ids,
56+
rgb->image,
57+
this->rgb_camera_model_,
58+
depth->image,
59+
this->depth_camera_model_,
60+
polarized->image,
61+
this->polarized_camera_model_);
62+
}
63+
);
5464
}
5565

5666
//==================================================================================================
57-
bool PoseEstimator::load_model(const std::filesystem::path & model_path)
67+
const std::filesystem::path & PoseEstimator::model_dir() const
5868
{
59-
// Fill.
60-
return true;
69+
return model_dir_;
6170
}
6271

6372
//==================================================================================================
6473
auto PoseEstimator::get_pose_estimates(
65-
std::shared_ptr<const GetPoseEstimates::Request> request) -> std::vector<PoseEstimate>
74+
const std::vector<uint64_t> & object_ids,
75+
const cv::Mat & rgb,
76+
const image_geometry::PinholeCameraModel & rgb_camera_model,
77+
const cv::Mat & depth,
78+
const image_geometry::PinholeCameraModel & depth_camera_model,
79+
const cv::Mat & polarized,
80+
const image_geometry::PinholeCameraModel & polarized_camera_model) -> std::vector<PoseEstimate>
6681
{
67-
std::vector<PoseEstimate> pose_estimates = {};
82+
std::vector<PoseEstimate> pose_estimates = {};
6883

69-
// Fill.
84+
// Fill.
7085

71-
return pose_estimates;
86+
return pose_estimates;
7287
}
7388

7489
} // namespace ibpc
7590

7691
//==================================================================================================
7792
#include <rclcpp_components/register_node_macro.hpp>
78-
RCLCPP_COMPONENTS_REGISTER_NODE(ibpc::PoseEstimator)
93+
RCLCPP_COMPONENTS_REGISTER_NODE(ibpc::PoseEstimator)

0 commit comments

Comments
 (0)