Advertisement
silver2row

Building ArduCopter on Debian

Sep 29th, 2021
1,094
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 12.21 KB | None | 0 0
  1. # This is the build on the BBBlue...
  2.  
  3. sudo apt-get install g++ make pkg-config python python-dev python-lxml python-pip
  4. sudo pip3 install future
  5. git clone https://github.com/ArduPilot/ardupilot
  6. cd ardupilot
  7. git branch -a
  8. git checkout Copter-4.1
  9. git submodule update --init --recursive
  10. sudo python3 waf configure --board=blue
  11. sudo python3 waf copter
  12.  
  13. # This is the build on the WSL2 Debian Distro...
  14.  
  15. /home/toasch/ARDU/Tools/environment_install/install-prereqs-ubuntu.sh
  16.  
  17. # Along w/ different scripts installed w/in the file as listed below
  18.  
  19. #!/bin/bash
  20. echo "---------- $0 start ----------"
  21. set -e
  22. set -x
  23.  
  24. if [ $EUID == 0 ]; then
  25.     echo "Please do not run this script as root; don't sudo it!"
  26.     exit 1
  27. fi
  28.  
  29. OPT="/opt"
  30. # Ardupilot Tools
  31. ARDUPILOT_TOOLS="Tools/autotest"
  32.  
  33. ASSUME_YES=false
  34. QUIET=false
  35. sep="##############################################"
  36.  
  37. OPTIND=1  # Reset in case getopts has been used previously in the shell.
  38. while getopts "yq" opt; do
  39.     case "$opt" in
  40.         \?)
  41.             exit 1
  42.             ;;
  43.         y)  ASSUME_YES=true
  44.             ;;
  45.         q)  QUIET=true
  46.             ;;
  47.     esac
  48. done
  49.  
  50. APT_GET="sudo apt"
  51. if $ASSUME_YES; then
  52.     APT_GET="$APT_GET --assume-yes"
  53. fi
  54. if $QUIET; then
  55.     APT_GET="$APT_GET -qq"
  56. fi
  57.  
  58. # update apt package list
  59. $APT_GET update
  60.  
  61. function package_is_installed() {
  62.     dpkg-query -W -f='${Status}' "$1" 2>/dev/null | grep -c "ok installed"
  63. }
  64.  
  65. function heading() {
  66.     echo "$sep"
  67.     echo $*
  68.     echo "$sep"
  69. }
  70.  
  71. # Install lsb-release as it is needed to check Ubuntu version
  72. if ! package_is_installed "lsb-release"; then
  73.     heading "Installing lsb-release"
  74.     $APT_GET install lsb-release
  75.     echo "Done!"
  76. fi
  77.  
  78. # Checking Ubuntu release to adapt software version to install
  79. RELEASE_CODENAME=$(lsb_release -c -s)
  80. PYTHON_V="python3"  # starting from ubuntu 20.04, python isn't symlink to default python interpreter
  81. PIP=sudo pip3
  82.  
  83. if [ ${RELEASE_CODENAME} == 'xenial' ]; then
  84.     SITLFML_VERSION="2.3v5"
  85.     SITLCFML_VERSION="2.3"
  86. elif [ ${RELEASE_CODENAME} == 'disco' ]; then
  87.     SITLFML_VERSION="2.5"
  88.     SITLCFML_VERSION="2.5"
  89. elif [ ${RELEASE_CODENAME} == 'eoan' ]; then
  90.     SITLFML_VERSION="2.5"
  91.     SITLCFML_VERSION="2.5"
  92. elif [ ${RELEASE_CODENAME} == 'focal' ] || [ ${RELEASE_CODENAME} == 'ulyssa' ]; then
  93.     SITLFML_VERSION="2.5"
  94.     SITLCFML_VERSION="2.5"
  95.     PYTHON_V="python3"
  96.     PIP=pip3
  97. elif [ ${RELEASE_CODENAME} == 'bullseye' ] || [ ${RELEASE_CODENAME} == 'hirsute' ]; then
  98.     SITLFML_VERSION="2.5"
  99.     SITLCFML_VERSION="2.5"
  100.     PYTHON_V="python3"
  101.     PIP=pip3
  102. elif [ ${RELEASE_CODENAME} == 'trusty' ]; then
  103.     SITLFML_VERSION="2"
  104.     SITLCFML_VERSION="2"
  105. else
  106.     # We assume APT based system, so let's try with apt-cache first.
  107.     SITLCFML_VERSION=$(apt-cache search -n '^libcsfml-audio' | cut -d" " -f1 | head -1 | grep -Eo '[+-]?[0-9]+([.][0-9]+)?')
  108.     SITLFML_VERSION=$(apt-cache search -n '^libsfml-audio' | cut -d" " -f1 | head -1 | grep -Eo '[+-]?[0-9]+([.][0-9]+)?')
  109.     # If we cannot retrieve the number with apt-cache, try a last time with dpkg-query
  110.     re='^[+-]?[0-9]+([.][0-9]+)?$'
  111.     if ! [[ $SITLCFML_VERSION =~ $re ]] || ! [[ $SITLFML_VERSION =~ $re ]] ; then
  112.         # Extract the floating point number that is the version of the libcsfml package.
  113.         SITLCFML_VERSION=$(dpkg-query --search libcsfml-audio | cut -d":" -f1 | grep libcsfml-audio | head -1 | grep -Eo '[+-]?[0-9]+([.][0-9]+)?')
  114.         # And same for libsfml-audio.
  115.         SITLFML_VERSION=$(dpkg-query --search libsfml-audio | cut -d":" -f1 | grep libsfml-audio | head -1 | grep -Eo '[+-]?[0-9]+([.][0-9]+)?')
  116.     fi
  117. fi
  118.  
  119. # Check whether the specific ARM pkg-config package is available or whether we should emulate the effect of installing it.
  120. # Check if we need to manually install libtool-bin
  121. ARM_PKG_CONFIG_NOT_PRESENT=0
  122. if [ -z "$(apt-cache search -n '^pkg-config-arm-linux-gnueabihf')" ]; then
  123.     ARM_PKG_CONFIG_NOT_PRESENT=$(dpkg-query --search pkg-config-arm-linux-gnueabihf |& grep -c "dpkg-query:")
  124. fi
  125. if [ "$ARM_PKG_CONFIG_NOT_PRESENT" -eq 1 ]; then
  126.     INSTALL_PKG_CONFIG=""
  127.     # No need to install Ubuntu's pkg-config-arm-linux-gnueabihf, instead install the base pkg-config.
  128.     sudo apt install pkg-config
  129.     if [ -f /usr/share/pkg-config-crosswrapper ]; then
  130.         # We are on non-Ubuntu so simulate effect of installing pkg-config-arm-linux-gnueabihf.
  131.         sudo ln -s /usr/share/pkg-config-crosswrapper /usr/bin/arm-linux-gnueabihf-pkg-config
  132.     #else
  133.         #echo "Warning: unable to link to pkg-config-crosswrapper"
  134.     fi
  135. else
  136.     # Package is available so install it later.
  137.     INSTALL_PKG_CONFIG="pkg-config-arm-linux-gnueabihf"
  138. fi
  139.  
  140. # Lists of packages to install
  141. BASE_PKGS="build-essential ccache g++ gawk git make wget"
  142. PYTHON_PKGS="future lxml pymavlink MAVProxy pexpect flake8 geocoder"
  143. # add some Python packages required for commonly-used MAVProxy modules and hex file generation:
  144. if [[ $SKIP_AP_EXT_ENV -ne 1 ]]; then
  145.   PYTHON_PKGS="$PYTHON_PKGS pygame intelhex"
  146. fi
  147. ARM_LINUX_PKGS="g++-arm-linux-gnueabihf $INSTALL_PKG_CONFIG"
  148. # python-wxgtk packages are added to SITL_PKGS below
  149. SITL_PKGS="libtool libxml2-dev libxslt1-dev ${PYTHON_V}-dev ${PYTHON_V}-pip ${PYTHON_V}-setuptools ${PYTHON_V}-numpy ${PYTHON_V}-pyparsing ${PYTHON_V}-psutil"
  150. # add some packages required for commonly-used MAVProxy modules:
  151. if [[ $SKIP_AP_GRAPHIC_ENV -ne 1 ]]; then
  152.   SITL_PKGS="$SITL_PKGS xterm ${PYTHON_V}-matplotlib ${PYTHON_V}-serial ${PYTHON_V}-scipy ${PYTHON_V}-opencv libcsfml-dev libcsfml-audio${SITLCFML_VERSION} libcsfml-dev libcsfml-graphics${SITLCFML_VERSION} libcsfml-network${SITLCFML_VERSION} libcsfml-system${SITLCFML_VERSION} libcsfml-window${SITLCFML_VERSION} libsfml-audio${SITLFML_VERSION} libsfml-dev libsfml-graphics${SITLFML_VERSION} libsfml-network${SITLFML_VERSION} libsfml-system${SITLFML_VERSION} libsfml-window${SITLFML_VERSION} ${PYTHON_V}-yaml"
  153. fi
  154. if [[ $SKIP_AP_COV_ENV -ne 1 ]]; then
  155.   # Coverage utilities
  156.   COVERAGE_PKGS="lcov gcovr"
  157. fi
  158.  
  159. # ArduPilot official Toolchain for STM32 boards
  160. function install_arm_none_eabi_toolchain() {
  161.   # GNU Tools for ARM Embedded Processors
  162.   # (see https://launchpad.net/gcc-arm-embedded/)
  163.   ARM_ROOT="gcc-arm-none-eabi-6-2017-q2-update"
  164.   ARM_TARBALL="$ARM_ROOT-linux.tar.bz2"
  165.   ARM_TARBALL_URL="https://firmware.ardupilot.org/Tools/STM32-tools/$ARM_TARBALL"
  166.   if [ ! -d $OPT/$ARM_ROOT ]; then
  167.     (
  168.         cd $OPT;
  169.         heading "Installing toolchain for STM32 Boards"
  170.         echo "Downloading from ArduPilot server"
  171.         sudo wget $ARM_TARBALL_URL
  172.         echo "Installing..."
  173.         sudo tar xjf ${ARM_TARBALL}
  174.         echo "... Cleaning"
  175.         sudo rm ${ARM_TARBALL};
  176.     )
  177.   fi
  178.   echo "Registering STM32 Toolchain for ccache"
  179.   sudo ln -s -f $CCACHE_PATH /usr/lib/ccache/arm-none-eabi-g++
  180.   sudo ln -s -f $CCACHE_PATH /usr/lib/ccache/arm-none-eabi-gcc
  181.   echo "Done!"
  182. }
  183.  
  184. function maybe_prompt_user() {
  185.     if $ASSUME_YES; then
  186.         return 0
  187.     else
  188.         read -p "$1"
  189.         if [[ $REPLY =~ ^[Yy]$ ]]; then
  190.             return 0
  191.         else
  192.             return 1
  193.         fi
  194.     fi
  195. }
  196.  
  197. heading "Add user to dialout group to allow managing serial ports"
  198. sudo usermod -a -G dialout $USER
  199. echo "Done!"
  200.  
  201. # Add back python symlink to python interpreter on Ubuntu >= 20.04
  202. if [ ${RELEASE_CODENAME} == 'focal' ] || [ ${RELEASE_CODENAME} == 'ulyssa' ]; then
  203.     BASE_PKGS+=" python-is-python3"
  204.     SITL_PKGS+=" libpython3-stdlib" # for argparse
  205. elif [ ${RELEASE_CODENAME} == 'bullseye' ] || [ ${RELEASE_CODENAME} == 'hirsute' ]; then
  206.     BASE_PKGS+=" python-is-python3"
  207.     SITL_PKGS+=" libpython3-stdlib" # for argparse
  208. else
  209.   SITL_PKGS+=" python-argparse"
  210. fi
  211.  
  212. # Check for graphical package for MAVProxy
  213. if [[ $SKIP_AP_GRAPHIC_ENV -ne 1 ]]; then
  214.   if [ ${RELEASE_CODENAME} == 'bullseye' ] || [ ${RELEASE_CODENAME} == 'hirsute' ]; then
  215.     SITL_PKGS+=" python3-wxgtk4.0"
  216.     SITL_PKGS+=" fonts-freefont-ttf libfreetype6-dev libjpeg62-turbo-dev libpng16-16 libportmidi-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev"  # for pygame
  217.   elif [ ${RELEASE_CODENAME} == 'focal' ] || [ ${RELEASE_CODENAME} == 'ulyssa' ]; then
  218.     SITL_PKGS+=" python3-wxgtk4.0"
  219.     SITL_PKGS+=" fonts-freefont-ttf libfreetype6-dev libjpeg8-dev libpng16-16 libportmidi-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev"  # for pygame
  220.   elif apt-cache search python-wxgtk3.0 | grep wx; then
  221.       SITL_PKGS+=" python-wxgtk3.0"
  222.   else
  223.       # we only support back to trusty:
  224.       SITL_PKGS+=" python-wxgtk2.8"
  225.       SITL_PKGS+=" fonts-freefont-ttf libfreetype6-dev libjpeg8-dev libpng12-0 libportmidi-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsdl1.2-dev"  # for pygame
  226.   fi
  227. fi
  228.  
  229. # Check if we need to manually install realpath
  230. RP=$(apt-cache search -n '^realpath$')
  231. if [ -n "$RP" ]; then
  232.     BASE_PKGS+=" realpath"
  233. fi
  234.  
  235. # Check if we need to manually install libtool-bin
  236. LBTBIN=$(apt-cache search -n '^libtool-bin')
  237. if [ -n "$LBTBIN" ]; then
  238.     SITL_PKGS+=" libtool-bin"
  239. fi
  240.  
  241. # Install all packages
  242. $APT_GET install $BASE_PKGS $SITL_PKGS $PX4_PKGS $ARM_LINUX_PKGS $COVERAGE_PKGS
  243. $PIP install --user -U $PYTHON_PKGS
  244.  
  245. if [[ -z "${DO_AP_STM_ENV}" ]] && maybe_prompt_user "Install ArduPilot STM32 toolchain [N/y]?" ; then
  246.     DO_AP_STM_ENV=1
  247. fi
  248.  
  249. heading "Removing modemmanager package that could conflict with firmware uploading"
  250. if package_is_installed "modemmanager"; then
  251.     $APT_GET remove modemmanager
  252. fi
  253. echo "Done!"
  254.  
  255. CCACHE_PATH=$(which ccache)
  256. if [[ $DO_AP_STM_ENV -eq 1 ]]; then
  257.   install_arm_none_eabi_toolchain
  258. fi
  259.  
  260. heading "Check if we are inside docker environment..."
  261. IS_DOCKER=false
  262. if [[ -f /.dockerenv ]] || grep -Eq '(lxc|docker)' /proc/1/cgroup ; then
  263.     IS_DOCKER=true
  264. fi
  265. echo "Done!"
  266.  
  267. SHELL_LOGIN=".profile"
  268. if $IS_DOCKER; then
  269.     echo "Inside docker, we add the tools path into .bashrc directly"
  270.     SHELL_LOGIN=".bashrc"
  271. fi
  272.  
  273. heading "Adding ArduPilot Tools to environment"
  274.  
  275. SCRIPT_DIR=$(dirname $(realpath ${BASH_SOURCE[0]}))
  276. ARDUPILOT_ROOT=$(realpath "$SCRIPT_DIR/../../")
  277. exportline="export PATH=$OPT/$ARM_ROOT/bin:\$PATH";
  278. grep -Fxq "$exportline" ~/$SHELL_LOGIN 2>/dev/null || {
  279.     if maybe_prompt_user "Add $OPT/$ARM_ROOT/bin to your PATH [N/y]?" ; then
  280.         echo $exportline >> ~/$SHELL_LOGIN
  281.         eval $exportline
  282.     else
  283.         echo "Skipping adding $OPT/$ARM_ROOT/bin to PATH."
  284.     fi
  285. }
  286.  
  287. exportline2="export PATH=$ARDUPILOT_ROOT/$ARDUPILOT_TOOLS:\$PATH";
  288. grep -Fxq "$exportline2" ~/$SHELL_LOGIN 2>/dev/null || {
  289.     if maybe_prompt_user "Add $ARDUPILOT_ROOT/$ARDUPILOT_TOOLS to your PATH [N/y]?" ; then
  290.         echo $exportline2 >> ~/$SHELL_LOGIN
  291.         eval $exportline2
  292.     else
  293.         echo "Skipping adding $ARDUPILOT_ROOT/$ARDUPILOT_TOOLS to PATH."
  294.     fi
  295. }
  296.  
  297. if [[ $SKIP_AP_COMPLETION_ENV -ne 1 ]]; then
  298. exportline3="source $ARDUPILOT_ROOT/Tools/completion/completion.bash";
  299. grep -Fxq "$exportline3" ~/$SHELL_LOGIN 2>/dev/null || {
  300.     if maybe_prompt_user "Add ArduPilot Bash Completion to your bash shell [N/y]?" ; then
  301.         echo $exportline3 >> ~/.bashrc
  302.         eval $exportline3
  303.     else
  304.         echo "Skipping adding ArduPilot Bash Completion."
  305.     fi
  306. }
  307. fi
  308.  
  309. exportline4="export PATH=/usr/lib/ccache:\$PATH";
  310. grep -Fxq "$exportline4" ~/$SHELL_LOGIN 2>/dev/null || {
  311.     if maybe_prompt_user "Append CCache to your PATH [N/y]?" ; then
  312.         echo $exportline4 >> ~/$SHELL_LOGIN
  313.         eval $exportline4
  314.     else
  315.         echo "Skipping appending CCache to PATH."
  316.     fi
  317. }
  318. echo "Done!"
  319.  
  320. if [[ $SKIP_AP_GIT_CHECK -ne 1 ]]; then
  321.   if [ -d ".git" ]; then
  322.     heading "Update git submodules"
  323.     cd $ARDUPILOT_ROOT
  324.     git submodule update --init --recursive
  325.     echo "Done!"
  326.   fi
  327. fi
  328. echo "---------- $0 end ----------"
  329.  
  330.  
  331.  
  332. ###### After this script ends and is done correctly, I perform these steps ######
  333.  
  334. # This is just like building on the BBBlue but only takes about 30 minutes, i.e. not 6 hours.
  335.  
  336. sudo apt-get install g++ make pkg-config python python-dev python-lxml python-pip
  337. sudo pip3 install future
  338. git clone https://github.com/ArduPilot/ardupilot
  339. cd ardupilot
  340. git branch -a
  341. git checkout Copter-4.1
  342. git submodule update --init --recursive
  343. sudo python3 waf configure --board=blue
  344. sudo python3 waf copter
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement