Setting up the Loco Positioning System
A big thanks to Marcus Greiff for writing this tutorial.
This is a short getting started tutorial on setting up the Local Positioning System (LPS) system. This only needs to be done once.
Additional information, including further description of the LPS system, is available at the Bitcraze home page here Links to an external site.
Prerequisites
We assume that you have the most recent cfclient installed on your computer and that you have assembled your Crazyflie as instructed in the previous tutorial. Before proceeding, it is highly advised to obtain all of the following items:
- 6 USB power banks (to power the LPS nodes)
- 6 mUSB cables (from power bank to LPS node)
- 6 rubber bands
- A 6-port USB power station for recharging the batteries
- 1 high-speed mUSB cable (works with the mUSB cables that shipped with the Crazyflies)
- 1 laser distance measurement device
- 1 label maker (so that you can mark the LPS nodes nicely)
Flashing the anchors
The first step is to download the latest firmware and flash all of the anchors. To this end, clone the lps-node-firmware repository and initialize all submodules by
git clone https://github.com/bitcraze/lps-node-firmware
followed by
cdlps-node-firmware
git submodule init
git submodule update
You can accomplish the same things directly with
git clone --recursive https://github.com/bitcraze/lps-node-firmware
In order to compile the firmware, we will need an ARM compiler. Assuming you are running a Linux distribution, downloading the compiler and setting up the ~/.bashrc file with the path to the compiler may be done by the following commands:
mkdir -p ~/opt/
cd ~/opt
wget https://launchpad.net/gcc-arm-embedded/5.0/5-2016-q3-update/+download/gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2
tar xf gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2
mv gcc-arm-none-eabi-5_4-2016q3 gcc-arm-none-eabi
rm gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2
echo "export PATH=\$HOME/opt/gcc-arm-none-eabi/bin:\$PATH" >> ~/.bashrc
On this homepage Links to an external site. you will find files for other operating systems than Linux. However, if you are running a 64bit OS, as most of us are, you will additionally have to install some 32bit libraries . On Linux, this is done by
sudo apt-get install libncurses5:i386
Upon restarting the shell, you should get the following when checking the version of your compiler using
arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 5.4.1 20160919 (release) [ARM/embedded-5-branch revision 240496]
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Once you have the compiler installed, you should now be able to make the firmware by typing make
in the ~/lps-node-firmware directory.
To flash an anchor, plug it into the computer using a high-speed mUSB cable. Note that the cables used to charge the batteries and Crazyflie typically cannot be used, you will need a high-speed mUSB cable available in most labs and at eg Kjell and Company.
We also need to ensure that the dfu-util package is installed
sudo apt-get install dfu-util
Nominally, the power LED (blue), mode LED (orange) and RX LED (green), should be blinking once the anchor is plugged in. It will then be registered as a serial device, and typing dmesg
in the terminal should yield a printout similar to
[ 1820.675458] usb 1-2: USB disconnect, device number 21
[ 1826.991514] usb 1-2: new full-speed USB device number 22 using xhci hcd
[ 1827.121769] usb 1-2: New USB device found, idVendor=0483, idProduct=5740
[ 1827.121774] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1827.121776] usb 1-2: Product: Loco Positioning Node
[ 1827.121778] usb 1-2: Manufacturer: Bitcraze AB
[ 1827.121780] usb 1-2: SerialNumber: 3F0028000457344632353020
[ 1827.122387] cdc acm 1-2:1.0: ttyACM0: USB ACM device
where, in this case, the device is registered on "/dev/ttyACM0". While plugged in, hold in the DFU-button and simultaneously press the reset button. This puts the anchor in DFU-mode, which may be seen visibly on the board with the mode LED (orange) turning off.
The next step is to flash the firmware via DFU, done simply by typing sudo make dfu
in the lps-node-firmware, with an example printuot shown below:
DFU mode device DFU version 011a
Device returned transfer size 2048
DfuSe interface name: "Internal Flash "
file contains 1 DFU images
parsing DFU image 1
image for alternate setting 0, (1 elements, total size = 82404)
parsing element 1, address = 0x08000000, size = 82396
Download [=================== ] 79% 65536 bytes
Once completed, the device has been flashed with the new firmware. Repeat this process for each and every anchor.
Configuring the anchors
To configure the anchors, we will use picocom Links to an external site. to access the serial ports. Similar functionality will have to be installed if attempting to flash the anchors from an OSX or Windows machine. Ubuntu is set up to try to start all serial devices as modems automatically. We want this to stop so we remove this package. Execute these commands
sudo apt-get install picocom
sudo apt-get remove modemmanager
To be able to run picocom without being root, make sure that your user is in the dialout group. Execute
sudo adduser wasp dialout
assuming that your user is called wasp.
With this tool installed, repeat the following steps for each anchor to complete the configuration step.
- Mark the anchor physically with a unique integer **X** from 0-5 using the label maker
- Run `dmesg` (similar to the previous section) and find out which address the anchor is registered on (let's say ttyACM**Y**)
- Start picocom by ``picocom /dev/ttyACMY`` (if you did not add your user to dialout, you need to run this with sudo)
- Type h to see the available options
- Set the anchor to the address **X**
- Press 'a' to set the anchor mode to TWR. You can also set other modes by pressing 'm'. Another option would be TDOAv2, but for a small number of UAVs the TWR mode is best, since it typically gives larger available flying space.
- Type CTRL+a and then CTRL+q to exit picocom
Repeat this process for each and every anchor, until you have 6 anchors flashed with new firmware with addresses matching the labels on the anchors. You are now ready to set up the LPS-system and fly!
Setting up the system
To finalize the setup, place the anchors in a space so as to maximize the volume of the convex hull they span. This is important, especially for TDOA positioning, as the estimation accuracy quickly worsens when moving outside of this space. Establish the anchor positions in a global frame of reference, for instance by setting origin at the position of anchor 0, measuring all other anchor positions relative this frame. In the Lund robotics lab, we have the positions
ID:0, x: 0.00, y: 0.00, z: 0.00
ID:1, x: 0.00, y: 4.50, z: 0.00
ID:2, x: 2.55, y: 0.00, z: 2.14
ID:3, x: 2.55, y: 4.50, z: 2.14
ID:4, x: 0.00, y: 0.00, z: 3.05
ID:5, x: 0.00, y: 4.50, z: 3.05
this setup is illustrated graphically in the figure below
To enter this data, launch the cfclient
Links to an external site. and add the "Loco Positioning" tab. Switch on your Crazyflie and put on the UWB tag also found in the positioning package. Connect to the Crazyflie via the client and switch to an arbitrary address with 2Mbit/s. Restart the Crazyflie for the changes to take effect. Power on the Crazyflie and set the anchor positions in the "Loco Positioning", press the "write" button to configure the anchors. To verify that the anchors have been configured correctly, disconnect from the Crazyflie, restart the GUI and the Crazyflie and press the "read" button in the "Loco Positioning" tab. The addresses you wrote to the anchors should once again be visible in the client and when moving the Crazyflie, you should see the blue marker move around in the plots when physically displacing the UAV.
To test the setup, you could fly with the client and check the position control mode, which will run positional PID controllers in the Crazyflie! However, this assumes that you have a joystick to fly with.
An alternative is to wait for the next part of your Crazyflie experiments, where we will implement controllers and code necessary to fly the system with the LPS using your computer keyboard.