Comparison of a Raspberry Pi 3B and Jetson Nano Artificial Intelligence Efficiency on a Ground Drone

Page 1


Comparison of Raspberry Pi 3 B and Jetson Nano Artificial Intelligence Efficiency on a Ground Drone

Which computing system is more efficient for the ground drone usage?

Maliik Jones


Acknowledgements: I would like to thank my mentor Ean Mikale, J.D. for guidance and access to the resources used in this experiment.

Table of Contents: Abstract p. 3 Question p. 3 Introduction p. 4 Hypothesis p. 4 Methods p. 5 Results p. 5 Conclusion p. 6 Bibliography p. 7 Tables p. 8 Graphs p. 9 Figures 1-2 p. 10 Figures 3-4 p. 11 Programming Protocols p. 12


Abstract: Ground drones are used in multiple ways: delivery services, security monitoring, transporting items, and accessing dangerous/hard to reach areas. There has been a recent increase in food delivery ground drones; for example, college campuses alone implemented 1,000 units in 2019 with 5,000 units expected by 2021. Artificial intelligence plays a major role in drone task completion and requires the drone to have a more complex computing system. The drone must be operated using the most efficient computing system, and currently they are limited by their battery life. This experiment tested the efficiency of the Raspberry Pi 3 B and the NVIDIA Jetson Nano on latency to boot up and battery life on a ground drone. The latency for each computing system to boot up was tested. The two drones were fully charged and run until the battery died. The Jetson Nano had a 16.7% shorter latency to boot up compared to the Raspberry Pi 3 B. However, the battery in the drone with the Raspberry Pi 3 B ran 41.8% longer than the drone with the Jetson Nano computing system. In conclusion, the Jetson Nano has a shorter latency to boot up, but the battery died more quickly than the Raspberry Pi 3 B. The Jetson Nano is more complex with artificial intelligence which requires more power, and this may be the reason the battery dies more quickly. In the future, I will test battery life in ground drones with and without a solar panel to address battery life limitation.

Question: Which computing system is more efficient for ground drone usage?


Introduction: Ground drones are used in multiple ways; for example, there has been a recent increase in food delivery ground drones. College campuses alone implemented at least 1,000 units in 2019 with 5,000 units expected by 2021 (Starship, 2019). Other examples of ways ground drones are being used include security monitoring, transporting items, and accessing dangerous/hard to reach areas. The implementation of ground drones in society will keep expanding and uses for them will keep broadening. The ground drone must be operated using the most efficient and powerful computing system, and currently they are limited by their battery life. Artificial intelligence plays a major role in drone task completion and requires the drone to have a more complex computing system. NVIDIA Jetson Nano is a computing system that brings the power of artificial intelligence to the platform of drones in an easy to use way (Monteiro et al., 2019). This experiment compared the NVIDIA Jetson Nano and the Raspberry Pi 3 B computing systems on a ground drone. Both computing systems are offered at a low-price point compared to alternative options. This experiment tested the latency to boot up the two computing systems and the battery life of both ground drones. The latency to boot up test shows how the Jetson Nano compares to the Raspberry Pi 3 B operating efficiency. This shows the difference in the speed that the computing system is going to be able to complete commands. The battery life test shows how long the ground drone will run on each system. This shows how much power is being used from the computing system. The information gained from this experiment will benefit society by providing the most efficient small scale and powerful computing system to use on ground drones.

Hypothesis: I hypothesize the ground drone with the Jetson Nano will have a shorter latency to boot up and shorter battery life than the Raspberry Pi 3 B.


Methods: To conduct this experiment, I built two identical ground drones with different computing systems. The list of materials used is in Table 1. The first step was assembling the ground drone using the TRAXXAS Ford Fiesta ST Rally RTR 1/10 4WD Rally Car w/TQ 2.4GHz Radio as a chassis. The power system was the TRAXXAS Velineon Brushless Power System Waterproof 1/10. I installed a black plastic cover on top of the chassis and drilled holes in precise proximity close enough that wires could connect all technical equipment that was held in place using the holes drilled (Figure 1 and 2). The Raspberry Pi 3 B (Figure 3) was installed on one ground drone, and the Jetson Nano (Figure 4) was installed on the other ground drone in the central area of the black plastic cover to allow access for connecting components. The technical specifications of both computing systems are in Table 2. A RPI PowerPack V2.0 was connected to power the computing system and allowing it to drive in a large radius. Ubuntu 16.04 operating system was used to program all software on the ground drone. DonkeyCar was installed on a 128GB microSD card to setup the driving of the ground drone. This software requires prerequisites along with extensive download periods. I programed the DonkeyCar software and wrote protocols for both computing systems (Protocol 1 and 2). The LRP B4-RX Pro 2.4 GHz FHSS Receiver ports one and two were wired into the power system. The LRP B2-STX Pro 2.4GHz Radio Set was then connected through Bluetooth Commnication. The throttle controls were programmed to full power for the DonkeyCar software. The latency for each ground drone to boot up was recorded. Lastly, to test battery life a PlayStation 3 Gaming Controller was used to run the ground drone until the 11.1V RC battery ran out. These same exact procedures were completed on both the ground drone with the Raspberry Pi 3 B and the ground drone with Jetson Nano computing systems for comparison.

Results: The purpose of this experiment was to compare the efficiency of Raspberry Pi 3 B and NVIDIA Jetson Nano computing systems on ground drones. The Jetson Nano had a 16.7% shorter latency to boot up compared to the Raspberry Pi 3 B (30 seconds and 36 seconds respectively). However, the battery in the drone with the Raspberry Pi 3 B ran 41.8% longer than the drone with the Jetson Nano computing system (73 minutes and 42.5 minutes respectively). Data table 1 and Graph 1 have the results for the latency to boot up and battery life tests.


Conclusion: The hypothesis was the ground drone with the NVIDIA Jetson Nano computing system will have a shorter latency to boot up and shorter battery life than the ground drone with the Raspberry Pi 3 B. The Jetson Nano had a 16.7% shorter latency to boot up compared to the Raspberry Pi 3 B. The Jetson Nano has a shorter latency to boot up due to it having a faster GPU and CPU. Battery life was 41.8% shorter on the Jetson Nano compared to the Raspberry Pi 3 B. The Jetson Nano requires more power to run; therefore, the battery dies more quickly compared to the Raspberry Pi 3 B. The dependencies are slightly different for the Jetson Nano and Raspberry Pi 3 B, so it requires slightly different programming. The Jetson Nano has more dynamic software, so it requires more power. The results indicate that the hypothesis was supported. The Jetson Nano provides more efficient usage. The newly released Jetson Nano allows the performance of higher level, deep learning artificial intelligence which is not offered with the Raspberry Pi 3 B. The Raspberry Pi 3 B offers similar values as the Jetson Nano; however, the Raspberry Pi 3 B is slower and more out of date. Maksimović et el. (2019) compared the Raspberry Pi 3 B to the Udoo, another small-scale computing system, and found that the Raspberry Pi 3 B was even less efficient than the Udoo. The Jetson Nano is the best choice for a small-scale computing system. In the future, I will test battery life with and without a solar panel attachment to address the issue of limited battery life in ground drones.


References: 1. “World's Largest Fleet of Delivery Robots on a University Campus Launched by Starship

Technologies and Sodexo.” Starship, Starship Technologies Inc., www.starship.xyz/press_releases/worlds-largest-fleet-of-delivery-robots-on-a-universitycampus-launched-by-starship-technologies-and-sodexo/ (2019) 2. Monteiro, Filipe Figueredo, et al. “Simulating Real Robots in Virtual Environments Using NVIDIA's Isaac SDK.” Anais Estendidos Do Simpósio De Realidade Virtual e Aumentada (SVR), SBC, sol.sbc.org.br/index.php/svr_estendido/article/view/8471 3. Maksimović, Vladimir, et al. “Raspberry Pi as Internet of Things hardware: Performances and Constraints” (2019) https://www.researchgate.net/profile/Vladimir_Vujovic/publication/280344140_ELI16_ Maksimovic_Vujovic_Davidovic_Milosevic_Perisic/links/55b3368608ae9289a08594aa.p df (2019)

.


Table 1: Bill of Materials

Table 2: Technical Specifications


Data Table 1:

Graph 1:


Figure 1: Top View of Ground Drone

Figure 2: Side View of Ground Drone


Figure 3: Raspberry Pi 3 B

Figure 4: NVIDIA Jetson Nano


Progamming Protocol 1: Donkey Car Build 1.0 for NVIDIA Jetson Nano

//Install VirtualBox sudo apt install virtualbox //start virtualbox virtualbox //for added features you may wish to install the Virtualbox extension sudo apt install virtualbox-ext-pack //Download Ubuntu ISO https://ubuntu.com/download/desktop //Install Ubuntu 18.04 on VirtualBox virtualbox //Select New icon and name a new VM //Select Start or Run Icon //Browse Files to select the Ubuntu ISO //Walk through Ubuntu installation steps //Install Archiconda3 wget https://github.com/Archiconda/build-tools/releases/download/0.2.2/Archiconda3-0.2.2Linux-aarch64.sh sh Archiconda3-0.2.2-Linux-aarch64.sh //Select Enter yes //Select Enter yes //Output should say Thank you for installing Archiconda3! sudo ldconfig //close terminal and reopen. //Install Donkeycar mkdir projects


cd projects sudo apt-get install git git clone https://github.com/autorope/donkeycar cd donkeycar git checkout master conda update -n base -c defaults conda conda env remove -donkey cd ~/donkeycar conda env create -f install/envs/ubuntu.yml conda activate donkey pip install -e .[pc] Visit: https://docs.nvidia.com/deeplearning/frameworks/install-tf-jetson-platform/index.html to install tensorflow donkey createcar --path ~/mycar sudo ldconfig //close terminal window and re-open. conda activate donkey sudo ldconfig sudo apt-get update //Next Install Software on Donkeycar [Actual PI] STEP 1: FLASH OPERATING SYSTEM You need to flash a micro SD image with an operating system. 



Download Maverick OS (16GB Card or larger). Leave micro SD card in your machine and edit/create some files as below:

STEP 2: SETUP THE WIFI FOR FIRST BOOT We can create a special file which will be used to login to wifi on first boot. More reading here, but we will walk you through it. On Windows, with your memory card image burned and memory disc still inserted, you should see two drives, which are actually two partitions on the mem disc. One is labeled boot. On Mac


and Linux, you should also have access to the boot partition of the mem disc. This is formatted with the common FAT type and is where we will edit some files to help it find and log-on to your wifi on its first boot. Note: If boot is not visible right away, try unplugging and re-inserting the memory card reader.  

Start a text editor: gedit on Linux. Notepad++ on Windows. TextEdit on a Mac. Paste and edit this contents to match your wifi:

country=USctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdevupdate_config=1network={ ssid="<your network name>" psk="<your password>"} Replace <your network name> with the ID of your network. Leave the quotes. I've seen problems when the network name contained an apostrophe, like "Joe's iPhone". Replace <your password> with your password, leaving it surrounded by quotes. If it bothers you to leave your password unencrypted, you may change the contents later once you've gotten the pi to boot and log-in. 

