A ROS 2 based autonomous robot using ultrasonic sensor-guided navigation, encoder-assisted localization, and a TensorFlow Lite machine learning model to identify crop diseases and collect environmental data for use in a greenhouse.
The following components were used for the robot assembly:
Item No. | Part Name | Quantity | Unit Price | Total Price |
---|---|---|---|---|
1 | Raspberry Pi 4 (4 GB) | 1 | DKK529.00 | DKK529.00 |
2 | SanDisk SD Card (32 GB) | 1 | DKK99.00 | DKK99.00 |
3 | Two-wheel drive with tracks robot chassis kit (with DC motors and wheel encoders) | 1 | DKK674.61 | DKK674.61 |
4 | L298N Motor Driver | 1 | DKK149.00 | DKK149.00 |
5 | HC-SR04 Ultrasonic Distance Sensor | 3 | DKK48.75 | DKK146.25 |
6 | Raspberry Pi Camera Board v1.3 (5MP, 1080p) | 1 | DKK99.00 | DKK99.00 |
7 | SCD30 (CO2, Humidity and Temperature Sensor) | 1 | DKK746.46 | DKK746.25 |
8 | Zeee 2S Lipo Battery 5200 mAh 5200 mAh 7.4 V | 1 | DKK172.00 | DKK172.00 |
9 | Powerbank for Raspberry Pi 4 (minimum output: 5V 3A) | 1 | N/A | N/A |
10 | Capacitor Electrolytic 10uF 25V | 2 | N/A | N/A |
11 | Resistor 330Ω | 3 | N/A | N/A |
12 | Resistor 470Ω | 3 | N/A | N/A |
13 | 5V Voltage Divider | 1 | N/A | N/A |
14 | 3D printed mount stands for ultrasonic sensors | 3 | N/A | N/A |
15 | 3D printed mount stand for camera | 1 | N/A | N/A |
16 | Breadboard | 1 | N/A | N/A |
17 | Mounting screws | N/A | N/A | N/A |
18 | Spare wires | N/A | N/A | N/A |
19 | Female to Female jumper cables | N/A | N/A | N/A |
Total | DKK2.616 + N/A |
Additional tools or parts used in the project:
Tool/Part | |
---|---|
1 | 3D Printer |
2 | Tape |
1 | Screwdriver set |
1 | Double-sided tape |
The electronic components and the complete circuit of the robot were connected as shown below in:
The HC-SR04 ultrasonic sensors were connected to the Raspberry Pi 4 GPIO pins as indicated below, and each of them were connected between one 330Ω and one 470Ω resistor:
HC-SR04 (Front) | GPIO.BOARD | GPIO.BCM |
---|---|---|
VCC | 5V | 5V |
GND | GND | GND |
TRIG | 8 | GPIO 14 |
ECHO | 10 | GPIO 15 |
HC-SR04 (Middle) | GPIO.BOARD | GPIO.BCM |
---|---|---|
VCC | 5V | 5V |
GND | GND | GND |
TRIG | 11 | GPIO 17 |
ECHO | 13 | GPIO 27 |
HC-SR04 (Rear) | GPIO.BOARD | GPIO.BCM |
---|---|---|
VCC | 5V | 5V |
GND | GND | GND |
TRIG | 24 | GPIO 8 |
ECHO | 26 | GPIO 7 |
The L298N motor driver pins were connected to the Raspberry Pi 4 as follows:
L298N Motor Driver | GPIO.BOARD | GPIO.BCM |
---|---|---|
VCC | 6.4V - 8.4V | 6.4 - 8.4V |
GND | GND | GND |
INA & INB | 16 & 18 | GPIO 24 & GPIO 23 |
INC & IND | 29 & 31 | GPIO 5 & GPIO 6 |
ENA | 32 | GPIO 12 PWM0 |
ENB | 33 | GPIO 13 PWM1 |
The left and right encoder from the DC motors were connected to the Raspberry Pi 4 as follows:
Encoder (Left) | GPIO.BOARD | GPIO.BCM |
---|---|---|
Output A | 37 | GPIO 26 |
Output B | 36 | GPIO 16 |
Encoder (Right) | GPIO.BOARD | GPIO.BCM |
---|---|---|
Output A | 22 | GPIO 25 |
Output B | 15 | GPIO 22 |
The SCD30 sensor was connected to the Raspberry Pi 4 as follows:
SCD30 | GPIO.BOARD | GPIO.BCM |
---|---|---|
VIN | 3.3V | 3.3V |
GND | GND | GND |
TX/SCL | 5 | GPIO 3 SCL |
RX/SDA | 3 | GPIO 2 SDA |
SEL | GND | GND |
The DC motors are connected to the L298N motor driver as follows:
DC motor (right) | L298N Motor Driver |
---|---|
Positive | OUT A |
Negative | OUT B |
DC motor (left) | L298N Motor Driver |
---|---|
Positive | OUT C |
Negative | OUT D |
For reference, overview of the GPIO pins for the Raspberry Pi 4:
Front view of the robot:
Right view of the robot:
Back view of the robot:
Left view of the robot:
Top view of the robot:
This section will walk you through setting up the development environment for ROS 2 using Visual Studio Code. The environment is based on the ROS2 workspace template by athackst with some minor tweaks to remove C++ as the robot is fully written in Python. Additionally, some of the settings .devcontainer
configuration file has been altered due to recent updates to Visual Studio Code.
The following are necessary to setup the development environment:
The Raspberry Pi 4 is based on the Raspberry Pi with ROS 2 and the real-time kernel image and modified during setup with the Raspberry Pi Imager software to have different a hostname and password. As of May 2023, the image is based off the ROS 2 Humble distribution with Ubuntu 22.04.01 and the real-time kernel (PREEMPT_RT) pre-installed.
The credentials during the thesis for the robot:
Hostname | Username | Password | Access Point | Access Point (Password) |
---|---|---|---|---|
sfr.local |
sfr.local |
sFRsuperduper@. |
SFR |
sFRsuperduper@ |
-
To enable SSH connection via hostname you should install avahi-daemon on the Raspberry Pi 4.
-
Disable SPI with
raspi-config
as we are not interfacing with a microcontroller.
The robot_control.sh script is used to transferring code and to communicate with the robot at ease. This becomes much simpler by copying your public SSH key to the Raspberry Pi 4 with ssh-copy-id -i </path/to/key [email protected]
.
If on a Windows machine you should also install the Bonjour Print Service from Apple which enables you to discover it by hostname instead of IP-address only.
- Code is tested and ran on a Raspberry Pi 4 with ROS 2 Humble installed on Ubuntu 22.04 (Jammy Jellyfish).
- Install dependencies as listed in requirements.txt.
- Build the workspace
colcon build --packages-select sfr --symlink-install
. - Source the installation
source install/setup.bash
. - Run the main algorithm
ros2 launch sfr start_crop_algorithm_launch.py
.