ARDUROVER with BBBmini Project made for ECE 785 Advanced Computer Design

Team Members: Pooja Bansal (pbansal2) Suraj Shanbhag (smshanbh)

OVERVIEW: The aim of the project was to interface the beaglebone with the APM rover in order to impart autonomy to the vehicle. The idea was to make the beaglebone as the gateway between the remote control and the vehicle and also interface with the sensors and communicate with the Ground Control Station(GCS) to give the commands to the rover. The GCS software is called Mission Planner and it runs on Windows OS. This report contains the details about the hardware and software required and procedure to be followed to build and launch the system.

HARDWARE: The basic hardware consists of a rover built to be compatible with the APM arduover software (we used the APM rover provided to us), Beagle Bone Black which forms the heart of the system, the BBB mini which is a cape on the BBB to interface with the other sensors and the Remote Control for providing the motion commands to the rover. The hardware of the BBBMini requires the following sensors: 1. MPU-9250 IMU 2. MS5611 barometer 3. 3Dr GPS 4. Wifi adapter 5. RC remote (Taranis capable of combined PWM output on one pin)

When all these components are connected to the beaglebone, an external power supply is required. In this project a battery pack with usb output of 5V and 2A was used. The connections are as shown below. The output to servo and ESC has to be on RC2(servo) and RC4(throttle). You can map these on the mission planner software under full parameter list. The

SOFTWARE: In order to run the entire system, we first need to flash the EEMC with the required version of for BBB (in our case it is BBB debian 8.6 compiled RT-kernel) and then set up a network for it to wirelessly connect to the computer running the GCS and install the ardurover software. Note: Link for the Debian image compiled with RT https://rcn-ee.net/rootfs/bb.org/testing/2016-10-02/console/BBB-blank-debian-8.6-console-armhf- 2016-10-02-2gb.img.xz The steps are as follows: 1. Setup WIFI a) ADHOC Wifi on beaglebone First step is to create an adHoc network with ssid “myADHOC” and IP on beaglebone is 10.10.1.1 Run all commands as root or using sudo ● apt-get update ● apt-get install wireless-tools -y ● iwconfig

● Install vim if not installed : apt-get install vim -y ● Copy the name of the wireless interface : in this case “wlxc46e1f23f5fe” ● vi /etc/network/interfaces ● Add the following lines in the interfaces file auto wlxc46e1f23f5fe iface wlxc46e1f23f5fe inet static address 10.10.1.1 netmask 255.255.255.0 wireless-channel 1 wireless-essid myADHOC wireless-mode ad-hoc

Description of the commands are as follows: auto wlxc46e1f23f5fe /// automatically load configuration iface wlxc46e1f23f5fe inet static /// configure statically address 10.10.1.1 // set ip as 10.10.1.1 (make sure this is not same as any in your network) netmask 255.255.255.0 // set appropriate netmask wireless-channel 1 // set channel 1-14 () wireless-essid myADHOC // name of the ADHOC network wireless-mode ad-hoc // set mode as ad-hoc (normally managed)

● ifup wlxc46e1f23f5fe ● iwconfig

● Shutdown and start beaglebone ( do not reboot ) ● Wait for the light on the adapter to turn on (wifi is up , if not login through wired and verify wireless properties) ● Wait for 1 minute after this to ensure wifi is up. ● Check in the wifi of laptop if the ssid is visible. If so the wifi is setup

Troubleshooting : ● Wifi needs more power and hence if powered using laptop usb the wifi may not function as expected. Use 5V,2A source ● Ensure that the wifi interface settings in /etc/network/interfaces are indented as shown ● Ensure the interface name is correct ● Also if wifi doesn't switch on, shutdown beaglebone, disconnect and reconnect power source and reboot

Useful Links https://wiki.debian.org/WiFi/AdHoc b) ADHOC wifi on Windows We will be connecting to adHoc network with ssid “myADHOC” and ip on windows should be set to 10.10.1.xxx. In our case we set the IP to 10.10.1.5 The following steps are to be followed:  Go to "Network and Sharing Center"  Click "Set up a new connection or network"  Double click "Manually connect to a wireless network"  Enter the SSID of the adhoc network (as shown by "netsh wlan show networks") into the "Network name" field In our case the ssid is “myADHOC”  Configure security settings accordingly

 Our network is not encrypted, hence use “No authentication(open)”  Uncheck "Start this connection automatically" (important)  Click "Next", then "Close"  Go to "Network and Sharing Center"  Go to “change adapter settings”  Go to the wireless card used to connect to the adhoc network and open properties by right clicking on the wifi network card.

● Double click in “Internet Protocol Version 4 (TCP/IPv4)” and set values as shown ○ Ip address: 10.10.1.5 ○ Subnet mask : 255.255.255.0

● Click “ok” and close. ● Open cmd as administrator