Save this file to the root of boot partition with the filename wpa_supplicant.conf. On first boot, this file will be moved to /etc/wpa_supplicant/wpa_supplicant.conf where it may be edited later. If you are using Notepad on Windows, make sure it doesn't have a .txt at the end.

STEP 3: SETUP PI'S HOSTNAME Note: This step only possible on a linux host pc. Otherwise you can set it up later in raspi-config after logging in to your pi. We can also setup the hostname so that your Pi easier to find once on the network. If yours is the only Pi on the network, then you can find it with ping raspberrypi.local once it's booted. If there are many other Pi's on the network, then this will have problems. If you are on a Linux machine, or are able to edit the UUID partition, then you can edit the /etc/hostname and /etc/hosts files now to make finding your pi on the network easier after boot. Edit those to replace raspberrypi with a name of your choosing. Use all lower case, no special characters, no hyphens, yes underscores _. sudo vi /media/userID/UUID/etc/hostnamesudo vi /media/userID/UUID/etc/hosts STEP 4: ENABLE SSH ON BOOT Put a file named ssh in the root of your boot partition. Now your SD card is ready. Eject it from your computer, put it in the Pi and plug in the Pi.


STEP 5: CONNECTING TO THE PI If you followed the above instructions to add wifi access, your Pi should now be connected to your wifi network. Now you need to find its IP address so you can connect to it via SSH. The easiest way (on Ubuntu) is to use the findcar donkey command. You can try ping raspberrypi.local. If you've modified the hostname, then you should try: ping <your hostname>.local. This will fail on a windows machine. Windows users will need the full IP address (unless using cygwin). If you are having troubles locating your Pi on the network, you will want to plug in an HDMI monitor and USB keyboard into the Pi. Boot it. Login with:  

Username: pi Password: raspberry

Then try the command: ifconfig wlan0 If this has a valid IPv4 address, 4 groups of numbers separated by dots, then you can try that with your SSH command. If you don't see anything like that, then your wifi config might have a mistake. You can try to fix with sudo nano /etc/wpa_supplicant/wpa_supplicant.conf If you don't have a HDMI monitor and keyboard, you can plug-in the Pi with a CAT5 cable to a router with DHCP. If that router is on the same network as your PC, you can try: ping raspberrypi.local Hopefully, one of those methods worked and you are now ready to SSH into your Pi. On Mac and Linux, you can open Terminal. On Windows you can install Putty, one of the alternatives, or on Windows 10 you may have ssh via the command prompt. If you have a command prompt, you can try: ssh pi@raspberrypi.local or ssh pi@<your pi ip address> or via Putty.   

Username: pi Password: raspberry Hostname:<your pi IP address>


STEP 6: UPDATE AND UPGRADE sudo apt-get updatesudo apt-get upgrade STEP 7: RASPI-CONFIG sudo raspi-config     

change default password for pi change hostname enable Interfacing Options | I2C enable Interfacing Options | Camera Advanced Options | Exapand Filesystem

Choose and hit enter. Note: Reboot after changing these settings. Should happen if you say yes. STEP 8: INSTALL DEPENDENCIES sudo apt-get install build-essential python3 python3-dev python3-pip python3-virtualenv python3-numpy python3-picamera python3-pandas python3-rpi.gpio i2c-tools avahi-utils joystick libopenjp2-7-dev libtiff5-dev gfortran libatlas-base-dev libopenblas-dev libhdf5-serialdev git STEP 9: INSTALL OPTIONAL OPENCV DEPENDENCIES If you are going for a minimal install, you can get by without these. But it can be handy to have OpenCV. sudo apt-get install libilmbase-dev libopenexr-dev libgstreamer1.0-dev libjasper-dev libwebpdev libatlas-base-dev libavcodec-dev libavformat-dev libswscale-dev libqtgui4 libqt4-test STEP 10: SETUP VIRTUAL ENV //Setup VirtualBox //Ubuntu VM Download - https://www.virtualbox.org/wiki/Linux_Downloads //Download Ubuntu 18.04 ISO - https://ubuntu.com/download/desktop //Install conda Ubuntu GPU environment - http://www.mousemotorlab.org/deeplabcut python3 -m virtualenv -p python3 env --system-site-packagesecho "source env/bin/activate" >> ~/.bashrcsource ~/.bashrc Modifying your .bashrc in this way will automatically enable this environment each time you login. To return to the system python you can type deactivate. STEP 11: INSTALL DONKEYCAR PYTHON CODE ON RASPBERRY PI  Change to a dir you would like to use as the head of your projects. mkdir projectscd projects


Get the latest donkeycar from Github.

git clone https://github.com/autorope/donkeycarcd donkeycargit checkout masterpip3 install -e .[pi]pip3 install tensorflow==1.13.1 //May have errors, if so, proceed to next step You can validate your tensorflow install with python -c "import tensorflow" Import OpenCV python -c "import cv2" STEP 12: INSTALL DONKEYCAR PYTHON CODE ON JETSON NANO //Burn UBUNTU 18.04 OS to Micro-SD by going to Jetson Nano Get Started page //Install Dependencies sudo apt-get updatesudo apt-get upgradesudo apt-get install build-essential python3 python3dev python3-pip libhdf5-serial-dev hdf5-tools nano Change to a dir you would like to use as the head of your projects. mkdir projectscd projects 

Get the latest donkeycar from Github.

