Sunfounder Video Car Kit for Raspberry Pi Setup Guide – Part 2: Software Configuration

Analysing ROS Distribution Capabilities (June 20, 2016)

If you followed the guide in my last post on how to assemble and get the Sunfounder Video Car running, you should at this stage have a fully-built Raspberry Pi-powered robot, but no means to program it as of yet. In order to remedy that, this post will detail the setup of the Pi's SD card, covering OS installation, some network configuration tips and the installation of a light version of the Robot Operating System.

Installing Raspbian

First, we need to get an OS up and running on the Raspberry Pi. Most sources you'll find on the Internet (and also the car's manufacturer, Sunfounder) will recommend Raspbian, a Pi-specific distribution of Linux, based on Debian. Indeed, its popularity and optimization for the Raspberry Pi make it a very good OS choice, with ample support and application compatibility.

You can choose to install Raspbian either by:

  • Downloading the NOOBS install manager and choosing Raspbian as OS to be installed. This option is quick and best for beginners. It will get you the latest stable Raspbian version.
  • Downloading a Raspbian image directly and writing it to your SD card using software like Win32 Disk Imager (Windows) or the dd command (Linux). This option gives more flexibility in case you want to install a specific Raspbian version for compatibility reasons. A word of caution here is that not all Raspbian versions seem to work on all Pis. I personally could not get Raspbian Wheezy working on the Pi 3, so do be mindful of the age difference between your hardware and the OS.

My Pis use Raspbian Jessie, the latest Raspbian version at the time of this post.

After the installation, the Pi will boot into Raspbian and log you in automatically as user "pi", logged into the host "raspberrypi", with password "raspberry".

Configuring SSH and Connection to a Wireless Network

At this stage, you may want to equip the Pi with some peripherals and configure it directly (via mouse, monitor and keyboard) or - if the Pi is Ethernet-connected or otherwise can connect to a wireless network on boot and has SSH enabled by default - ssh into it from another machine and configure it "headlessly". In the latter case, you'll want to make sure your ssh computer is on the same network as the Pi and use a tool such as nmap to discover the Pi's IP address. You can also use a VNC application such as the Remote Desktop Viewer in Ubuntu to access the Pi's graphical interface remotely.

Once you're in and have a terminal open, use the command:

  1. $ sudo raspi-config

This will bring up a configuration interface from which you should first of all expand the filesystem (note: if you used NOOBS to install Raspbian, your system is already expanded) and then enable SSH and I2C (from the "Advanced Options"). The latter two settings will allow your Pi to be accessed from different machines and allow for the rest of the electronic components to be controlled through the Pi, respectively.

Following this, you should now make sure you can connect to the Internet, to download and install needed software. Check your network interfaces and if they're connected to any network by running:

  1. $ ifconfig

If an IP address is listed next to any of your network interfaces (apart from the local loopback interface, which will always have IP, that interface is currently connected.

If no connections are active, then either use the network icon on the right of the taskbar to connect to a discovered WiFi network or modify the wpa_supplicant.conf file as follows:

  1. $ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Add an entry to this file using this format:

  1. network={
  2.          ssid="name-of-your-network"
  3.          key-mgmt=WPA-PSK         # or "NONE" if the network is open
  4.          psk="passphrase"
  5. }

Save (Ctrl+O+Enter) and close (Ctrl+X) the file and then run:

  1. $ sudo wpa_cli reconfigure

This will force the WPA supplicant to re-read its configuration file and hopefully now the wireless interface should automatically connect to your network. If you have more than one network that you want to switch between, you can set priorities for your networks in the wpa_supplicant.conf file, so that some networks are preferred over others. Similarly, if you're looking to connect the Pi to a network with a more complex authentication (such as an enterprise network), refer to this list of fields you can add to a network entry in wpa_supplicant.conf

Installing ROS and OpenCV

After obtaining a network connection, run:

  1. $ sudo apt-get update
  2. $ sudo apt-get upgrade

Then, follow the software installation steps indicated in the car kit's instruction booklet to get the I2C interface up and running and obtain the car control code provided by Sunfounder.

Once you have done this and made sure the car's motors, steering, pan and tilt are properly calibrated, you can begin the ROS installation! Luckily, has a tutorial dedicated to this task, where all the necessary steps are explained in much better detail than I could go into here :).

Just like the guide, I recommend installing the ROS-comm variant, as it is lightweight and will not put excessive strain on the Pi's processor at compilation. However, unlike the tutorial, I did not catkin_make the ROS packages in an isolated build environment, as I generally found that complicates the addition of new packages significantly. For our purpose (and indeed for most purposes), using the standard catkin_make in place of catkin_make_isolated works just fine.

Since the car comes equipped with a camera, I figured I would try to make the most of its capabilities by also installing OpenCV, a widely-supported open source computer vision library which allows for some pretty neat image processing. The Pi 3's processor is sufficiently equipped to run most OpenCV functions smoothly, but take note that older Pis with less capable processors might struggle.

To install OpenCV, simply follow this handy and very comprehensive guide.

An important thing to note is that your OpenCV installation will be independent from ROS at this stage, if you installed ros-comm. This will pose problems if you ever want to publish or consume OpenCV-processed images to or from a ROS topic. In order to allow ROS and OpenCV to cooperate, the ROS package cv_bridge must be added, alongside the useful message library common_msgs (which contains the specification for the ROS Image message type).

To add new packages to your ROS installation, refer the guide on the bottom of the ROS installation tutorial (under "Adding Released Packages"). Namely, you should run the following commands:

  1. $ cd ~/ros_catkin_ws
  2. $ rosinstall_generator cv_bridge common_msgs --rosdistro indigo --deps --wet-only --exclude roslisp --tar > indigo-custom_ros.rosinstall
  3. $ wstool merge -t src indigo-custom_ros.rosinstall
  4. $ wstool update -t src
  5. $ rosdep install --from-paths src --ignore-src --rosdistro indigo -y -r --os=debian:jessie
  6. $ catkin_make

Now the ROS environment should be fully functional and integrated with OpenCV. Now work can begin on your own ROS projects!

Installing the QR Tracker

The QR tracker is designed as a ROS project and there are a few steps to be followed so that you can run this demo on you own Raspberry Pi. As the QR tracker is using the I2C communication channel the following code needs to be executed as root. If you have followed the steps above when installing ROS and OpenCV you will have to add the following lines to your root's .profile or .bashrc

  1.    export WORKON_HOME=/home//.virtualenvs
  2.    source /usr/share/virtualenvwrapper/
  3.    source /home//ros_catkin_ws/devel/setup.bash

If these changes were made you will need to either source the file or start a new shell.

Additional dependencies are required and they need to be installed in the virtual environment where OpenCV was installed

  1. $ workon cv
  2. $ pip install python-dev python-setuptools catkin_pkg netifaces smbus libzbar-cffi
  3. $ apt-get install python-pil libzbar-dev libiconv-hook-dev libffi-dev libffi6

Now that all the dependencies are installed and the python virtual environment is ready you can install the QR tracker. At this stage you will need access to the repository. More information on how to add the code into your ROS catkin workshpace and build the tracker are available in the repository in the relevant Readme file. Have fun QR-tracing with the Raspberry Pi car-kit!

<< Previous                  Next >>