Standard Formula Pi SD card image - Monster series

Please note that most of the installation steps will expect the Raspberry Pi to be connected to the internet.
We recommend using a Raspberry Pi 3 as that is what will be fitted in the MonsterBorgs.

Basic Raspbian Lite image

The standard image is based on the official version of Raspbian Lite.
We have tested using the 14th of March 2018 version: http://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2018...
We recommend following the install guide here.

The advantage to using Raspbian Lite is that you only need a 4 GB SD card and there is plenty of space for detailed logging still :)
The downside is that the setup will take a bit longer as we need to install more things.

We also recommend expanding the file system using raspi-config:

  1. Enter the following command in a terminal: sudo raspi-config
  2. Move down to option 7 Advanced Options and press ENTER
  3. Move down to option A1 Expand Filesystem and press ENTER
  4. Move right until Finish is highlighted, then press ENTER
  5. If asked if you would like to reboot, make sure Yes is highlighted, then press ENTER

If you need to use the WiFi to download files from the internet you should set it up before proceeding.
We recommend following the guide from the official Raspberry Pi site here.
If you are using a Pi 3B+ you also need to make sure the WiFi country is set, otherwise the WiFi will be disabled!

  1. Enter the following command in a terminal: sudo raspi-config
  2. Move down to option 4 Localisation Options and press ENTER
  3. Move down to option I4 Change Wi-fi Country and press ENTER
  4. Move down until you have the correct country highlighted and press ENTER
  5. When the dialog says the county is set press ENTER
  6. Move right until Finish is highlighted, then press ENTER

You may have to reboot to get the WiFi to connect.

You may also want to install git to download the Formula Pi code:

sudo apt-get update
sudo apt-get -y install git

At this point you should reboot your Raspberry Pi to allow any changes to finish.

Installing the ThunderBorg

First enable I2C using raspi-config:

  1. Enter the following command in a terminal: sudo raspi-config
  2. Move down to option 5 Interfacing Options and press ENTER
  3. Move down to option P5 I2C and press ENTER
  4. Make sure Yes is highlighted and press ENTER
  5. When the dialog says I2C is enabled press ENTER
  6. Move right until Finish is highlighted, then press ENTER

If the I2C option is not available simply proceed to the next step.

To run through the automatic installer just use this one line in a terminal:

bash <(curl https://www.piborg.org/installer/install-thunderborg.txt)

If you would prefer to manually run through the steps use the commands below:

mkdir ~/thunderborg
cd ~/thunderborg
wget http://www.piborg.org/downloads/thunderborg/examples.zip
unzip examples.zip
chmod +x install.sh
./install.sh

Setting up the camera

After powering the Raspberry Pi you want to enable the camera functionality:

  1. Enter the following command in a terminal: sudo raspi-config
  2. Move down to option 5 Interfacing Options and press ENTER
  3. Move down to option P1 Enable camera and press ENTER
  4. Make sure Yes is highlighted and press ENTER
  5. When the dialog says the camera is enabled press ENTER
  6. Move right until Finish is highlighted, then press ENTER
  7. If asked if you would like to reboot, make sure Yes is highlighted, then press ENTER

You can check the Raspberry Pi camera is attached and working by using the following command:

raspistill -d

If the camera is working you should see the image from the camera on the monitor for a few seconds.
If it is not working or incorrectly connected you will get error messages instead.

Next we want to install the Python library for talking to the camera:

sudo apt-get -y install python-picamera

As we want to do image processing we want the OpenCV libraries as well.
This download is a bit larger and may take a while:

sudo apt-get -y install libcv-dev libopencv-dev python-opencv

Graphical output

The standard code allows for image output of what the robot can see and how it has analysed the image. Because the visual components (such as LXDE) are not installed by default on Raspbian Lite we will need to install them as well.

First we need to install the LXDE desktop environment to provide the visual interface. This will take a while to run.

sudo apt-get -y install xserver-xorg xinit lxde-core lxappearance lightdm

Next we will install PIXEL, which is the standard desktop as used by the full version of Raspbian:

sudo apt-get -y install pi-greeter raspberrypi-ui-mods raspberrypi-artwork raspberrypi-bootloader
sudo apt-get -y install pix-icons pix-plym-splash rpd-wallpaper rpi-chromium-mods

The last thing we do is to get the pi to automatically login at bootup. This is done using raspi-config:

  1. Enter the following command in a terminal: sudo raspi-config
  2. Move down to option 3 Boot Options and press ENTER
  3. Move down to option B1 Desktop / CLI and press ENTER
  4. Move down to option B2 Console Autologin and press ENTER
  5. Move down to option 3 Boot Options again and press ENTER
  6. Move down to option B3 Splash Screen and press ENTER
  7. Make sure No is highlighted and press ENTER
  8. When the dialog says the splash screen is disabled press ENTER
  9. Move right until Finish is highlighted, then press ENTER
  10. If asked if you would like to reboot, make sure Yes is highlighted, then press ENTER

When you restart the Pi it should now start and login for you.

If you want to see the desktop simply run the command startx and it will appear :)

Final notes

We will download and unzip your code into the /home/pi/formulapi directory.
We will add this line into rc.local to start the code:

sudo python /home/pi/formulapi/Formula.py &

This means you will need a Python script called Formula.py as the starting part of your code.
This will be how our standard example works, with Formula.py loading all of the other scripts.

If you wish to use a language other than Python you may, but it must be started from the command in rc.local listed above.
If your code will not run on our standard image you will need to provide a pre-setup micro SD card which will work with the Raspberry Pi 3 and will start up into a waiting for lights state on its own.
It will also need to access the /colours.txt file we write to the card and set the RGB values from the first line to the ThunderBorg LEDs (see the rules for more details).

Tags: 

Comments

I followed the instructions above to setup an SD card.

However, it seems that I'm now lacking some python packages on this SD card.

I have the following questions.
1. Can I assume that the standard SD card used for the Formula Pi has the packages used by the standard Race Code available?

2. Can somebody give me a pointer how to install packages like numpy and OpenCV on my custom SD card?

Arron Churchill's picture

The instructions above should be enough to set everything up for the standard code, it might be worth checking if there were any errors running the commands.

I did have a look earlier and it seems that the longer lines might be missing the horizontal scrollbar at the bottom on phones / tablets. I would check the instructions on a PC to be safe :)

The install for OpenCV and its dependencies (including numpy) is the following:

sudo apt-get -y install libcv-dev libopencv-dev python-opencv

It should take a long time, if it finishes quickly then it is either installed already or it failed to install.

On a side note we are using the default copy of Python which runs from the python command, which is 2.7 if I remember correctly. This means your code needs to work on Python 2 unless you are sending us a custom SD card.

I'm trying to use this new official SD card image. Saving the captured images I'm getting a very strange colour problem. This is my guess what is wrong: at the top 2/3 of the image the red and blue channel are swapped, the lower part is correct. There is no real image processing done, it seems to be a low level problem (opencv etc).
Raspistill gives correct colours.

Arron Churchill's picture

That is not a problem we have seen on the robots at any point, but it sounds like something might be getting overwritten somewhere.

I know that the images directly from the cv2.VideoCapture object are in BGR format so it might make sense if the data was mixed up with RGB format data in some fashion.

I would try taking a copy of the image and using the copy instead as early as possible in the script, like this:

image = image.copy()

I have a similar line in the script we use for the streaming the camera footage. From memory I was seeing some kind of memory corruption before using it, but it was a long time ago now...

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre>
  • Syntax highlight code surrounded by the <pre class="brush: lang">...</pre> tags, where lang is one of the following language brushes: bash, cpp, perl, python.
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.