git clone https://github.com/autorope/donkeycarcd donkeycargit checkout masterpip3 install -e .[pi]pip3 install tensorflow==1.13.1 //May have errors, if so, proceed to next step You can validate your tensorflow install with python -c "import tensorflow" Import OpenCV python -c "import cv2" STEP 13: CREATE DONKEYCAR APPLICATION //Create application donkey createcar --path ~/mycar STEP 13.1: CALIBRATE ESC ON TRAXXAS BUGGY  Plug in battery and then start the transmitter. Make sure all the trims are at zero (Steering, Throttle).  With the speed controller off, press and hold the on button, until it turns green and then red. Then immediately let go.  After it flashes red once, hold the full throttle on on the receiver, until it flashes red twice.


 

Then hold the receiver in full reverse, until it flashes green. Then return the trigger to the neutral position. Put car into lipo-safe mode, by turning on vehicle, and holding the power button for 10 seconds, until you hear a chime, and the light on the ESC turns green.

STEP 13.2: SELECT VEHICLE MODE  Sport Mode - (100% Throttle, 100% Brake, 100% Reverse) This is the default mode. Turn the power on. Hold the power button until it blinks red one time.  Racing Mode - (100% Throttle, 100% Brake, 0% Reverse) This is the default mode. Turn the power on. Hold the power button until it blinks red twice.  Racing Mode - (50% Throttle, 100% Brake, 100% Reverse) This is the default mode. Turn the power on. Hold the power button until it blinks red three times. STEP 14: CONFIGURE OPTIONS //Look at myconfig.py in your newly created directory, ~/mycar nano myconfig.py //Each line has a comment mark. The commented text shows the default value. When you want to make an edit to over-write //the default, un-comment the line by removing the # and any spaces before the first character of the option. Jetson Nano: set PCA9685_I2C_BUSNUM = 1 in your myconfig.py . For the pi, this will be auto detected by the Adafruit library. But not on the Jetson Nano. //Steering Port is 0, while the Throttle Port is 1 STEERING_LEFT_PWM = 460 //becomes STEERING_LEFT_PWM = 500 //when edited. You will adjust these later in the calibrate section. Now open your myconfig.py script and enter the PWM values for your car into the throttle_controller part:   

THROTTLE_FORWARD_PWM = PWM value for full throttle forward (My values = 460) THROTTLE_STOPPED_PWM = PWM value for zero throttle (My values = 380) THROTTLE_REVERSE_PWM = PWM value at full reverse throttle (My values = 215)

STEP 15: CONFIGURE I2C PCA9685 // If you are using a PCA9685 card, make sure you can see it on I2C. Replace with your Linux username. Jetson Nano:


sudo usermod -aG i2c <username>sudo reboot //After a reboot, then try: sudo i2cdetect -r -y 1 Raspberry Pi: sudo apt-get install i2c-toolssudo i2cdetect -y 1 //This should show you a grid of addresses like: 0 1 2 3 4 5 6 7 8 9 a b c d e f00: -- -- -- -- -- -- -- -- -- -- -- -- --10: -- -- -- -- -- -- -- -- --- -- -- -- -- -- --20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --40: 40 --- -- -- -- -- -- -- -- -- -- -- -- -- --50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --60: -- -- -- -- -- -- -- -- -- -- -- -- --- -- --70: 70 -- -- -- -- -- -- -//In this case, the 40 shows up as the address of our PCA9685 board. If this does not show up, then check your wiring to the //board. On a pi, ensure I2C is enabled in sudo raspi-config //If you have assigned a non-standard address to your board, then adjust the address in the myconfig.py PCA9685_I2C_ADDR. If //your board is on another bus, then you can specify that with the PCA9685_I2C_BUSNUM. //Jetson Nano: set PCA9685_I2C_BUSNUM = 1 in your myconfig.py . For the pi, this will be auto detected by the //Adafruit library. But not on the Jetson Nano. STEP 16: CONTROLLER PARTS WEB CONTROLLER The default controller to drive the car with your phone or browser. This has a web live preview of camera. Control options include:    

A virtual joystick The tilt, when using a mobile device with supported accelerometer A physical joystick using the web adapter. Support varies per browser, OS, and joystick combination. Keyboard input via the 'ikjl' keys.

Note: Recently iOS has disabled default Safari access to motion control. JOYSTICK CONTROLLER Many people find it easier to control the car using a game controller. There are several parts that provide this option. The default web controller may be replaced with a one line change to use a physical joystick part for input. This uses the OS device /dev/input/js0 by default. In theory, any joystick device that the OS mounts like this can be used. In practice, the behavior will change depending on the


model of joystick ( Sony, or knockoff ), or XBox controller and the Bluetooth driver used to support it. The default code has been written and tested with a Sony brand PS3 Sixaxis controller. Other controllers may work, but will require alternative Bluetooth installs, and tweaks to the software for correct axis and buttons. THESE JOYSTICKS ARE KNOWN TO WORK:  Logitech Gamepad F710  Sony PS3 Sixaxis OEM (Not compatible with Jetson Nano)  Sony PS4 Dualshock OEM  WiiU Pro  XBox Controller  SteelSeries Nimbus (works only on TX2 jetpack 4.2+, may work on the Nano) These can be enabled by finding the CONTROLLER_TYPE in your myconfig.py and setting it to the correct string identifier ( after disabling the comment ). These can be used plugged in with a USB cable. It's been much more convenient to setup Bluetooth for a wireless control. There are controller specific setup details below. CUSTOMIZING OR ADDING A NEW CONTROLLER TYPE Note: If are having troubles getting your controller to work, try this Joystick Wizard. This can help customize your buttons and axis inputs as well. CHANGE TO CONFIG.PY OR RUN WITH --JS python manage.py drive --js Will enable driving with the joystick. This disables the live preview of the camera and the web page features. If you modify config.py to make USE_JOYSTICK_AS_DEFAULT = True, then you do not need to run with the --js. STEP 17: XBOX ONE CONTROLLER BLUETOOTH PAIRING This code presumes the built-in linux driver for 'Xbox Wireless Controller'; this is pre-installed on Raspbian, so there is no need to install any other drivers. This will generally show up on /dev/input/js0. There is another userland driver called xboxdrv; this code has not been tested with that driver. The XBox One controller requires that the bluetooth disable_ertm parameter be set to true; to do this:   

edit the file /etc/modprobe.d/xbox_bt.conf (that may create the file; it is commonly not there by default) add the line: options bluetooth disable_ertm=1 reboot so that this takes affect.


 

after reboot you can verify that disable_ertm is set to true entering this command in a terminal: cat /sys/module/bluetooth/parameters/disable_ertm the result should print 'Y'. If not, make sure the above steps have been done correctly.

Once that is done, you can pair your controller to your Raspberry Pi using the bluetooth tool. Enter the following command into a bash shell prompt: sudo bluetoothctl That will start blue tooth pairing in interactive mode. The remaining commands will be entered in that interactive session. Enter the following commands: agent ondefault-agentscan on That last command will start the Raspberry Pi scanning for new bluetooth devices. At this point, turn on your XBox One controller using the big round 'X' button on top, then start the pairing mode by pressing the 'sync' button on the front of the controller. Within a few minutes, you should see the controller show up in the output something like this; [NEW] Device B8:27:EB:A4:59:08 XBox One Wireless Controller Write down the MAC address, you will need it for the following steps. Enter this command to pair with your controller: connect YOUR_MAC_ADDRESS where YOUR_MAC_ADDRESS is the MAC address you copied previously. If it does not connect on the first try, try again. It can take a few tries. If your controller connects, but then immediately disconnects, your disable_ertm setting might be wrong (see above). Once your controller is connected, the big round 'X' button on the top of your controller should be solid white. Enter the following commands to finish: trust YOUR_MAC_ADDRESSquit Now that your controller is trusted, it should automatically connect with your Raspberry Pi when they are both turned on. If your controller fails to connect, run the bluetoothctl steps again to reconnect. PYGAME INSTALLATION Pygame requires Python; if you don't already have it, you can download it from python.org. Use python 3.6.1 or greater, because it is much friendlier to newbies, and additionally runs faster. The best way to install pygame is with the pip tool (which is what python uses to install packages). Note, this comes with python in recent versions. We use the --user flag to tell it to install into the home directory, rather than globally. python3 -m pip install -U pygame --user


To see if it works, run one of the included examples: python3 -m pygame.examples.aliens If it works, you are ready to go! Continue on to the tutorials.

FURTHER INFORMATION IF YOU NEED IT. Hopefully the installation instructions above worked for you. If not, please read some alternative installation methods, and extra details below. Wheels are available for x86 and x64 architectures on Linux and Windows, and for x64 on Mac. If pip doesn't find a wheel for your platform, it will try to compile pygame from source (see below). pygame requires a "newer" pip. If pygame starts compiling from source and fails, first try upgrading pip. RASPBERRY PI This comes with pygame already installed on the default raspbian installation. UNIX BINARY PACKAGES Many Linux and BSD distributions have their own packages of Pygame. These may have an older version of Pygame than the wheels, but have been carefully tested with other packages in that distribution. DEBIAN/UBUNTU/MINT sudo apt-get install python3-pygamepython3 -m pygame.examples.aliens FEDORA/RED HAT sudo yum install python3-pygamepython3 -m pygame.examples.aliens Distribution Python 3 package Python 2 package Debian/Ubuntu python3-pygame pythonpygame Fedora python3-pygame pygame FreeBSD also has an active pygame package. While techinicaly it isn't binary, it is automatically built and installed by the ports manager. See the FreeBSD package page for more information. http://www.freebsdports.info/ports/devel/py-gUDame.html Gentoo has a builtin package for pygame. This is compiled for your system as it installs, similar to BSD, http://packages.gentoo.org/package/dev-python/pygame PICAMERA INSTALLS sudo pip3 install PiCamera


sudo pip3 install ipython pyzmq tornadosudo apt-get install qv4l2 v4l-utils


Programming Protocol 2: Donkey Car Build 1.0 Raspberry Pi 3 B //Install VirtualBox sudo apt install virtualbox //start virtualbox virtualbox //for added features you may wish to install the Virtualbox extension sudo apt install virtualbox-ext-pack //Download Ubuntu ISO https://ubuntu.com/download/desktop //Install Ubuntu 18.04 on VirtualBox virtualbox //Select New icon and name a new VM //Select Start or Run Icon //Browse Files to select the Ubuntu ISO //Walk through Ubuntu installation steps //Install Miniconda wget https://repo.anaconda.com/miniconda/Miniconda2-latest-Linux-x86_64.sh sh Miniconda2-latest-Linux-x86_64.sh //Select Enter yes //Select Enter yes //Output should say Thank you for installing Miniconda2! sudo ldconfig //close terminal and reopen. //Install Donkeycar mkdir projects


cd projects sudo apt-get install git git clone https://github.com/autorope/donkeycar cd donkeycar git checkout master conda update -n base -c defaults conda conda env remove -donkey cd ~/donkeycar conda env create -f install/envs/ubuntu.yml conda activate donkey pip install -e .[pc] conda install tensorflow-gpu==1.13.1 python import tensorflow as tf donkey createcar --path ~/mycar sudo ldconfig //close terminal window and re-open. conda activate donkey sudo ldconfig sudo apt-get update //Next Install Software on Donkeycar [Actual PI] STEP 1: FLASH OPERATING SYSTEM You need to flash a micro SD image with an operating system. 