● Run the following commands: netsh wlan set profileparameter myADHOC connectiontype=ibss connectionmode=manual netsh wlan connect name="myADHOC" ssid="myADHOC" interface="Wi-Fi 3" pause

Here interface="Wi-Fi 3" should be set as the name of the wireless network. This is the name of the card as displayed in change adapter settings.

“Wi-Fi 3” was an external adapter used during this example.

In case you are using the default wi-fi adapter of your system, you need not add the interface property.

● Ping the bone to verify (IP of the BBB was set to 10.10.1.1)

● Make sure beaglebone wifi is up first ● Make sure you wait for a minute after beaglebone wifi is up before starting windows network. ● At this point you should be able to ssh into the beaglebone at ssh [email protected]

Issues with wifi

The image of debian flashed on the EEMC is compiled with Rt-kernel and might be missing a few packages. So when we connect the wifi adapter we can see that the adapter is not configured correctly. And connecting to a wpa-protected Wifi access point can fail. Hence ADHOC mode should be preferred with this adapter. In case one wishes to install the adapter follow the instructions below.

Download all files starting with rtl8192cufw from this link https://git.kernel.org/cgit/linux/kernel/git/firmware/linux-firmware.git/tree/rtlwifi

Copy them to /lib/firmware/rtlwifi/ (create the directory if required) This is automatically done in the setupbeaglebone_1.sh After this we were able to connect to a unprotected wifi network. When the network is encrypted connection is not established and we get an error which mentions that the interface is not found. Hence adhoc was chosen as it didn’t have any issue.

2. Setup software for ardupilot

