Skip to content

Commit

Permalink
Add Ubunut RPI Scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jmachuca77 committed Mar 16, 2020
1 parent e6e2039 commit d828698
Show file tree
Hide file tree
Showing 33 changed files with 1,157 additions and 2 deletions.
69 changes: 69 additions & 0 deletions Common/Ubuntu/create_swap_file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash
# Copyright 2017-2019 JetsonHacks
# MIT License
# Create a swap file and set up permissions
# If a parameter is passed, it should be the place to create the swapfile
set -e
SWAPDIRECTORY="/mnt"
# Ubuntu recommends 6GB for 4GB of memory when using suspend
# You can use 1 or 2 if need be
SWAPSIZE=6
AUTOMOUNT="Y"
function usage
{
echo "usage: installSwapFile [[[-d directory ] [-s size] -a] | [-h]]"
echo " -d | --dir <directoryname> Directory to place swapfile ( default: /mnt)"
echo " -s | --size <gigabytes> (default: 6)"
echo " -a | --auto Enable swap on boot in /etc/fstab (default: Y)"
echo " -h | --help This message"
}

while [ "$1" != "" ]; do
case $1 in
-d | --dir ) shift
SWAPDIRECTORY=$1
;;
-s | --size ) shift
SWAPSIZE=$1
;;
-a | --auto ) shift
AUTOMOUNT=$1
;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
esac
shift
done

echo "Creating Swapfile at: " $SWAPDIRECTORY
echo "Swapfile Size: " $SWAPSIZE"G"
echo "Automount: " $AUTOMOUNT

#Create a swapfile for Ubuntu at the current directory location
sudo fallocate -l $SWAPSIZE"G" $SWAPDIRECTORY"/swapfile"
cd $SWAPDIRECTORY
#List out the file
ls -lh swapfile
# Change permissions so that only root can use it
sudo chmod 600 swapfile
#List out the file
ls -lh swapfile
#Set up the Linux swap area
sudo mkswap swapfile
#Now start using the swapfile
sudo swapon swapfile
#Show that it's now being used
swapon -s

if [ "$AUTOMOUNT" = "Y" ]; then
echo "Modifying /etc/fstab to enable on boot"
SWAPLOCATION=$SWAPDIRECTORY"/swapfile"
echo $SWAPLOCATION
sudo sh -c 'echo "'$SWAPLOCATION' swap swap defaults 0 0" >> /etc/fstab'
fi

echo "Swap file has been created"
echo "Reboot to make sure changes are in effect"
4 changes: 2 additions & 2 deletions Common/Ubuntu/install_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ apt-get dist-upgrade -y
apt-get -y install python-dev python-numpy python3-numpy python-pip python-opencv

# pymavlink deps:
apt-get install -y libxml2-dev libxslt1.1 libxslt1-dev libz-dev
time pip install future lxml
apt-get install -y libxml2-dev libxslt1.1 libxslt1-dev libz-dev python-lxml
time pip install future

# install dronekit
pip install dronekit dronekit-sitl # also installs pymavlink
Expand Down
146 changes: 146 additions & 0 deletions Common/Ubuntu/librealsense/buildLibrealsense.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#!/bin/bash
# Builds the Intel Realsense library librealsense on a Jetson Nano Development Kit
# Copyright (c) 2016-19 Jetsonhacks
# MIT License

# Jetson Nano; L4T 32.2.3

LIBREALSENSE_DIRECTORY=${HOME}/GitHub/librealsense
LIBREALSENSE_VERSION=v2.33.1
INSTALL_DIR=$PWD
NVCC_PATH=/usr/local/cuda-10.0/bin/nvcc

USE_CUDA=false
s
function usage
{
echo "usage: ./buildLibrealsense.sh [[-c ] | [-h]]"
echo "-nc | --build_with_cuda Build no CUDA (Defaults to with CUDA)"
echo "-h | --help This message"
}

# Iterate through command line inputs
while [ "$1" != "" ]; do
case $1 in
-nc | --build_no_cuda ) USE_CUDA=false
;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
esac
shift
done

echo "Build with CUDA: "$USE_CUDA

red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
# e.g. echo "${red}The red tail hawk ${green}loves the green grass${reset}"


echo ""
echo "Please make sure that no RealSense cameras are currently attached"
echo ""
read -n 1 -s -r -p "Press any key to continue"
echo ""

if [ ! -d "$LIBREALSENSE_DIRECTORY" ] ; then
# clone librealsense
cd ${HOME}
echo "${green}Cloning librealsense${reset}"
git clone https://github.com/IntelRealSense/librealsense.git
fi

# Is the version of librealsense current enough?
cd $LIBREALSENSE_DIRECTORY
VERSION_TAG=$(git tag -l $LIBREALSENSE_VERSION)
if [ ! $VERSION_TAG ] ; then
echo ""
tput setaf 1
echo "==== librealsense Version Mismatch! ============="
tput sgr0
echo ""
echo "The installed version of librealsense is not current enough for these scripts."
echo "This script needs librealsense tag version: "$LIBREALSENSE_VERSION "but it is not available."
echo "Please upgrade librealsense or remove the librealsense folder before attempting to install again."
echo ""
exit 1
fi

# Checkout version the last tested version of librealsense
git checkout $LIBREALSENSE_VERSION

# Install the dependencies
cd $INSTALL_DIR
sudo ./scripts/installDependencies.sh