Download Maverick OS (16GB Card or larger). Leave micro SD card in your machine and edit/create some files as below:

STEP 2: SETUP THE WIFI FOR FIRST BOOT We can create a special file which will be used to login to wifi on first boot. More reading here, but we will walk you through it.


On Windows, with your memory card image burned and memory disc still inserted, you should see two drives, which are actually two partitions on the mem disc. One is labeled boot. On Mac and Linux, you should also have access to the boot partition of the mem disc. This is formatted with the common FAT type and is where we will edit some files to help it find and log-on to your wifi on its first boot. Note: If boot is not visible right away, try unplugging and re-inserting the memory card reader.  

Start a text editor: gedit on Linux. Notepad++ on Windows. TextEdit on a Mac. Paste and edit this contents to match your wifi:

country=USctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdevupdate_config=1network={ ssid="<your network name>" psk="<your password>"} Replace <your network name> with the ID of your network. Leave the quotes. I've seen problems when the network name contained an apostrophe, like "Joe's iPhone". Replace <your password> with your password, leaving it surrounded by quotes. If it bothers you to leave your password unencrypted, you may change the contents later once you've gotten the pi to boot and log-in. 

Save this file to the root of boot partition with the filename wpa_supplicant.conf. On first boot, this file will be moved to /etc/wpa_supplicant/wpa_supplicant.conf where it may be edited later. If you are using Notepad on Windows, make sure it doesn't have a .txt at the end.

STEP 3: SETUP PI'S HOSTNAME Note: This step only possible on a linux host pc. Otherwise you can set it up later in raspi-config after logging in to your pi. We can also setup the hostname so that your Pi easier to find once on the network. If yours is the only Pi on the network, then you can find it with ping raspberrypi.local once it's booted. If there are many other Pi's on the network, then this will have problems. If you are on a Linux machine, or are able to edit the UUID partition, then you can edit the /etc/hostname and /etc/hosts files now to make finding your pi on the network easier after boot. Edit those to replace raspberrypi with a name of your choosing. Use all lower case, no special characters, no hyphens, yes underscores _. sudo vi /media/userID/UUID/etc/hostnamesudo vi /media/userID/UUID/etc/hosts STEP 4: ENABLE SSH ON BOOT Put a file named ssh in the root of your boot partition. Now your SD card is ready. Eject it from your computer, put it in the Pi and plug in the Pi.


STEP 5: CONNECTING TO THE PI If you followed the above instructions to add wifi access, your Pi should now be connected to your wifi network. Now you need to find its IP address so you can connect to it via SSH. The easiest way (on Ubuntu) is to use the findcar donkey command. You can try ping raspberrypi.local. If you've modified the hostname, then you should try: ping <your hostname>.local. This will fail on a windows machine. Windows users will need the full IP address (unless using cygwin). If you are having troubles locating your Pi on the network, you will want to plug in an HDMI monitor and USB keyboard into the Pi. Boot it. Login with:  

Username: pi Password: raspberry

Then try the command: ifconfig wlan0 If this has a valid IPv4 address, 4 groups of numbers separated by dots, then you can try that with your SSH command. If you don't see anything like that, then your wifi config might have a mistake. You can try to fix with sudo nano /etc/wpa_supplicant/wpa_supplicant.conf If you don't have a HDMI monitor and keyboard, you can plug-in the Pi with a CAT5 cable to a router with DHCP. If that router is on the same network as your PC, you can try: ping raspberrypi.local Hopefully, one of those methods worked and you are now ready to SSH into your Pi. On Mac and Linux, you can open Terminal. On Windows you can install Putty, one of the alternatives, or on Windows 10 you may have ssh via the command prompt. If you have a command prompt, you can try: ssh pi@raspberrypi.local or ssh pi@<your pi ip address> or via Putty.   

Username: pi Password: raspberry Hostname:<your pi IP address>


STEP 6: UPDATE AND UPGRADE sudo apt-get updatesudo apt-get upgrade STEP 7: RASPI-CONFIG sudo raspi-config     

change default password for pi change hostname enable Interfacing Options | I2C enable Interfacing Options | Camera Advanced Options | Exapand Filesystem

Choose and hit enter. Note: Reboot after changing these settings. Should happen if you say yes. STEP 8: INSTALL DEPENDENCIES sudo apt-get install build-essential python3 python3-dev python3-pip python3-virtualenv python3-numpy python3-picamera python3-pandas python3-rpi.gpio i2c-tools avahi-utils joystick libopenjp2-7-dev libtiff5-dev gfortran libatlas-base-dev libopenblas-dev libhdf5-serialdev git STEP 9: INSTALL OPTIONAL OPENCV DEPENDENCIES If you are going for a minimal install, you can get by without these. But it can be handy to have OpenCV. sudo apt-get install libilmbase-dev libopenexr-dev libgstreamer1.0-dev libjasper-dev libwebpdev libatlas-base-dev libavcodec-dev libavformat-dev libswscale-dev libqtgui4 libqt4-test STEP 10: SETUP VIRTUAL ENV //Setup VirtualBox //Ubuntu VM Download - https://www.virtualbox.org/wiki/Linux_Downloads //Download Ubuntu 18.04 ISO - https://ubuntu.com/download/desktop //Install conda Ubuntu GPU environment - http://www.mousemotorlab.org/deeplabcut python3 -m virtualenv -p python3 env --system-site-packagesecho "source env/bin/activate" >> ~/.bashrcsource ~/.bashrc Modifying your .bashrc in this way will automatically enable this environment each time you login. To return to the system python you can type deactivate. STEP 11: INSTALL DONKEYCAR PYTHON CODE ON RASPBERRY PI  Change to a dir you would like to use as the head of your projects. mkdir projectscd projects


