ROS2 Builds for the PiDog/PiCar

I’ve seen a couple of posts about ROS2 Builds for the PiCar-X and Pi-Dog, thought it might be a good idea to group them here so we can share experiences.

I’ve been trying: danhermes/Nevil-picar-v2

Build but got stuck at 3. Install ROS2 on Raspberry Pi (ARM64), there is no start.py.

But i’m a noob at Python and github.

So what other ROS2 installs have people done and what success did you have with the onboard sensors. Have you extended to have other sensors.

1 Like

Well here’s my build script for ros2 jazzy

Enjoy

#Usual to ensure all upto date

sudo apt update

sudo apt upgrade

#I like vim! But please swap for favorite editor

sudo apt install vim

#Max out everything for swap!

#increase swap space (allocate more if needed): and zram compression

sudo apt install zram-tools

sudo dphys-swapfile swapoff

##Edit to increase swap as needed I used 8g on a 4g pi4

sudo vim /etc/dphys-swapfile

#AND SAME FOR I used 8g

sudo vim /sbin/dphys-swapfile

sudo dphys-swapfile setup

sudo dphys-swapfile swapon

sudo reboot now

#####################################################################################

#ROS2 on Pi raspbian is not available from repos, it must be built from source. as below

sudo apt install -y git colcon python3-rosdep2 vcstool wget python3-flake8-docstrings python3-pip python3-pytest-cov python3-flake8-blind-except python3-flake8-builtins python3-flake8-class-newline python3-flake8-comprehensions python3-flake8-deprecated python3-flake8-import-order python3-flake8-quotes python3-pytest-repeat python3-pytest-rerunfailures python3-vcstools libx11-dev libxrandr-dev libasio-dev libtinyxml2-dev

mkdir -p ~/ros2_jazzy/src

cd ~/ros2_jazzy # important NOT the src subdirectory created above, but this parent.

#This seems to be a very unreliable link, may need to run several times until no more “E”'s

##Otherwise can get missing libraries etc

vcs import --input https://raw.githubusercontent.com/ros2/ros2/jazzy/ros2.repos src

sudo rm /etc/ros/rosdep/sources.list.d/20-default.list

sudo apt upgrade

sudo rosdep init

rosdep update

rosdep install --from-paths src --ignore-src --rosdistro jazzy -y --skip-keys “fastcdr rti-connext-dds-6.0.1 urdfdom_headers python3-vcstool”

#This takes about 8 hours on rpi4 4Gb. could even freeze due to memory problems, just rerun. Reduce/increase parallel workers if you have less/more memory than my 4GB

colcon build --symlink-install --parallel-workers 2

echo “source ~/ros2_jazzy/install/local_setup.bash” >> ~/.bashrc

source ~/.bashrc

1 Like

I’d suggest posting a bug on the github page regarding the missing start.py. Meanwhile the OLDstart.py looks like it should get you going.

1 Like

Thanks, this really helped me get started.

Here are my current build notes in case it helps anyone else. Note, I’m taking extra steps to avoid running code with sudo in my finished product, which may turn out to be a fool’s errand, but so far seems to be working. Second note, watch the ““ I tripped on them getting converted:

init raspbian OS with pi Imager
enable VNC and i2c
sudo raspi-config

Update and install prerequisites
sudo apt updatesudo apt upgradesudo apt install git python3-pip python3-setuptools python3-smbus
install robot-hat
cd ~/git clone -b v2.0 cd robot-hatsudo python3 setup.py install
install vilib
cd ~/git clone -b picamera2 cd vilibsudo python3 install.py
install picar-x
cd ~/git clone -b v2.0  --depth 1cd picar-xsudo python3 setup.py install
setup sound
cd ~/picar-xsudo bash i2samp.sh
calibrate
cd ~/picar-x/example/calibrationsudo python3 calibration.py
cd ~/picar-x/example/calibrationsudo python3 grayscale_calibration.py
increase swap
sudo apt install zram-toolssudo dphys-swapfile swapoffsudo nano /etc/dphys-swapfilesudo dphys-swapfile setupsudo dphys-swapfile swapon
install prerequisites
sudo apt install -y git colcon python3-rosdep2 vcstool wget python3-flake8-docstrings python3-pip python3-pytest-cov python3-flake8-blind-except python3-flake8-builtins python3-flake8-class-newline python3-flake8-comprehensions python3-flake8-deprecated python3-flake8-import-order python3-flake8-quotes python3-pytest-repeat python3-pytest-rerunfailures python3-vcstools libx11-dev libxrandr-dev libasio-dev libtinyxml2-dev
create directory
mkdir -p ~/ros2_jazzy/srccd ~/ros2_jazzy
vcs import --input https://raw.githubusercontent.com/ros2/ros2/jazzy/ros2.repos srcsudo rm /etc/ros/rosdep/sources.list.d/20-default.listsudo apt upgradesudo rosdep initrosdep updaterosdep install --from-paths src --ignore-src --rosdistro jazzy -y --skip-keys “fastcdr rti-connext-dds-6.0.1 urdfdom_headers python3-vcstool”colcon build --symlink-install --parallel-workers 8echo “source ~/ros2_jazzy/install/local_setup.bash” >> ~/.bashrcsource ~/.bashrc
fix sound without sudo
audio for /dev/snd/*
sudo usermod -aG audio $USER
video is often needed on Pi for some stacks; harmless to add
sudo usermod -aG video $USER
if your code touches GPIO/I²C, add these so you don’t need sudo for pins/bus
sudo usermod -aG gpio $USERsudo usermod -aG i2c $USER
allow user code to connect to pins
sudo systemctl enable --now pigpiod
ideally, I should track down what is starting aplay, probably vnc, but for now, just kill it on reboot, I run fix_sound.sh, which runs:
sudo systemctl stop aplay.servicesudo systemctl disable aplay.servicesudo systemctl mask aplay.serviceps -ef | grep aplaypactl list short sinks#pactl set-default-sink alsa_output.platform-soc_107c000000_sound.stereo-fallbackpinctrl set 20 op dh

Now I just need to to get to work on actually making it do something: GitHub - coreyt429/rover_ros2: Personal project to give picar-x an ROS2 brain.

1 Like

You are most welcome, glad that I could help you on your ROS journey!

Please keep me up to date on progress, I’d be very interested to see what you develop.

Enjoy!

Just one tip I’d like to share. I originally wrote those instructions for ros2 humble about 18 months ago. When I last tried to execute them, they no longer worked. There are so many dependent libraries required, that they simply became deprecated over that 18 months. I regret not having kept a record of all of the library versions used such that I could recreate it. Fortunately Switching to jazzy fixed everything. However, similarly. I developed a methodology to add orbslam3 to my pidog in ros, (my videos are somewhere on this forum!) This also broke after multiple library updates and is going to take a lot of work to get it working again with the latest libraries. So tip → make a (many) sdcard backup once it’s all working and record the exact library versions you are using to facilitate easy restoration.

can you suggest what to do, my sunfounder picar v ‘s servo is twiching without command

James, is your product the Picar-V?

Could you please share a video of the servo jittering? This will help us analyze and resolve the issue.

If there is a problem with the servo, we will send you a replacement servo.