● Create 3 files (setupbeaglebone_1.sh, setupbeaglebone_2.sh, setupbeaglebone_3.sh) with contents as shown in Appendix in /root ● Run the following commands: (https://github.com/surajshanbhag/arduPilot_Rover) ○ chmod +x setupbeaglebone* ○ ./setupbeaglebone_1.sh ○ Sudo shutdown -r now ○ ./setupbeaglebone_2.sh ○ Sudo shutdown -r now ○ ./setupbeaglebone_3.sh ○ Sudo shutdown -r now ● If all scripts run with no errors then the beaglebone is setup to run ardupilot. ● We have to now build the ardupilot for beaglebone. It can be done on beaglebone(very slow) or on laptop as follows ( requires Ubuntu) ● We used a laptop having ubuntu as it was faster. The following steps were followed: ○ git clone https://github.com/diydrones/ardupilot.git ○ cd ardupilot ○ ./Tools/scripts/install-prereqs-ubuntu.sh ○ git checkout Copter-3.4 for ArduCopter or git checkout ArduPlane-3.7.1 for ArduPlane ○ git submodule update --init --recursive ○ alias ="$PWD/modules/waf/waf-light" ○ waf configure --board=bbbmini ○ waf ○ scp build/bbbmini/bin/* [email protected]:/home/debian/ ● Compile examples to test the hardware ○ cd ardupilot

○ git checkout master ○ git submodule update --init --recursive ○ alias waf="$PWD/modules/waf/waf-light" ○ waf configure --board=bbbmini ○ waf examples ○ scp build/bbbmini/examples/* [email protected]:/home/debian/ This completes the setup for Ardupilot

Once this done, the next step is to test the hardware connected to the BBB mini i.e. MPU-9250 10DOF IMU, MS5611 Barometer, and 3DR GPS. The following executables are to be run

Testing GPS: ● Run: sudo /home/debian/GPS_AUTO_test -B /dev/ttyO5

Testing IMU: ● Run: sudo /home/debian/INS_generic ● Hit enter once after about 30 seconds.

Testing Compass:  Run: sudo /home/debian/AP_Compass_test

These outputs confirm that the beaglebone is able to communicate to the sensors.

3) Mission Planner

The next step is to connect to Mission Planner.

● Install Mission Planner from this link: http://ardupilot.org/planner/docs/common-install-mission- planner.html on the laptop which will run the GCS ● Run : /home/debian/ardurover sudo /home/debian/arducopter-quad -C udp:10.10.1.5:14550 - B /dev/ttyO5 The highlighted IP is the IP of the laptop

● Run mission Planner ● Select UDP in Click on ‘Connect’

Once you are connected you see the rover with a GPS location shown as below. We notice that the left window says “Disarmed” which means that the throttle is disabled. For the purpose of this project, the Arming check is disabled by writing Arming_Require paramter as 0(disabled).

Please note that the first channel (RC1) is configured for servo and hence will be running a PWM. If the throttle or ESC is connected to this, the vehicle will move. The RC3 is configured for throttle by default. In our case this configuration was not working to use the Remote Control with us and thus we reconfigured the RC channels for the rover, the details of which have been mentioned further on in the report.

Fig: The mission planner is connected to the rover and can detect the location of the rover quite accurately. The text below the map shows the GPS co-ordinates

First step in Mission planner is to calibrate all the sensors. For this, go to ‘Initial Setup’ Menu. Click on Acceleration Calibration, Compass and Radio Calibration consecutively and complete the steps mentioned. For Compass, Select Live Calibration. For Flight Modes set the mode in green to Manual. For Failsafe, check the ‘GCS FS Enable’. Following screenshots show the steps.

Change the mode for the green one to manual.

Once all the calibrations are done, we need to map the remote controller to the GCS. Go to ‘Config/Tuning’ menu to set the parameters to map the Radio to the outputs. Use the RCMAP to search the parameters. Depending on which channels on the radio are connected to which sticks the configuration may change. For our radio the mapping was as follows:

● right side stick up-down control : channel 4 ● Right side stick left-right control : channel 1

● Left side stick up-down control : channel 3 ● Left side stick left-right control : channel 2 We have mapped throttle to channel 4 and steering to channel 2

Every time the parameters are updated, click on ‘Write Parameters’ and Refresh. Also disconnect mission planner from BBB, stop the application on the beaglebone and restart it. This ensures that the parameters have been reflected.

The rover is now ready to controlled by the RC and good to go!

CONCLUSION: We have successfully integrated the beaglebone with bbbmini and ardupilot to control the rover through the ardupilot software.

FUTURE WORK: As the manual mode is working successfully, we will focus on make the rover run on ‘Auto’ mode by specifying waypoints in the mission planner.

APPENDIX

Create this 3 files on beaglebone with their contents: 1. setupbeaglebone_1.sh

#!/bin/bash -x #setup beaglebone for ARduCopter echo "update debian" sudo apt-get update sudo apt-get upgrade -y echo "install software" sudo apt install -y cpufrequtils g++ liblttng-ust-dev pkg-config gawk git make device-tree-compiler screen python python-dev python-lxml python-pip sudo pip install future sudo ln -s pkg-config /usr/bin/arm-linux-gnueabihf-pkg-config cd /opt/scripts && sudo git pull sudo /opt/scripts/tools/grow_partition.sh sudo /opt/scripts/tools/update_kernel.sh --bone-rt-kernel --lts-4_4 sudo sed -i 's/#dtb=$/dtb=am335x-boneblack-bbbmini.dtb/' /boot/uEnv.txt sudo sed -i 's/GOVERNOR="ondemand"/GOVERNOR="performance"/g' /etc/init.d/cpufrequtils

echo "setup wifi" sudo apt-get install -y wireless-tools unzip dhcpcd5 sudo apt-get install -y build-essential linux-headers-$(uname -r) cd ~/ wget https://git.kernel.org/cgit/linux/kernel/git/firmware/linux- firmware.git/tree/rtlwifi/rtl8192cufw_TMSC.bin wget https://git.kernel.org/cgit/linux/kernel/git/firmware/linux- firmware.git/tree/rtlwifi/rtl8192cufw.bin wget https://git.kernel.org/cgit/linux/kernel/git/firmware/linux- firmware.git/tree/rtlwifi/rtl8192cufw_A.bin wget https://git.kernel.org/cgit/linux/kernel/git/firmware/linux- firmware.git/tree/rtlwifi/rtl8192cufw_B.bin cp rtl8192cufw* /lib/modules/4.4.22-ti- r49/kernel/drivers/net/wireless/realtek/rtlwifi/ cp rtl8192cufw* /lib/modules/4.4.22-ti- r49/kernel/drivers/net/wireless/realtek/rtlwifi/rtl8192cu

rm -rf ~/rtl8192cufw*

2. setupbeaglebone_2.sh

#!/bin/bash -x

RED='\033[0;31m' NC='\033[0m' # No Color cd ~/ printf "${RED}git clone https://github.com/beagleboard/bb.org- overlays${NC}" git clone https://github.com/beagleboard/bb.org-overlays printf "${RED}cd ./bb.org-overlays && ./install.sh${NC}" cd ./bb.org-overlays && ./install.sh printf "${RED}sudo sed -i 's/#cape_enable=bone_capemgr.enable_partno=/cape_enable=bone_capemgr.enabl e_partno=BB-ADC/g' / boot/uEnv.txt ${NC}" sudo sed -i 's/#cape_enable=bone_capemgr.enable_partno=/cape_enable=bone_capemgr.enabl e_partno=BB-ADC/g' /boot/uEnv.txt cd ~/ printf "${RED}git clone https://github.com/ArduPilot/ardupilot.git${NC}" git clone https://github.com/ArduPilot/ardupilot.git

3. setupbeaglebone_3.sh

#!/bin/bash -x cd ~/ardupilot/Tools/Linux_HAL_Essentials/pru/rangefinderpru sudo make install