Get the latest donkeycar from Github.

git clone https://github.com/autorope/donkeycarcd donkeycargit checkout masterpip3 install -e .[pi]pip3 install tensorflow==1.13.1 //May have errors, if so, proceed to next step You can validate your tensorflow install with python -c "import tensorflow" Import OpenCV python -c "import cv2" STEP 12: INSTALL DONKEYCAR PYTHON CODE ON JETSON NANO //Burn UBUNTU 18.04 OS to Micro-SD by going to Jetson Nano Get Started page //Install Dependencies sudo apt-get updatesudo apt-get upgradesudo apt-get install build-essential python3 python3dev python3-pip libhdf5-serial-dev hdf5-tools nano Change to a dir you would like to use as the head of your projects. mkdir projectscd projects 

Get the latest donkeycar from Github.

git clone https://github.com/autorope/donkeycarcd donkeycargit checkout masterpip3 install -e .[pi]pip3 install tensorflow==1.13.1 //May have errors, if so, proceed to next step You can validate your tensorflow install with python -c "import tensorflow" Import OpenCV python -c "import cv2" STEP 13: CREATE DONKEYCAR APPLICATION //Create application donkey createcar --path ~/mycar STEP 13.1: CALIBRATE ESC ON TRAXXAS BUGGY  Plug in battery and then start the transmitter. Make sure all the trims are at zero (Steering, Throttle).  With the speed controller off, press and hold the on button, until it turns green and then red. Then immediately let go.  After it flashes red once, hold the full throttle on on the receiver, until it flashes red twice.


 

Then hold the receiver in full reverse, until it flashes green. Then return the trigger to the neutral position. Put car into lipo-safe mode, by turning on vehicle, and holding the power button for 10 seconds, until you hear a chime, and the light on the ESC turns green.

STEP 13.2: SELECT VEHICLE MODE  Sport Mode - (100% Throttle, 100% Brake, 100% Reverse) This is the default mode. Turn the power on. Hold the power button until it blinks red one time.  Racing Mode - (100% Throttle, 100% Brake, 0% Reverse) This is the default mode. Turn the power on. Hold the power button until it blinks red twice.  Racing Mode - (50% Throttle, 100% Brake, 100% Reverse) This is the default mode. Turn the power on. Hold the power button until it blinks red three times. STEP 14: CONFIGURE OPTIONS //Look at myconfig.py in your newly created directory, ~/mycar nano myconfig.py //Each line has a comment mark. The commented text shows the default value. When you want to make an edit to over-write //the default, un-comment the line by removing the # and any spaces before the first character of the option. Jetson Nano: set PCA9685_I2C_BUSNUM = 1 in your myconfig.py . For the pi, this will be auto detected by the Adafruit library. But not on the Jetson Nano. //Steering Port is 0, while the Throttle Port is 1 STEERING_LEFT_PWM = 460 //becomes STEERING_LEFT_PWM = 500 //when edited. You will adjust these later in the calibrate section. Now open your myconfig.py script and enter the PWM values for your car into the throttle_controller part:   

THROTTLE_FORWARD_PWM = PWM value for full throttle forward (My values = 460) THROTTLE_STOPPED_PWM = PWM value for zero throttle (My values = 380) THROTTLE_REVERSE_PWM = PWM value at full reverse throttle (My values = 215)

STEP 15: CONFIGURE I2C PCA9685 // If you are using a PCA9685 card, make sure you can see it on I2C. Replace with your Linux username. Jetson Nano:


sudo usermod -aG i2c <username>sudo reboot //After a reboot, then try: sudo i2cdetect -r -y 1 Raspberry Pi: sudo apt-get install i2c-toolssudo i2cdetect -y 1 //This should show you a grid of addresses like: 0 1 2 3 4 5 6 7 8 9 a b c d e f00: -- -- -- -- -- -- -- -- -- -- -- -- --10: -- -- -- -- -- -- -- -- --- -- -- -- -- -- --20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --40: 40 --- -- -- -- -- -- -- -- -- -- -- -- -- --50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --60: -- -- -- -- -- -- -- -- -- -- -- -- --- -- --70: 70 -- -- -- -- -- -- -//In this case, the 40 shows up as the address of our PCA9685 board. If this does not show up, then check your wiring to the //board. On a pi, ensure I2C is enabled in sudo raspi-config //If you have assigned a non-standard address to your board, then adjust the address in the myconfig.py PCA9685_I2C_ADDR. If //your board is on another bus, then you can specify that with the PCA9685_I2C_BUSNUM. //Jetson Nano: set PCA9685_I2C_BUSNUM = 1 in your myconfig.py . For the pi, this will be auto detected by the //Adafruit library. But not on the Jetson Nano. STEP 16: CONTROLLER PARTS WEB CONTROLLER The default controller to drive the car with your phone or browser. This has a web live preview of camera. Control options include:    

A virtual joystick The tilt, when using a mobile device with supported accelerometer A physical joystick using the web adapter. Support varies per browser, OS, and joystick combination. Keyboard input via the 'ikjl' keys.

Note: Recently iOS has disabled default Safari access to motion control. JOYSTICK CONTROLLER Many people find it easier to control the car using a game controller. There are several parts that provide this option. The default web controller may be replaced with a one line change to use a physical joystick part for input. This uses the OS device /dev/input/js0 by default. In theory, any joystick device that the OS mounts like this can be used. In practice, the behavior will change depending on the


model of joystick ( Sony, or knockoff ), or XBox controller and the Bluetooth driver used to support it. The default code has been written and tested with a Sony brand PS3 Sixaxis controller. Other controllers may work, but will require alternative Bluetooth installs, and tweaks to the software for correct axis and buttons. THESE JOYSTICKS ARE KNOWN TO WORK:  Logitech Gamepad F710  Sony PS3 Sixaxis OEM (Not compatible with Jetson Nano)  Sony PS4 Dualshock OEM  WiiU Pro  XBox Controller  SteelSeries Nimbus (works only on TX2 jetpack 4.2+, may work on the Nano) These can be enabled by finding the CONTROLLER_TYPE in your myconfig.py and setting it to the correct string identifier ( after disabling the comment ). These can be used plugged in with a USB cable. It's been much more convenient to setup Bluetooth for a wireless control. There are controller specific setup details below. CUSTOMIZING OR ADDING A NEW CONTROLLER TYPE Note: If are having troubles getting your controller to work, try this Joystick Wizard. This can help customize your buttons and axis inputs as well. CHANGE TO CONFIG.PY OR RUN WITH --JS python manage.py drive --js Will enable driving with the joystick. This disables the live preview of the camera and the web page features. If you modify config.py to make USE_JOYSTICK_AS_DEFAULT = True, then you do not need to run with the --js. STEP 17: XBOX ONE CONTROLLER BLUETOOTH PAIRING This code presumes the built-in linux driver for 'Xbox Wireless Controller'; this is pre-installed on Raspbian, so there is no need to install any other drivers. This will generally show up on /dev/input/js0. There is another userland driver called xboxdrv; this code has not been tested with that driver. The XBox One controller requires that the bluetooth disable_ertm parameter be set to true; to do this:   

edit the file /etc/modprobe.d/xbox_bt.conf (that may create the file; it is commonly not there by default) add the line: options bluetooth disable_ertm=1 reboot so that this takes affect.


 

after reboot you can verify that disable_ertm is set to true entering this command in a terminal: cat /sys/module/bluetooth/parameters/disable_ertm the result should print 'Y'. If not, make sure the above steps have been done correctly.

Once that is done, you can pair your controller to your Raspberry Pi using the bluetooth tool. Enter the following command into a bash shell prompt: sudo bluetoothctl That will start blue tooth pairing in interactive mode. The remaining commands will be entered in that interactive session. Enter the following commands: agent ondefault-agentscan on That last command will start the Raspberry Pi scanning for new bluetooth devices. At this point, turn on your XBox One controller using the big round 'X' button on top, then start the pairing mode by pressing the 'sync' button on the front of the controller. Within a few minutes, you should see the controller show up in the output something like this; [NEW] Device B8:27:EB:A4:59:08 XBox One Wireless Controller Write down the MAC address, you will need it for the following steps. Enter this command to pair with your controller: connect YOUR_MAC_ADDRESS where YOUR_MAC_ADDRESS is the MAC address you copied previously. If it does not connect on the first try, try again. It can take a few tries. If your controller connects, but then immediately disconnects, your disable_ertm setting might be wrong (see above). Once your controller is connected, the big round 'X' button on the top of your controller should be solid white. Enter the following commands to finish: trust YOUR_MAC_ADDRESSquit Now that your controller is trusted, it should automatically connect with your Raspberry Pi when they are both turned on. If your controller fails to connect, run the bluetoothctl steps again to reconnect. PYGAME INSTALLATION Pygame requires Python; if you don't already have it, you can download it from python.org. Use python 3.6.1 or greater, because it is much friendlier to newbies, and additionally runs faster. The best way to install pygame is with the pip tool (which is what python uses to install packages). Note, this comes with python in recent versions. We use the --user flag to tell it to install into the home directory, rather than globally. python3 -m pip install -U pygame --user


To see if it works, run one of the included examples: python3 -m pygame.examples.aliens If it works, you are ready to go! Continue on to the tutorials.

FURTHER INFORMATION IF YOU NEED IT. Hopefully the installation instructions above worked for you. If not, please read some alternative installation methods, and extra details below. Wheels are available for x86 and x64 architectures on Linux and Windows, and for x64 on Mac. If pip doesn't find a wheel for your platform, it will try to compile pygame from source (see below). pygame requires a "newer" pip. If pygame starts compiling from source and fails, first try upgrading pip. RASPBERRY PI This comes with pygame already installed on the default raspbian installation. UNIX BINARY PACKAGES Many Linux and BSD distributions have their own packages of Pygame. These may have an older version of Pygame than the wheels, but have been carefully tested with other packages in that distribution. DEBIAN/UBUNTU/MINT sudo apt-get install python3-pygamepython3 -m pygame.examples.aliens FEDORA/RED HAT sudo yum install python3-pygamepython3 -m pygame.examples.aliens Distribution Python 3 package Python 2 package Debian/Ubuntu python3-pygame pythonpygame Fedora python3-pygame pygame FreeBSD also has an active pygame package. While techinicaly it isn't binary, it is automatically built and installed by the ports manager. See the FreeBSD package page for more information. http://www.freebsdports.info/ports/devel/py-gUDame.html Gentoo has a builtin package for pygame. This is compiled for your system as it installs, similar to BSD, http://packages.gentoo.org/package/dev-python/pygame PICAMERA INSTALLS sudo pip3 install PiCamera


sudo pip3 install ipython pyzmq tornadosudo apt-get install qv4l2 v4l-utils



Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.