Skip to content

Software Guides

pryre edited this page Apr 26, 2020 · 41 revisions

Flashing a Disk Image to an SD Card or eMMC Chip

The first step is to select and download an actual disk image. This won't be covered in detail, however the guides below provide links to some potential disk images to use. The file you should prepare to be flashed should be a .img file.


Instructions

To begin the flashing procedure:

  1. Download Etcher
  2. Plug in your disk
  3. Run Etcher
  4. Select your disk image
  5. Select the disk to flash the image to
  6. Begin the flash

Once the flash is complete, you should be able to plug the disk back into the onboard computer and start up the device.


Preparing the Pre-Compiled PiROS Raspberry Pi Disk Image

There are two sets of disk images available. Please ensure you select the correct one for the version of Ubuntu & ROS that you plan on using.


PiROS Melodic (Ubuntu 18.04)

This PiROS disk image for RPi versions 2, 3, and 4 can be found here.

PiROS Kinetic (Ubuntu 16.04)

This disk image can found at the links below:


The disk images require at least an 8GB SD Card to properly flash the disk image. Download the image and flash the disk image as detailed above.

Login details

To log into your Pi for the first time, you will have to use a serial terminal like putty. The serial port to use will be dependent on your PC, but the PiROS image is configured to use a buadrate of 115200.

Username: pi

Password: raspberry

Installed Packages

The following packages have been pre-installed and configured:

  • tmux
  • picocom
  • python
  • OpenCV (via ROS)
  • wiringpi-python
  • ROS:
    • vision-opencv
    • raspicam_node
    • mavros and mavros_extras

Additional Configuration

The following scripts are configured:

  • Enable Graphical User Interface (GUI)
    • The GUI may first need to be installed. To instal LXDE for example (see General Computing) for GUI options), run: sudo apt install xinit lxde
    • Add the following line to the file ~/.xsession: startlxde
    • The GUI can be started (after logging in) by running the command: startx
  • A ROS catkin workspace has already been setup: ~/catkin_ws/
  • Distributed ROS can be configured by:

PiROS Melodic (Ubuntu 18.04)

Running either of the following disros commands:

  • To use this device as the ROS master: disros
  • To connect to another device that is the ROS master (replace the IP with the actual IP or hostname): disros 192.168.1.2 or disros otherdevice
PiROS Kinetic (Ubuntu 16.04)

Running either of the following kinetic commands:

  • To use this device as the ROS master: kinetic
  • To connect to another device that is the ROS master (replace the IP with the actual IP or hostname): kinetic 192.168.1.2 or kinetic otherdevice

  • The hardware serial port:

PiROS Melodic (Ubuntu 18.04)

uart0 has been enabled ready for use as: /dev/ttyS0. A login has be enabled to allow interfacing without a screen or WiFi. To change serial login: - To enable: sudo systemctl enable [email protected] - To disable: sudo systemctl disable [email protected]

  • Interfacing with the serial port:
    • Serial login must be disabled before the serial interface can be used for anything else
    • The command picocom can be used to open a terminal port for viewing
PiROS Kinetic (Ubuntu 16.04)
  • Raspberry Pi 2:
    • uart0 has been enabled ready for use as: /dev/ttyAMA0
    • A login has be enabled to allow interfacing without a screen or WiFi
  • Raspberry Pi 3:
    • uart0 has been enabled ready for use as: /dev/serial0
    • A login can be enabled to allow interfacing without a screen or WiFi
  • Serial login:
  • Interfacing with the serial port:
    • Serial login must be disabled before the serial interface can be used for anything else
    • The command picocom can be used to open a terminal port for viewing

WiFi Initial Connection & Issues

To perform the initial connection, you can use NetworkManager to handle everything. To perform a scan of available WiFi networks:

sudo nmcli device wifi rescan
sudo nmcli device wifi list

Once you see your WiFi network, you can connect like so:

sudo nmcli device wifi connect WIFINAME password WIFIPASSWORD

The connection should now be active, and will automatically connect when on your next boot. Note that as the WiFi connection is a new connection to the router, you may need to find the new IP address before you can reconnect.

You should also refer to the Networking in Linux guide to get maximum performance out of your system.

Resizing the Primary File System

