Skip to content

Instantly share code, notes, and snippets.

@wolfeidau
Last active June 25, 2019 10:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolfeidau/7ff98eebf7e774d64c6cf45e80abff31 to your computer and use it in GitHub Desktop.
Save wolfeidau/7ff98eebf7e774d64c6cf45e80abff31 to your computer and use it in GitHub Desktop.
Setup Gist
#!/bin/bash
set -e
# provide a folder like ~/temp to build the opencv sources
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <Build Folder>"
exit
fi
folder="$1"
echo "** Install requirement"
sudo apt-get update
sudo apt-get install -y build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev \
libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \
python2.7-dev python3.6-dev python-dev python-numpy python3-numpy \
libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev \
libv4l-dev v4l-utils qv4l2 v4l2ucp \
curl
echo "** Download opencv-4.0.0"
cd $folder
curl -L https://github.com/opencv/opencv/archive/4.0.0.zip -o opencv-4.0.0.zip
curl -L https://github.com/opencv/opencv_contrib/archive/4.0.0.zip -o opencv_contrib-4.0.0.zip
unzip opencv-4.0.0.zip
unzip opencv_contrib-4.0.0.zip
cd opencv-4.0.0/
echo "** Building..."
mkdir release
cd release/
cmake -D WITH_CUDA=ON -D CUDA_ARCH_BIN="5.3" -D CUDA_ARCH_PTX="" -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.0.0/modules -D WITH_GSTREAMER=ON -D WITH_LIBV4L=ON -D BUILD_opencv_python2=ON -D BUILD_opencv_python3=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j3
sudo make install
diff --git a/donkeycar/parts/camera.py b/donkeycar/parts/camera.py
index e78bd12..8b56dc7 100644
--- a/donkeycar/parts/camera.py
+++ b/donkeycar/parts/camera.py
@@ -11,7 +11,7 @@ class BaseCamera:
return self.frame
class CSICamera(BaseCamera):
- def gstreamer_pipeline(self,capture_width=120, capture_height=160, display_width=120, display_height=160, framerate=20, flip_method=0) :
+ def gstreamer_pipeline(self,capture_width=120, capture_height=160, display_width=120, display_height=160, framerate=20, flip_method=2) :
return ('nvarguscamerasrc ! '
'video/x-raw(memory:NVMM), '
'width=(int)%d, height=(int)%d, '
@@ -24,7 +24,7 @@ class CSICamera(BaseCamera):
def __init__(self, resolution=(120, 160), framerate=60):
import cv2
# initialize the camera and stream
- self.camera = cv2.VideoCapture(self.gstreamer_pipeline(display_width=resolution[1],display_height=resolution[0],flip_method=0), cv2.CAP_GSTREAMER)
+ self.camera = cv2.VideoCapture(self.gstreamer_pipeline(display_width=resolution[1],display_height=resolution[0],flip_method=2), cv2.CAP_GSTREAMER)
self.ret , self.image = self.camera.read()
# initialize the frame and the variable used to indicate
# if the thread should be stopped
diff --git a/donkeycar/parts/keras.py b/donkeycar/parts/keras.py
index 1d2f6f3..0fdcb36 100644
--- a/donkeycar/parts/keras.py
+++ b/donkeycar/parts/keras.py
@@ -55,7 +55,7 @@ class KerasPilot:
verbose=1,
validation_data=val_gen,
callbacks=callbacks_list,
- validation_steps=int(steps * (1.0 - train_split) / train_split)
+ validation_steps=int(steps * (1.0 - train_split) / train_split))
return hist

Getting Started

To write the image to an SD card using trusty old dd.

sudo dd if=~/Downloads/jetson-nano-sd-r32.1-2019-03-18.img of=/dev/sda bs=1M status=progress

Turn off the UI once you have gone through the setup process.

sudo systemctl set-default multi-user.target

You may want to change to the local ubuntu-ports mirror on internode.

http://mirror.internode.on.net/pub/ubuntu-ports/

Add a SWAP file

Just follow this How To Add Swap Space on Ubuntu 18.04

Reboot now.

sudo reboot

Check you still have swap.

swapon

Should output as follows:

NAME      TYPE  SIZE USED PRIO
/swapfile file 1024M 425M   -1

Install donkeycar

Install apt dependencies.

sudo apt-get install python3-pip libhdf5-serial-dev hdf5-tools
sudo apt-get install virtualenv build-essential python3-dev gfortran libhdf5-dev

Update your users groups to enable access to i2c devices and reboot.

sudo usermod -a -G i2c markw
sudo reboot

Setup virtualenv and activate it.

virtualenv donkeycar -p python3
source ~/donkeycar/bin/activate

Install tensorflow.

pip install --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v42 tensorflow-gpu==1.13.1+nv19.3

Install adafruit PCA9685 library.

pip install Adafruit_PCA9685

Test i2c devices are present.

i2cdetect -y -r 1

Output should look as follows:

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: 40 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: 70 -- -- -- -- -- -- --

Download and install donkeycar.

cd ~/donkeycar/
git clone https://github.com/feicccccccc/donkeycar.git
cd donkeycar
pip -e install .

Note: This will take a while so get a coffee.

Building OpenCV

Building opencv from sources.

mkdir ~/temp
./build_opencv4.sh ~/temp

Link cv2 you just built into your virtual environment.

cd ~/donkeycar/lib/python3.6/site-packages
ln -s /usr/local/python/cv2/python-3.6/cv2.cpython-36m-aarch64-linux-gnu.so

Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment