Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save rakosi2/a22a915aefb4c9781deb30bdfb13eb32 to your computer and use it in GitHub Desktop.

Select an option

Save rakosi2/a22a915aefb4c9781deb30bdfb13eb32 to your computer and use it in GitHub Desktop.
!/bin/bash
##########
##
## VMX Robotics Toolkit (VMX-rtk) Build Script
##
## Initial Release (1/4/2017)
##
## NOTE: Before running this script, verify that the swap space on the Raspberry Pi
## has been increased (see comments within this script). This is necessary if building
## from Raspian Stretch Desktop and when a value greater than "make -j1" is used.
##
## The recommended swap space size is 2048MB.
##
## And finally: a reminder that swapping to SD card is not recommended. The purpose
## of increasing swap space is to ensure the system continues to run (although slowly)
## when physical memory is temporarily exhausted.
##########
###
# Increase Raspberry Pi SWAP Size (TODO: Currently Manual - automate this)
###
# Increase Swap size, to stop the system from hanging on multi-core builds
# 1) Edit /etc/dphys-swapfile to change this line to:
# CONF_SWAPSIZE=2048
#
# 2) Restart the swapfile service:
# sudo /etc/init.d/dphys-swapfile stop
# sudo /etc/init.d/dphys-swapfile start
# Echo commands to console
set -x
# Abort the script if any commands fail
set -e
##
# Download and place VMX-RTK Desktop Icons
##
cd ~
mkdir -p vmx-rtk/images
pushd vmx-rtk/images
# The following wget options ensure that only the files in the target directory will be download
wget -e robots=off -nH -nd -np -l1 --recursive --no-parent --reject="index.html*" http://www.kauailabs.com/public_files/vmx-rtk/images/
popd
#Download and place Desktop shortcuts
pushd Desktop
# The following wget options ensure that only the files in the target directory will be download
wget -e robots=off -nH -nd -np -l1 --recursive --no-parent --reject="index.html*" http://www.kauailabs.com/public_files/vmx-rtk/desktop/
popd
##
# Ensure that Raspbian is all up-to-date with ROS Dependencies
##
sudo apt-get -y update
sudo apt-get -y --allow-unauthenticated upgrade
cd ~
###
# Raspberry Pi System Configuration
###
# Enable SPI Interface (required for VMX-pi)
sudo raspi-config nonint do_spi 0
# Enable I2C Interface (typically required for VMX-pi)
sudo raspi-config nonint do_i2c 0
echo "dtparam=i2s=on" | sudo tee --append /boot/config.txt
# Enable Serial Interface
sudo raspi-config nonint do_serial 0
# Disable serial console (so as not to conflict with serial interface)
sudo sed -i -e "s/console=serial0,115200//g" /boot/cmdline.txt
sudo sed -i -e "s/console=tty1//g" /boot/cmdline.txt
##
# Raspi-Config loacalization settings
##
# Set Timezone
sudo rm /etc/timezone
echo "Pacific/Honolulu" | sudo tee --append /etc/timezone
# Set WIFI country
sudo raspi-config nonint do_wifi_country US
# Configure Keyboard
sudo rm /etc/default/keyboard
echo "# KEYBOARD CONFIGURATION FILE
# Consult the keyboard(5) manual page.
XKBMODEL="pc105"
XKBLAYOUT="us"
XKBVARIANT="us"
XKBOPTIONS=""
BACKSPACE="guess"" | sudo tee --append /etc/default/keyboard
##
# Replace syslog with busybox, avoiding writes to the hard disk for system logs
# (this is needed when configuring VMX Robotics Toolkit in 'headless' mode)
##
sudo apt-get install busybox-syslogd; sudo dpkg --purge rsyslog
##
# Replace openjdk with oracle java8 sdk - this avoids some issues with opencv
##
sudo apt-get -y purge openjdk*
sudo apt -y autoremove
sudo apt-get -y install oracle-java8-jdk*
export JAVA_HOME=/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt
##
# Miscellaneous distribution installs
##
sudo apt-get -y install eclipse eclipse-jdt eclipse-cdt
sudo apt-get -y install git
sudo apt-get -y install git-gui
sudo apt-get -y install ftp
sudo apt-get -y install libboost1.62-all
sudo apt-get -y install ntp
sudo apt-get -y install xgalaga
sudo apt-get -y install tcl-dev
sudo apt-get -y install mono-runtime
sudo apt-get -y install libpcre3 libpcre3-dev
sudo apt-get -y install cmake
sudo apt-get -y install mono-devel
sudo apt-get -y install gradle
##
# Add KauaiLabs gpg key, add KauaiLabs apt site, and install VMX-pi HAL
#
# (This can be updated later via: sudo apt-get install --only-upgrade vmxpi-hal)
##
sudo apt-get -y install dirmngr
sudo apt-key adv --recv-key --keyserver pgp.mit.edu "74BBDA3E"
echo "deb http://www.kauailabs.com/apt ./" | sudo tee --append /etc/apt/sources.list
sudo apt-get update
sudo apt-get -y install vmxpi-hal
##
# Build/Install SWIG
##
cd ~
wget http://prdownloads.sourceforge.net/swig/swig-3.0.12.tar.gz
tar xzf swig-3.0.12.tar.gz
cd swig-3.0.12
./configure
make
sudo make install
cd ~
rm swig-3.0.12.tar.gz
##
# Enable VMX-RTK Splashscreen
##
# Clean unnecessary text from boot, to help ensure an aesthetically-pleasing splashscreen
# NOTE: All the text in this file must be on a single line
bash -c "printf ' consoleblank=0 loglevel=1 quiet' >> /boot/cmdline.txt"
# Download, rename, and move splashscreen image
wget http://www.kauailabs.com/public_files/vmx-rtk/VMXrtk_Splashscreen.png
sudo mv VMXrtk_Splashscreen.png /opt/splash.png
# Replace default Raspbian Spashscreen file w/VMX-RTK image
sudo mv /usr/share/plymouth/themes/pix/splash.png /usr/share/plymouth/themes/pix/splash_orig.png
sudo cp /opt/splash.png /usr/share/plymouth/themes/pix/splash.png
##
# Custom FFMPEG Build. This step is necessary in order to work around a conflict
# that occurs when using OpenCV from Java. The issue is that the default build
# of FFMPEG (installed typically via apt) for Raspbian Stretch [v.3.2.9 as of this
# writing] is built to be dependent upon libopenmpt - which causes an exception
# when loaded from Java.
#
# Therefore, this custom build disables the references to libopenmpt.
##
# To help keep things clean, uninstall any existing ffmpeg
sudo apt-get remove ffmpeg
# Checkout FFMPEG
cd ~
wget https://github.com/FFmpeg/FFmpeg/archive/n3.2.9.zip
unzip n3.2.9.zip
cd FFmpeg-n3.2.9
# Configure build to build .so files, and to NOT include the build of libopenmpt
./configure --disable-libopenmpt --enable-shared
# Build & Install
make -j1
sudo make install
##
# OpenCV - build from source, with a special set of options for performance
##
sudo apt-get -y install build-essential
sudo apt-get -y install python-dev python-numpy
sudo apt-get -y install python-scipy python-matplotlib libgtk2.0-dev
cd ~
sudo wget https://github.com/opencv/opencv/archive/3.3.1.zip
mv 3.3.1.zip opencv.zip
unzip opencv.zip
cd opencv-3.3.1/
mkdir build
cd build
# ENABLE_NEON and ENABLE_VFPV3 to optimize performance on Raspberry Pi platform
cmake -DENABLE_NEON=ON -DENABLE_VFPV3=ON -D CMAKE_BUILD_TYPE=RELEASE -D BUILD_PERF_TESTS=OFF -D BUILD_SHARED_LIBRARY=ON -D BUILD_TESTS=OFF -D BUILD_opencv_python2=ON -D BUILD_opencv_python3=ON -D JAVA_INCLUDE_PATH=/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/include/ -D JAVA_AWT_INCLUDE_PATH=/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/include/ -D JAVA_AWT_LIBRARY=/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/include/jawt.h -D JAVA_JVM_LIBRARY=/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/include/jni.h /home/pi/opencv-3.3.1
make -j1
sudo make install
cd ~
rm -f opencv.zip
#Cmake wpilib (Includes cscore, ntcore, and wpiutil)
# NOTE: wpilib build must occur ~after~ the opencv 3.3.1 build, since cscore is dependent upon opencv
#
# This builds the wpi library ntcore, cscore and wpiutil components,
# builds them using cmake and installs the files to:
#
# /usr/local/wpilib
mkdir wpilib_cmake
pushd wpilib_cmake
git clone https://github.com/ThadHouse/CmakeWpilib.git .
# update all submodules
git submodule update --init --recursive
# change to the installbuild branch
git checkout installbuild
mkdir build
cd build
cmake ..
make -j1
sudo make install
popd
# Install Python ntcore, cscore (and dependencies)
# This uses the instructions at http://robotpy.readthedocs.io/en/stable/install/cscore.html
# (in the "Compile from Source" section)
#
# NOTE: This assumes opencv3.3.1 has been previously built/installed
#
pip3 install Numpy
pip3 install pybind11==2.0.1
pip3 install robotpy-cscore
##
# VisionBuildSamples (helpers for integrating GRIP-generated pipelines on Raspberry Pi)
##
mkdir VisionBuildSamples
cd VisionBuildSamples
git clone https://github.com/wpilibsuite/VisionBuildSamples.git
cd Java/src/main/java
cd ~
mkdir -p grip/pipeline/java
mkdir -p grip/pipeline/include
cd grip/pipeline/java
mkdir -p edu/wpi/first/wpilibj/vision
cd edu/wpi/first/wpilibj/vision
wget https://raw.githubusercontent.com/wpilibsuite/allwpilib/master/wpilibj/src/main/java/edu/wpi/first/wpilibj/vision/VisionPipeline.java
cd ~/grip/pipeline/include
wget https://raw.githubusercontent.com/wpilibsuite/allwpilib/master/wpilibc/src/main/native/include/vision/VisionPipeline.h
cd ~
##
# ROS (Kinetic) [NOTE that this build can take many hours to complete]
##
# Add ROS distro site to apt sources list
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu stretch main" > /etc/apt/sources.list.d/ros-latest.list'
# Import ROS GPG key
sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116
sudo apt-get update
# Acquire ROS Dependencies
sudo apt-get -y --allow-unauthenticated install python-rosdep python-rosinstall-generator python-wstool python-rosinstall build-essential cmake
# Construct Catkin Workspace & Build ROS
mkdir -p ~/ros_catkin_ws
cd ~/ros_catkin_ws
rosinstall_generator ros_comm --rosdistro kinetic --deps --wet-only --tar > kinetic-ros_comm-wet.rosinstall
wstool init src kinetic-ros_comm-wet.rosinstall
rosinstall_generator desktop --rosdistro kinetic --deps --wet-only --tar > kinetic-desktop-wet.rosinstall
cd src
wstool merge ../kinetic-desktop-wet.rosinstall
wstool update
cd ~/ros_catkin_ws
rosdep install -y --from-paths src --ignore-src --rosdistro kinetic -r --os=debian:stretch
sudo rosdep init
rosdep update
sudo apt-get install python-empy
# Modify src/modules/viz/CMakeLists.txt, to add this line at the end:
# set(ENABLE_PRECOMPILED_HEADERS OFF CACHE INTERNAL "" FORCE)
echo "set(ENABLE_PRECOMPILED_HEADERS OFF CACHE INTERNAL \"\" FORCE)" | tee --append src/opencv3/modules/viz/CMakeLists.txt
# Build
sudo ./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release --install-space /opt/ros/kinetic -j1
# Source ROS
source /opt/ros/kinetic/setup.bash
#edit .bashrc to ensure ROS is always sourced when a new console terminal is opened
echo "# Automatically source ROS" >> ~/.bashrc
echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
cd ~
#Remove temporary installation files
sudo apt-get -y autoremove
##
# JavaFX Embedded Port (Experimental)
##
#wget http://gluonhq.com/download/javafx-embedded-sdk/
echo "VMX-RTK Build Completed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment