Setting Up ROS Environment On The Raspberry PI
ROS stands for Robot Operating System, which modularizes your code and provide a template for communication across different parts of the robot (different parts of your code). More about ROS can be found on their official guide.
It's recommended to setup the ROS environment inside a Docker container. A container is similar to a Virtual Machine(VM) but is more lightweight. More about docker can be found on their website.
Yahboom's Raspbot V2 comes with some premade ROS nodes which act as an interface to code around it. Its usage is documented on their official guide under 9. ROS2-Robot chassis control course and 10.ROS2-OpenCV course.
The easiest way to setup the ROS enviroment in a docker container is to flash the default .img which can be found on their website under System_File which redirects you here.
Otherwise, it's possible to build a custom Docker image from a custom Dockerfile to setup the environment. The source files for their ROS workspace can be found in their website under Code which redirects here.
.
├── instruction_manual
├── project_demo
│ ├── 03.Basic_car_course
│ │ └── RGB_Light_bar_test
│ ├── 04.Car_motion_control
│ │ └── __pycache__
│ ├── 05.Advance_course
│ ├── 06.Open_source_cv_course
│ │ ├── A.introduction
│ │ ├── B.Geometric_Transformations
│ │ ├── C.Image_Processing_Text_Drawing
│ │ ├── D.Image_Enhancement
│ │ └── E.Machine_Learning
│ ├── 07.AI_Visual_Recognition
│ │ ├── 01.Camera_Driving
│ │ ├── 02.Color_Recog
│ │ ├── 04.Tensorflow_object_recognition
│ │ ├── 05.QR_code_recognition
│ │ ├── 06.Face_recognition
│ │ ├── 07.License_plate_recognition
│ │ ├── detection
│ │ └── mediapipe
│ ├── 08.AI_Visual_Interaction_Course
│ │ ├── 01.Color_tracking
│ │ ├── 02.Color_follows
│ │ ├── 03.QRcode_recog_campaign
│ │ ├── 04.Face_tracking
│ │ ├── 05.Face_follow
│ │ ├── 06.Vision_Based_Auto_LineFollowing
│ │ ├── 07.Garbage_identification_yolov4tiny
│ │ ├── 07.Garbage_identification_yolov5lite
│ │ ├── 08.Autopilot_map_sandbox
│ │ └── 09.Gesture_follows
│ ├── lib
│ │ └── __pycache__
│ └── raspbot
│ ├── data
│ ├── object_detection
│ ├── __pycache__
│ ├── ssdlite_mobilenet_v2_coco_2018_05_09
│ └── templates
└── ros2_source_code
├── library_ws
│ ├── bin
│ ├── include
│ ├── lib
│ ├── lib64 -> lib
│ ├── py_install
│ ├── software
│ └── test
├── yahboomcar_ros2_ws
│ └── yahboomcar_ws
└── yahboomcar_ws
└── src
54 directories
The src directory for the workspace is stored at ./ros2_source_code/yahboomcar_ws/src.
An example setup may look something like this:
.
├── Dockerfile
├── docker_ros2.sh
└── src
├── yahboomcar_apriltag
├── yahboomcar_astra
├── yahboomcar_bringup
├── yahboomcar_ctrl
├── yahboomcar_description
├── yahboomcar_mediapipe
├── yahboomcar_msgs
├── yahboomcar_point
└── yahboomcar_visual
In the Dockerfile:
FROM ros@sha256:5ebfd9b9282d540dadcb3affe02d90496b075a8e81c70b235a1e56e0788d610a
# Install required system packages
RUN apt-get update && apt-get install -y \
ros-humble-cv-bridge \
ros-humble-usb-cam\
python3-smbus \
python3-pip \
libgl1-mesa-glx \
micro
RUN sudo apt install -y libxcb-xinerama0 libxcb-xinerama0-dev libxcb1 libx11-xcb1 libxcb-render0 libxcb-shm0
RUN apt install -y libpcl-dev
RUN rm -rf /var/lib/apt/lists/*
# Install Python packages
RUN pip3 install mediapipe opencv-python
RUN echo "source /ros_entrypoint.sh" >> .bashrc
WORKDIR /ros2_ws
COPY . .
CMD ["/bin/bash"]
Inside docker_ros2.sh:
#!/bin/bash
xhost +
docker run -it \
--privileged=true \
--env="DISPLAY" \
--env="QT_X11_NO_MITSHM=1" \
-v /tmp/.X11-unix:/tmp/.X11-unix \
--security-opt apparmor:unconfined \
-v /home/pi/temp:/root/temp \
-v /dev/i2c-1:/dev/i2c-1 \
-v /dev/i2c-0:/dev/i2c-0 \
--device=/dev/video0 \
--device=/dev/video1 \
--device=/dev/gpiomem \
ros_for_raspbot_custom:latest /bin/bash
Build the environment using Docker
docker build -t ros_for_raspbot_custom:latest
Run the docker environment by running the docker_ros2.sh script
bash ./docker_ros2.sh
Once inside the Docker environment, build the ROS workspace using colcon
colcon build
Source the setup.bash.
source ./install/setup.bash
It's then possible to follow the tutorials in the official website.
Common Problems and its fix
ros2command not found can be fixed by sourcing/ros_entrypoint.sh- not being able to access Yahboom's premade modules can be fixed by sourcing
./install/setup.bash - GUI not being able to launch can be fixed by first running
bash ./docker_ros2shwhile using remote desktop, such thatecho $DISPLAYgives:0. - the
apriltagmodules generally don't work due tonp.floatbeing deprecated innumpyversion 1.20, can be manually fixed by changingnp.floatto justfloat