cd $LIBREALSENSE_DIRECTORY
git checkout $LIBREALSENSE_VERSION

# Now compile librealsense and install
mkdir build
cd build
# Build examples, including graphical ones
echo "${green}Configuring Make system${reset}"
# Build with CUDA (default), the CUDA flag is USE_CUDA, ie -DUSE_CUDA=true
export CUDACXX=$NVCC_PATH
export PATH=${PATH}:/usr/local/cuda/bin
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/cuda/lib64

/usr/bin/cmake ../ -DBUILD_EXAMPLES=true -DFORCE_LIBUVC=true -DBUILD_WITH_CUDA="$USE_CUDA" -DCMAKE_BUILD_TYPE=release -DBUILD_PYTHON_BINDINGS=bool:true -DBUILD_WITH_TM2=ON

# The library will be installed in /usr/local/lib, header files in /usr/local/include
# The demos, tutorials and tests will located in /usr/local/bin.
echo "${green}Building librealsense, headers, tools and demos${reset}"

NUM_CPU=$(nproc)
time make -j$(($NUM_CPU - 1))
if [ $? -eq 0 ] ; then
echo "librealsense make successful"
else
# Try to make again; Sometimes there are issues with the build
# because of lack of resources or concurrency issues
echo "librealsense did not build " >&2
echo "Retrying ... "
# Single thread this time
time make
if [ $? -eq 0 ] ; then
echo "librealsense make successful"
else
# Try to make again
echo "librealsense did not successfully build" >&2
echo "Please fix issues and retry build"
exit 1
fi
fi
echo "${green}Installing librealsense, headers, tools and demos${reset}"
sudo make install

if grep -Fxq 'export PYTHONPATH=$PYTHONPATH:/usr/local/lib' ~/.bashrc ; then
echo "PYTHONPATH already exists in .bashrc file"
else
echo 'export PYTHONPATH=$PYTHONPATH:/usr/local/lib' >> ~/.bashrc
echo "PYTHONPATH added to ~/.bashrc. Pyhon wrapper is now available for importing pyrealsense2"
fi

cd $LIBREALSENSE_DIRECTORY
echo "${green}Applying udev rules${reset}"
# Copy over the udev rules so that camera can be run from user space
sudo cp config/99-realsense-libusb.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules && udevadm trigger

echo "${green}Library Installed${reset}"
echo " "
echo " -----------------------------------------"
echo "The library is installed in /usr/local/lib"
echo "The header files are in /usr/local/include"
echo "The demos and tools are located in /usr/local/bin"
echo " "
echo " -----------------------------------------"
echo " "



33 changes: 33 additions & 0 deletions Common/Ubuntu/librealsense/install_vision_to_mavros.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

set -e
set -x

tput setaf 3
echo "Build latest version of librealsense"
tput sgr0

time ./buildLibrealsense.sh

pushd /home/$NORMAL_USER/GitHub
sudo apt install python3-lxml
sudo -H pip3 install cython
sudo -H pip3 install numpy --upgrade
sudo -H pip3 install transformations
sudo -H pip3 install apscheduler
sudo -H pip3 install dronekit

git clone https://github.com/thien94/vision_to_mavros.git

mkdir /home/$NORMAL_USER/start_t265_to_mavlink
pushd vision_to_mavros/scripts
cp t265_to_mavlink.py /home/$NORMAL_USER/start_t265_to_mavlink
popd
popd
cp start_t265.sh /home/$NORMAL_USER/start_t265_to_mavlink
sudo cp t265.service /etc/systemd/system

tput setaf 2
echo "Finished installing vision_to_mavros"
tput sgr0

26 changes: 26 additions & 0 deletions Common/Ubuntu/librealsense/scripts/installDependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
# installDependencies.sh
# Install dependencies for the Intel Realsense library librealsense2 on a Jetson Nano Developer Kit
# Copyright (c) 2016-19 Jetsonhacks
# MIT License
red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
# e.g. echo "${red}red text ${green}green text${reset}"
echo "${green}Adding Universe repository and updating${reset}"
apt-add-repository universe
apt update
echo "${green}Adding dependencies, graphics libraries and tools${reset}"
apt install libssl-dev libusb-1.0-0-dev pkg-config -y
# This is for ccmake
apt install build-essential cmake cmake-curses-gui -y

# Graphics libraries - for SDK's OpenGL-enabled examples
apt install libgtk-3-dev libglfw3-dev libgl1-mesa-dev libglu1-mesa-dev -y

# QtCreator for development; not required for librealsense core library
apt install qtcreator -y

# Add Python 3 support
apt install -y python3 python3-dev

6 changes: 6 additions & 0 deletions Common/Ubuntu/librealsense/start_t265.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
# This is /usr/bin/your_config-start.sh
# # do all your commands here... script terminates when all is done.

# Change the path to t265_to_mavlink.py
/home/apsync/start_t265_to_mavlink/t265_to_mavlink.py --connect udp:127.0.0.1:14560
17 changes: 17 additions & 0 deletions Common/Ubuntu/librealsense/t265.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Unit]
Description=Realsense T265 Service
After==multi-user.target
StartLimitIntervalSec=0
Conflicts=

[Service]
User=apsync
EnvironmentFile=
ExecStartPre=
ExecStart=/home/apsync/start_t265_to_mavlink/start_t265.sh

Restart=on-failure
RestartSec=1

[Install]
WantedBy=multi-user.target
Loading

0 comments on commit d828698

Please sign in to comment.