Skip to content

Raspberry Pi 3 Setup

Brian Keating edited this page Oct 9, 2017 · 14 revisions

ROS on Ubuntu 16.04 for Raspberry Pi 3

Ubuntu install

  • download image from here
  • cd Downloads
  • Put tiny sd card into adapter, insert into laptop.
  • use gparted GUI to delete existing partitions, and create a new maximally-sized ext4 partition
  • assuming the card is mounted to /dev/sdb/, xzcat ubuntu-mate-16.04.2-desktop-armhf-raspberry-pi.img.xz | sudo dd bs=4M of=/dev/sdb. This copy operation will take a few minutes, and gives no feedback while running.

Hook up peripherals to pi -- hdmi display (TV), usb keyboard -- then plug it in to a 5V power supply. This copy operation will take a few minutes, and gives no feedback while running.Follow the wizard to set up wifi, create usrer name, etc.

sudo apt-get update sudo apt-get upgrade

Ubuntu 16.04 has automatically scheduled updates by default. This is a problem, since I don't want to be using resources to upgrade packages when I start up a robot. Disable these with sudo systemctl disable apt-daily.service and sudo systemctl disable apt-daily.timer.

Install wifi following the instructions here::

sudo apt-get install wireless-tools wpasupplicant sudo apt-get install openssh-server

Edit /etc/hosts and append the new hostname to the 127.0.0.1 line so it reads 127.0.0.1 localhost raspberrypi.

Unplug the pi, and plug it back in. Should be connected to wifi! I edited my laptop's /etc/hosts to have a line 192.168.0.102 raspberrypi. Can now connect with ssh raspberry pi. Note that the pi won't work at 5ghz wifi, your router must be set to 2.4ghz.

Set up public key authentication:

  • run ssh-keygen -t rsa to generate a key if you don't already have one. Don't overwrite old key file (answer no when prompted). Log on to pi and run:
  • touch ~/.ssh/authorized_keys
  • cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
  • rm ~/id_rsa.pub

One could now set a static ip address with the instructions here. However, I used the router settings to reserve and IP address for the raspberry pi.

Note that a raspberry pi 3 with ubuntu 16.04 boots in only 30 sec.

ROS

  • Followed the directions here

  • sudo apt-get install ros-kinectic-openni-launch to control the kinect. Also installs many dependencies.

  • sudo rosdep init, sudo rosdep fix-permissions, rosdep update

  • Clone this repo, change to ROS/workspace/, initialize ROS with source /opt/ros/kinetic/setup.bash, and build the workspace with catkin_make.

  • Edit your .bashrc to add the lines

    source /opt/ros/kinetic/setup.bash source /home/brian/ROS/workspace/devel/setup.bash

Also need to set ROS_IP on all computers that will be connecting to the master node on the raspberry pi. On ubuntu, you can get your ip address with ip route get 8.8.8.8 | awk '{print $NF; exit}', so on my Ubuntu laptop, I added a line like export ROS_IP="$(ip route get 8.8.8.8 | awk '{print $NF; exit}')" to a script in my PATH. I created an executable bash script in my PATH named rospi_init with the following contents

source /opt/ros/kinetic/setup.bash
source ~/robotics_code/ROS/workspace/devel/setup.bash
export ROS_MASTER_URI=http://raspberrypi:11311/
export ROS_IP="$(ip route get 8.8.8.8 | awk '{print $NF; exit}')"

Now, in order to start the robot, plug in the raspberry pi, wait 30 seconds, ssh raspberrypi, start roscore on the pi. In a separate terminal on my laptop, source rospi_init. If all goes well, rostopic list should produce output

/rosout
/rosout_agg

I generally develop on my laptop and push new code to the pi with rsync -a <local_dir> raspberrypi:~. It's probably a good idea when first setting up the pi to delete the devel and build folders in the ROS workspace, and build from scratch with catkin_make. Pretty sure it's safe thereafter to move python scripts around with rsync. For C++ source files, I'll probably need to set up an automated build on the pi...

Arduino

sudo usermod -a -G dialout brian sudo chmod a+rw /dev/ttyACM0

I installed the arduino IDE as usual (using the ARM distribution). I can then connect using ssh -X and use the arduino IDE to upload sketches.

Root

It is convenient to allow for passwordless sudo. Run sudo visudo and add the line brian ALL=(ALL) NOPASSWD:ALL to the end. Make sure the ROS is properly initialize for root sudo cp ~/.bashrc /root/ In an ROS launch file, specify the "launch-prefix" like so, <node pkg="my_pkg" type="my_node" name="my_super_node" launch-prefix="sudo"/>. However, I couldn't figure out how to get sudo -E rosrun working; even with the -E flag, I'm getting rosrun: command not found.

Clone this wiki locally