Resizing the primary file system must be done to ensure that the amount of space you have to use is actually represents the entire space available. Depending on the OS image that you download, the system partition may automatically be resized on your first boot. To make sure that your system has as much disk space as possible, it may be necessary to perform a live resize the system partition.


PiROS Melodic (Ubuntu 18.04)

To resize the system, run the following command:

sudo resize_filesystem

You should see something like the following:

Found the start point of mmcblk0p2: 266240
Ok, Partition resized, please reboot now
Once the reboot is completed please run this script again

Now you will need to reboot the device:

sudo reboot

Finally, run the script a second time to complete the process:

sudo resize_filesystem

You should see something like the following:

Activating the new size
resize2fs 1.42.13 (17-May-2015)
The filesystem is already 1906688 (4k) blocks long.  Nothing to do!

Done!
Enjoy your new space!
PiROS Kinetic (Ubuntu 16.04)

This task can be performed in two ways, but only needs to be done once. Pick the way that most applies to you.

Using raspi-config

If you are using a Raspberry Pi compatible OS, you should have access to the raspi-config utility. The utility can be run in interactive mode with the command sudo raspi-config, however expanding the file system can be done in one step by running the following command instead:

sudo raspi-config --expand-rootfs

Using the QUTAS Resize Script

Firstly, login to the computer via SSH (described below) or by using a monitor, and download the script (which can also be found here):

wget https://raw.githubusercontent.com/qutas/info/master/Scripts/resize.sh

Next, prepare the script to be executed and then run it:

chmod +x resize.sh
sudo ./resize.sh

You should see something like the following:

Found the start point of mmcblk0p2: 266240
Ok, Partition resized, please reboot now
Once the reboot is completed please run this script agai

Now you will need to reboot the device:

sudo reboot

Finally, run the script a second time to complete the process:

sudo ./resize.sh

You should see something like the following:

Activating the new size
resize2fs 1.42.13 (17-May-2015)
The filesystem is already 1906688 (4k) blocks long.  Nothing to do!

Done!
Enjoy your new space!

Setting a Hostname

When connected a properly configured router, this will allow you to connect to your onboard computer without needing to look up the IP address every time. You will have to change 2 files to correct set the host name (refer here for some tips on using the command line). Replace newhostname with something else of your choosing (for a group project, something like "rpi-gX" may be a good choice).

sudo nano /etc/hosts
# Add in a line at the top that says:
127.0.0.1 newhostname
sudo nano /etc/hostname
# Replace the old name with the new one:
newhostname

You should now reboot for everything to take effect and update correctly:

sudo reboot

Preparing an Onboard Computer from Scratch

There are a few steps that are necessary to take to get your onboard computer running ROS. The first is to be aware that it is highly recommended (though not strictly necessary) to have the onboard computer running the correct version of Ubuntu for the ROS distribution you expect to run. As an example, the best choice for running ROS Kinetic is Ubuntu 16.xx, however, more information can be found on the ROS installation guides.


Instructions

Preparing the OS

To begin, you will need to flash the OS image onto the SD card, disk, or hard-drive that your onboard computer will use.

Firstly, you will have to obtain the disk image of the OS that you wish to install. As an onboard computer typically will not have constant access to a monitor or display, it is recommended that you start with an image based off of Ubuntu Server. The server image is the same as normal Ubuntu, but does not come with a desktop installed by default (however if you change your mind later, the desktops are quite simple to install).

For Raspberry Pi 2/3, the Ubuntu MATE is recommended (make sure you get the correct image for RPi2 or RPi3).

For Odroid devices, the appropriate Ubuntu 'Minimal' is recommended (look for the images with '...minimal-odroid-xu4...' in the name for XU4 devices).

Follow the instructions above to flash the selected disk image.

First Boot

