Skip to content

Commit

Permalink
Merge pull request #32 from UBCAgroBot/feature/25-mvp-integration
Browse files Browse the repository at this point in the history
Feature/25 mvp integration
  • Loading branch information
Ishaan-Datta authored Nov 6, 2024
2 parents 5833fce + 0aedd7a commit 726cdd0
Show file tree
Hide file tree
Showing 16 changed files with 800 additions and 301 deletions.
3 changes: 3 additions & 0 deletions workspace_python/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/build/
/install/
/log/
11 changes: 7 additions & 4 deletions workspace_python/ros2_ws/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
build/
install/
log/
*.onnx
build/
install/
log/
datasets/

*.onnx
*.pt
38 changes: 38 additions & 0 deletions workspace_python/ros2_ws/src/custom_interfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
cmake_minimum_required(VERSION 3.8)
project(custom_interfaces)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(sensor_msgs REQUIRED)


rosidl_generate_interfaces(${PROJECT_NAME}
"msg/ImageInput.msg"
"msg/InferenceOutput.msg"
"srv/GetOriginalImage.srv"
DEPENDENCIES sensor_msgs

)


if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# comment the line when a copyright and license is added to all source files
set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# comment the line when this package is in a git repo and when
# a copyright and license is added to all source files
set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()

ament_package()
55 changes: 55 additions & 0 deletions workspace_python/ros2_ws/src/custom_interfaces/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

# Custom Interfaces in ROS2

This interface uses the ROS2 tutorial on custom interfaces:
[ROS2 Custom Interfaces Tutorial](https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Custom-ROS2-Interfaces.html)

Instructions to use the custom message or services can be found here:
[ROS2 Custom Interfaces Tutorial](https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Custom-ROS2-Interfaces.html)


Custom message
type name description
x-velocity int64 x-velocity of the camera
b-box int64 array array of bounding boxes



## Re building the custom message interface
```sh
colcon build --packages-select custom_interfaces
```

## Fun ROS2 Commands

### Show All Messages and Services
Use the `-m` flag to show only messages:
```sh
ros2 interface list
```

### Show Message and Service Definitions
```sh
ros2 interface show custom_interfaces/msg/Custom
```

### Topic Commands
```sh
### Topic Commands
List all active topics:
```sh
ros2 topic list
```

Show information about a specific topic:
```sh
ros2 topic info /topic_name
```

Echo messages from a specific topic:
```sh
ros2 topic echo /topic_name
```

### Troubleshooting
If you get "the message type `custom_interface/msg/Custom` is invalid", source the ROS2 install/setup.bash and try to run the commands again.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
std_msgs/Header header
sensor_msgs/Image raw_image
float32 velocity
sensor_msgs/Image preprocessed_image
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
std_msgs/Header header #header should have the ID
int64 num_boxes
std_msgs/Float32MultiArray bounding_boxes
std_msgs/Float32MultiArray confidences
sensor_msgs/Image raw_image
float32 velocity
sensor_msgs/Image preprocessed_image
25 changes: 25 additions & 0 deletions workspace_python/ros2_ws/src/custom_interfaces/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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>custom_interfaces</name>
<version>0.0.0</version>
<description>TODO: Package description</description>
<maintainer email="[email protected]">valery</maintainer>
<license>TODO: License declaration</license>

<buildtool_depend>ament_cmake</buildtool_depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>


<build_depend>rosidl_default_generators</build_depend>

<exec_depend>rosidl_default_runtime</exec_depend>
<exec_depend>sensor_msgs</exec_depend>

<member_of_group>rosidl_interface_packages</member_of_group>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
string image_id # to make sure the image is correctly received
---
sensor_msgs/Image original_image
float32 velocity
88 changes: 82 additions & 6 deletions workspace_python/ros2_ws/src/python_workspace/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,82 @@
Running the camera node:
ros2 run python_workspace camera_node --ros-args -p static_image_path:='/home/user/Desktop/ROS/Models/Maize Model/sample_maize_images' -p loop:=-1 -p frame_rate:=10 -p model_dimensions:=[640,640]

ros2 run python_workspace jetson_node

ros2 run python_workspace extermination_node

### List of Nodes

| Node Type | Subscribes To | Publishes To | Example command |
|-------------------|----------------|-----------------------------------|------|
| Picture Node | - | `/input_image` | `ros2 run python_workspace picture_node --ros-args -p static_image_path:='./../assets/maize' -p loop:=-1 -p frame_rate:=1`|
| Inference Node | `/input_image` | -`/inference_out` <br> - `/output_img` | `ros2 run python_workspace inference_node --ros-args -p weights_path:='../models/maize/Maize.pt'`|
| Extermination Node | `/inference_out` | external binary | `ros2 run python_workspace extermination_node`|


### List of Topics and Data Types

| Topic Name | Description | Data Type |
|-----------------------------|--------------------------------------|--------------------|
| `/input_image` | custom msg that sends raw image, processed image and velocity | `custom_interface/msg/ImageInput`|
| `/inference_out` | custom msg that passes inference output and raw image to extermination node | `custom_interface/msg/InferenceOutput` |
| `/output_img` | Processed output image | `sensor_msgs/Image`|



### Other commands
#### Running the camera node:
`ros2 run python_workspace camera_node --ros-args -p static_image_path:='/home/user/Desktop/ROS/Models/Maize Model/sample_maize_images' -p loop:=-1 -p frame_rate:=10 -p model_dimensions:=[640,640]`

#### Running the jetson_node
ros2 run python_workspace jetson_node

#### Running the extermination node
```ros2 run python_workspace extermination_node```

Without any additional arguments, this will also show a window with the drawn bounding boxes.
To turn it off,
add the argument `--ros-args -p use_display_node:=false` to the command.
#### Running the picture node:
File paths are relative to the working directory

`ros2 run python_workspace picture_node --ros-args -p static_image_path:='./../assets/maize' -p loop:=-1 -p frame_rate:=1`

#### Running the inference node:

The path for weights (.pt) is relative to the ROS/workspace_python/ros2_ws directory.


```bash
ros2 run python_workspace inference_node --ros-args -p weights_path:='../models/maize/Maize.pt'
```

### Compiling new Changes
```bash
colcon build --packages-select custom_interface python_workspace
source install/setup.bash
```

### using RQT to view
#### Installing RQT on ROS 2 Humble

To install RQT and its plugins on ROS 2 Humble, use the following command:

```bash
sudo apt update
sudo apt install ~nros-humble-rqt*
```

This command will install RQT along with all available plugins for ROS 2 Humble.

#### Running RQT

To start RQT, simply run:

```bash
rqt
```

You can now use RQT to visualize and interact with various ROS topics and nodes.

To view the image topic :

1. go to plugins/visualization/image view. a new box will open up
2. click refresh topic
3. select the name of the image topic you want to see


2 changes: 2 additions & 0 deletions workspace_python/ros2_ws/src/python_workspace/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<test_depend>ament_pep257</test_depend>
<test_depend>python3-pytest</test_depend>

<exec_depend>custom_interfaces</exec_depend>

<export>
<build_type>ament_python</build_type>
</export>
Expand Down
Loading

0 comments on commit 726cdd0

Please sign in to comment.