Install ROS on Raspberry Pi
This tutorial is referenced to the ardupilot.org
Setup is as shown below:
Components | |
---|---|
FMU | The Cube Black |
Companion Computer | Raspberry Pi 3B |
System | Ubuntu Mate 16.04 |
Camera | Pi Camera v2 |
SD card | At least 8 GB |
Power Source for Companion Computer | 5000mAh Portable USB Power Bank |
You will need a keyboard, a mouse, and a HDMI monitor to setup your pi.
Prepare the Operation System on Pi
You can find the detailed installation procedure here but it is troublesome.
You may direct download the workable image at https://www.raspberrypi.org/forums/viewtopic.php?p=1295937#p1295937
Use SD Card Formatter to clear everything on your card and burn the image by balenaEtcher.
Plug the SD card into your Pi and turn it on. Follow the instructions to finish all initial settings.
Install ROS
Detail instruction can be found on ROS.org
Setup your computer to accept software from packages.ros.org.
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
Set up your keys
sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116
Make sure your Debian package index is up-to-date
sudo apt-get update
sudo apt-get upgrade
Install ROS Desktop-Full
sudo apt-get install ros-kinetic-desktop-full
Initialize rosdep
sudo rosdep init
rosdep update
Environment setup
echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
Install dependencies for building packages
sudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential
Install MAVROS
Detailed instructions can be found here
Or you may type these commands in the terminal to install
sudo apt-get install ros-kinetic-mavros ros-kinetic-mavros-extras
wget https://raw.githubusercontent.com/mavlink/mavros/master/mavros/scripts/install_geographiclib_datasets.sh
chmod a+x install_geographiclib_datasets.sh
./install_geographiclib_datasets.sh
Install RQT tools
sudo apt-get install ros-kinetic-rqt ros-kinetic-rqt-common-plugins ros-kinetic-rqt-robot-plugins
Install catkin tools
sudo apt-get install python-catkin-tools
Setup the Cube
Connect the Cube to ground station (eg: Mission Planner). Go to Config/Tunning > Full Parameter List
and modify the following parameters:
SERIAL2_PROTOCOL = 1 to enable MAVLink on the serial port.
SERIAL2_BAUD = 57 baud rate can be up to 921000.
LOG_BACKEND_TYPE = 3 dataflash log files enable.
Connect your Raspberry Pi to the Cube
There are 2 ways to connect them.
Connect via USB
Simply plug connect the Raspberry Pi and the Cube with a USB-to-microUSB cable. The Raspberry Pi should be able to recognize the device.
Connected USB devices can be checked by running the command in terminal as shown below:
for sysdevpath in $(find /sys/bus/usb/devices/usb*/ -name dev); do
(
syspath="${sysdevpath%/dev}"
devname="$(udevadm info -q name -p $syspath)"
[[ "$devname" == "bus/"* ]] && continue
eval "$(udevadm info -q property --export -p $syspath)"
[[ -z "$ID_SERIAL" ]] && continue
echo "/dev/$devname - $ID_SERIAL"
)
done
Remember the tty port of the fmu. It will be used later.
Connect via GPIO
Modify one of the telem cable from the Cube
IT IS NOT RECOMMMANDED to connect the 5V pin of the Cube with Pi as Cube is not a proper power source. But if you still want to, connect them as shown in the image.
For Raspberry Pi 3B and newer models, the Bluetooth module occupied UART serial port. To disable the Bluetooth, type the following command in the terminal:
sudo nano /boot/config.txt
Then, add the following lines at the end of config.txt:
dtoverlay=pi-disable-bt
enable_uart=1
Type
sudo nano /boot/cmdline.txt
Modify the file to the following:
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles
Type
sudo raspi-config
Select Advanced Options > Interfacing Options
. Disable serial login shell
and keep serial interface
enabled.
The Cube will not be recognized as an USB device. The port can be check by typing the following commands in terminal:
ls /dev/tty*
/dev/ttyS0
or /dev/ttyAMA0
should be used to communicate with the Cube. For my case, it is /dev/ttyS0