Skip to content

Commit 895e2a2

Browse files
authored
Merge pull request #22 from WATonomous/feature/object-detector-integration
Add basic water bottle and hammer object detection
2 parents c02d71e + 682114a commit 895e2a2

File tree

20 files changed

+428
-19
lines changed

20 files changed

+428
-19
lines changed

docker/robot/robot.Dockerfile

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ FROM ${BASE_IMAGE} AS source
66
WORKDIR ${AMENT_WS}/src
77

88
RUN apt-get update && apt-get install -y curl \
9-
&& curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
9+
&& curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
1010

1111
# Copy in source code
12+
COPY src/robot/yolo_inference ./yolo_inference
13+
COPY src/robot/object_detection object_detection
1214
COPY src/robot/odometry_spoof odometry_spoof
1315
COPY src/robot/bringup_robot bringup_robot
1416
COPY src/robot/camera_fallback camera_fallback
@@ -19,7 +21,7 @@ COPY src/wato_msgs/drivetrain_msgs drivetrain_msgs
1921

2022
# Scan for rosdeps
2123
RUN apt-get update && apt-get install -y curl \
22-
&& curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
24+
&& curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
2325

2426
RUN apt-get -qq update && rosdep update && \
2527
(rosdep install --from-paths . --ignore-src -r -s \
@@ -33,7 +35,7 @@ FROM ${BASE_IMAGE} AS dependencies
3335
# Clean up and update apt-get, then update rosdep
3436

3537
RUN apt-get update && apt-get install -y curl \
36-
&& curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
38+
&& curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
3739

3840
RUN sudo apt-get clean && \
3941
sudo apt-get update && \
@@ -49,6 +51,7 @@ RUN apt-get -qq update && \
4951
apt-get -qq install -y --no-install-recommends ros-humble-librealsense2* || true
5052

5153
# Copy in source code from source stage
54+
COPY src/robot/object_detection object_detection
5255
WORKDIR ${AMENT_WS}
5356
COPY --from=source ${AMENT_WS}/src src
5457

@@ -64,12 +67,21 @@ FROM dependencies AS build
6467
# Clean up and update apt-get, then update rosdep
6568

6669
RUN apt-get update && apt-get install -y curl \
67-
&& curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
70+
&& curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
6871

6972
RUN sudo apt-get clean && \
7073
sudo apt-get update && \
7174
sudo rosdep update
7275

76+
RUN apt-get update && apt-get install -y \
77+
python3-pip \
78+
python3-dev \
79+
python3-setuptools \
80+
&& rm -rf /var/lib/apt/lists/*
81+
82+
RUN pip install onnxruntime
83+
RUN pip3 install "numpy<2.0"
84+
7385
# Build ROS2 packages
7486
WORKDIR ${AMENT_WS}
7587
RUN . /opt/ros/$ROS_DISTRO/setup.sh && \

scripts/add_robot_package.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@ if ! grep -Fq "${pkg}_node = Node(" "$LAUNCH_FILE"; then
3030
block_file=$(mktemp)
3131
printf '%s' "$block" > "$block_file"
3232
awk -v bf="$block_file" '
33-
$0 ~ /##[[:space:]]+LAUNCH[[:space:]]+NODES/ && !done {
34-
print
35-
while ((getline line < bf) > 0) print line
36-
close(bf); done=1; next
37-
}
38-
{ print }
33+
$0 ~ /^[[:space:]]*return[[:space:]]+ld/ && !done {
34+
while ((getline line < bf) > 0) print line
35+
close(bf); done=1
36+
}
37+
{ print }
3938
' "$LAUNCH_FILE" > "$tmp" && mv "$tmp" "$LAUNCH_FILE"
4039
rm -f "$block_file"
4140
echo "✓ Added node block to '$LAUNCH_FILE'"

src/gazebo/launch/mars_env.urdf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@
3131
<link name="water_bottle">
3232
<visual>
3333
<geometry>
34-
<mesh filename="https://raw.githubusercontent.com/WATonomous/wato_rover/master/src/gazebo/launch/water_bottle.stl" scale="0.1 0.1 0.1"/>
34+
<mesh filename="https://raw.githubusercontent.com/WATonomous/wato_rover/master/src/gazebo/launch/water_bottle.stl" scale="0.4 0.4 0.4"/>
3535
</geometry>
3636
<material name="water_blue">
3737
<color rgba="0.68 0.85 0.90 1"/>
3838
</material>
3939
</visual>
4040
<collision>
4141
<geometry>
42-
<mesh filename="https://raw.githubusercontent.com/WATonomous/wato_rover/master/src/gazebo/launch/water_bottle.stl" scale="0.1 0.1 0.1"/>
42+
<mesh filename="https://raw.githubusercontent.com/WATonomous/wato_rover/master/src/gazebo/launch/water_bottle.stl" scale="0.4 0.4 0.4"/>
4343
</geometry>
4444
</collision>
4545
</link>
@@ -54,15 +54,15 @@
5454
<link name="mallet">
5555
<visual>
5656
<geometry>
57-
<mesh filename="https://raw.githubusercontent.com/WATonomous/wato_rover/master/src/gazebo/launch/mallet.stl" scale="0.1 0.1 0.1"/>
57+
<mesh filename="https://raw.githubusercontent.com/WATonomous/wato_rover/master/src/gazebo/launch/mallet.stl" scale="0.4 0.4 0.4"/>
5858
</geometry>
5959
<material name="orange">
6060
<color rgba="1 0.4 0.0 1"/>
6161
</material>
6262
</visual>
6363
<collision>
6464
<geometry>
65-
<mesh filename="https://raw.githubusercontent.com/WATonomous/wato_rover/master/src/gazebo/launch/mallet.stl" scale="0.1 0.1 0.1"/>
65+
<mesh filename="https://raw.githubusercontent.com/WATonomous/wato_rover/master/src/gazebo/launch/mallet.stl" scale="0.4 0.4 0.4"/>
6666
</geometry>
6767
</collision>
6868
</link>

src/gazebo/launch/robot_env.sdf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@
327327
<geometry>
328328
<mesh>
329329
<uri>water_bottle.stl</uri>
330-
<scale>0.1 0.1 0.1</scale>
330+
<scale>0.4 0.4 0.4</scale>
331331
</mesh>
332332
</geometry>
333333
<material>
@@ -340,7 +340,7 @@
340340
<geometry>
341341
<mesh>
342342
<uri>water_bottle.stl</uri>
343-
<scale>0.1 0.1 0.1</scale>
343+
<scale>0.4 0.4 0.4</scale>
344344
</mesh>
345345
</geometry>
346346
<pose>0 0 0 0 0 3.14159</pose>
@@ -355,7 +355,7 @@
355355
<geometry>
356356
<mesh>
357357
<uri>mallet.stl</uri>
358-
<scale>0.1 0.1 0.1</scale>
358+
<scale>0.4 0.4 0.4</scale>
359359
</mesh>
360360
</geometry>
361361
<material>
@@ -368,7 +368,7 @@
368368
<geometry>
369369
<mesh>
370370
<uri>mallet.stl</uri>
371-
<scale>0.1 0.1 0.1</scale>
371+
<scale>0.4 0.4 0.4</scale>
372372
</mesh>
373373
</geometry>
374374
<pose>0 0 0 0 0 3.14159</pose>

src/gazebo/launch/water_bottle.stl

711 KB
Binary file not shown.

src/robot/bringup_robot/launch/robot.launch.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@
1010
def generate_launch_description():
1111
ld = LaunchDescription() # Begin building a launch description
1212

13+
yolo_pkg_share = get_package_share_directory("yolo_inference")
14+
default_model_path = os.path.join(yolo_pkg_share, "models", "yolov8.onnx")
15+
16+
model_path_arg = DeclareLaunchArgument(
17+
"model_path",
18+
default_value=default_model_path,
19+
description="Absolute path to the YOLO ONNX/PT weights file",
20+
)
21+
ld.add_action(model_path_arg)
22+
1323
#################### Odometry Spoof Node #####################
1424
odometry_spoof_node = Node(
1525
package='odometry_spoof',
@@ -57,4 +67,27 @@ def generate_launch_description():
5767
)
5868
ld.add_action(motor_speed_controller_node)
5969

60-
return ld
70+
#################### Object_detection Node #####################
71+
object_detection_node = Node(
72+
package='object_detection',
73+
name='object_detection_node',
74+
executable='object_detection_node',
75+
)
76+
ld.add_action(object_detection_node)
77+
78+
ld.add_action(
79+
Node(
80+
package="yolo_inference",
81+
executable="yolo_inference_node",
82+
name="yolo_inference_node",
83+
output="screen",
84+
parameters=[
85+
{
86+
"model_path": LaunchConfiguration("model_path"),
87+
"input_size": 640, # TODO: adjust DEPENDING on model needs 416, 512, etc
88+
}
89+
],
90+
remappings=[("/image", "/sim/realsense1/depth/image")],
91+
)
92+
)
93+
return ld
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
project(object_detection)
3+
4+
# Set compiler to use C++ 17 standard
5+
if(NOT CMAKE_CXX_STANDARD)
6+
set(CMAKE_CXX_STANDARD 17)
7+
endif()
8+
9+
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
10+
add_compile_options(-Wall -Wextra -Wpedantic)
11+
endif()
12+
13+
# Search for dependencies required for building this package
14+
find_package(ament_cmake REQUIRED) # ROS2 build tool
15+
find_package(rclcpp REQUIRED) # ROS2 C++ package
16+
17+
# Compiles source files into a library
18+
# A library is not executed, instead other executables can link
19+
# against it to access defined methods and classes.
20+
# We build a library so that the methods defined can be used by
21+
# both the unit test and ROS2 node executables.
22+
add_library(object_detection_lib
23+
src/object_detection_core.cpp)
24+
# Indicate to compiler where to search for header files
25+
target_include_directories(object_detection_lib
26+
PUBLIC include)
27+
# Add ROS2 dependencies required by package
28+
ament_target_dependencies(object_detection_lib
29+
rclcpp
30+
)
31+
32+
# Create ROS2 node executable from source files
33+
add_executable(object_detection_node src/object_detection_node.cpp)
34+
# Link to the previously built library to access object_detection classes and methods
35+
target_link_libraries(object_detection_node object_detection_lib)
36+
37+
# Copy executable to installation location
38+
install(TARGETS
39+
object_detection_node
40+
DESTINATION lib/${PROJECT_NAME})
41+
42+
# Copy launch and config files to installation location
43+
install(DIRECTORY
44+
config
45+
DESTINATION share/${PROJECT_NAME})
46+
47+
48+
ament_package()

src/robot/object_detection/config/params.yaml

Whitespace-only changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef PACKAGE_NAME_CORE_HPP_
2+
#define PACKAGE_NAME_CORE_HPP_
3+
4+
#include "rclcpp/rclcpp.hpp"
5+
6+
namespace robot
7+
{
8+
9+
class Object_detectionCore
10+
{
11+
public:
12+
explicit Object_detectionCore(const rclcpp::Logger &logger);
13+
14+
private:
15+
rclcpp::Logger logger_;
16+
};
17+
18+
} // namespace robot
19+
20+
#endif
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef PACKAGE_NAME_NODE_HPP_
2+
#define PACKAGE_NAME_NODE_HPP_
3+
4+
#include "rclcpp/rclcpp.hpp"
5+
#include "object_detection_core.hpp"
6+
7+
class Object_detectionNode : public rclcpp::Node
8+
{
9+
public:
10+
Object_detectionNode();
11+
12+
private:
13+
robot::Object_detectionCore object_detection_;
14+
};
15+
16+
#endif

0 commit comments

Comments
 (0)