It is recommended that you perform the first boot with the system configured as one of the following:

  • Plugged into a router (that you have access to see the connected system's IP addess) with an Ethernet cable
  • Plugged into a monitor/display with a keyboard and WiFi module attached (if not built in)

If using the first method, you will need to SSH into your onboard computer to gain access to the command line. To do this, you will need to do the following:

The onboard computer typically has a single administrator account set up, with the credentials as follows (however they may be different):

  • Raspberry Pi:
    • Username: pi
    • Password: raspberry
  • ODroid:
    • Username: root
    • Password: odroid

Once you are logged in, you should see a command prompt that looks something like the following:

user@linux $

Or:

root@linux #

If you see the second prompt with a #, this typically signifies that you are running as an administrator account. It is good practice (and necessary to run ROS properly) to set up a standard user account, and then re-log as the new user (replace username with something of your own):

useradd -m username
passwd username

Note: As you should be using a relatively standard Ubuntu system image, you should look up documentation and guides relating to software referencing Ubuntu, rather than your onboard computer type (i.e. "How to set up WiFi in Ubuntu" rather than "How to set up WiFi on a Raspberry Pi"). Failing to do so will most likely make a mess of your system image. Hardware issues (such as "How to enable the camera on Raspberry Pi") should still be fine.


Enable SSH

In some cases, SSH does not come enabled by default. Depending on your disk image, you may be able to skip this section and come back to it later if you are getting the error "connection refused" when trying to log in via SSH.

First off, make sure you have an ssh server installed:

sudo apt install openssh-server

If you have access to a monitor and keyboard, you should be able to log in, access a terminal, and run the command:

sudo systemctl enable sshd.service
sudo systemctl start sshd.service

Or in some versions:

sudo systemctl enable ssh.service
sudo systemctl start ssh.service

For a typical Ubuntu disk image, if you only have access to the SD card, you should be able to do the following:

  • Connect the SD card to a computer running linux
  • Mount the SD card, and open a terminal in the root directory
  • Run the following command:
sudo ln -s ./usr/lib/systemd/system/sshd.service ./etc/systemd/system/multi-user.target.wants/sshd.service

System Management

The first thing you should do on the new system is to expand the root file system to ensure you have as much space as you need (refer here).

After you manage to log in, you probably want to perform a system update:

sudo apt update
sudo apt upgrade

The last step in a typical upgrade is to set a custom hostname (refer here).

Now your system should be functioning and up to date! The next step is to install ROS and any other software you might need.


Non-Standard Baud Rates for Pixhawk Variants

Users of PixHawk and PixRacer should refer here before following this guide.


Instructions

If anything goes wrong, remember that you can always reset your safely firmware through QGCS (use the latest stable build)!

This guide assumes that you have already cloned the px4 firmware repository, and have at least compiled the code for the PixHawk (if you have jMavSim running, you are way past this point).

Please ensure you can successfully build the firmware before continuing.

For the purposes of stability, we will be working using the most recent stable release (v1.6.5). To do this, navigate to the px4 firmware directory (most likely: ~/src/Firmware) and run the command:

git checkout v1.6.5

You should get a message that says something like this if successful:

M    Tools/jMAVSim
M    Tools/sitl_gazebo
M    mavlink/include/mavlink/v1.0
M    mavlink/include/mavlink/v2.0
M    src/drivers/gps/devices
M    src/lib/DriverFramework
M    src/lib/ecl
Note: checking out 'v1.6.5'.

...

HEAD is now at f160743... Join us on Slack README badge

From here, you should clean our build directories, and recompile the code to make sure everything is working as expected (there may be some warnings about submodules, just follow the instructions that are provided in the warnings):

make clean
make px4fmu-v2_default

If there are no errors, and the code compiles successfully, then it is time to move on. The specific file that needs to be changed is under ./ROMFS/px4fmu_common/init.d/rcS.

Open this file in a text editor, and navigate to line 194. Change the line from:

set MAVLINK_F default

To:

set MAVLINK_F "-d /dev/ttyS1 -b 921600 -m onboard -r 80000 -x"

This is all you should have to change to get the port running at full speed. From here, recompile the code (it should be a lot quicker this time):

make px4fmu-v2_default

Now plug in your px4 (and if you're on a VM, remember to enable passthrough mode), and run:

make px4fmu-v2_default upload

And you should be left with the messages:

Erase  : [====================] 100.0%
Program: [====================] 100.0%
Verify : [====================] 100.0%
Rebooting.

[100%] Built target upload

Now you will have to open up QGCS, and redo the autopilot calibrations.sudo ln -s ./usr/lib/systemd/system/sshd.service ./etc/systemd/system/multi-user.target.wants/sshd.service

You should also be able to connect the PixFalcon to MavROS using the USB serial adapter you have previously made (but remember to change the baud rate in the launch file to 921600)!


Clone this wiki locally