├── .gitignore ├── Documents ├── AirSim │ └── settings.json ├── launch.sh └── px4_sitl_airsim ├── run.sh ├── rpc_patch.patch ├── README.md ├── LICENSE └── Dockerfile /.gitignore: -------------------------------------------------------------------------------- 1 | NVIDIA-Linux-x86_64-375.39.run 2 | UnrealEngine-4.15.zip 3 | -------------------------------------------------------------------------------- /Documents/AirSim/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "FpvVehicleName": "Pixhawk", 3 | "LocalHostIp": "127.0.0.1", 4 | "RpcEnabled": true, 5 | "Pixhawk": { 6 | "SerialBaudRate": 115200, 7 | "SerialPort": "*", 8 | "UseSerial": false, 9 | "UdpIp": "127.0.0.1", 10 | "UdpPort": 14560, 11 | "SitlIp": "127.0.0.1", 12 | "SitlPort": 14556 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | xhost +local:root; \ 3 | docker run -it \ 4 | --env="DISPLAY" \ 5 | --env="QT_X11_NO_MITSHM=1" \ 6 | --device="/dev/nvidia0:/dev/nvidia0" \ 7 | --device="/dev/nvidiactl:/dev/nvidiactl" \ 8 | --device="/dev/nvidia-modeset:/dev/nvidia-modeset" \ 9 | --volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \ 10 | --volume="$PWD/Documents:/home/unreal/Documents" \ 11 | --cap-add sys_nice \ 12 | --net=host \ 13 | airsim_nvidia /home/unreal/Documents/launch.sh 14 | -------------------------------------------------------------------------------- /rpc_patch.patch: -------------------------------------------------------------------------------- 1 | diff --git a/lib/rpc/this_handler.cc b/lib/rpc/this_handler.cc 2 | index 2479310..f969a48 100644 3 | --- a/lib/rpc/this_handler.cc 4 | +++ b/lib/rpc/this_handler.cc 5 | @@ -1,5 +1,11 @@ 6 | #include "rpc/this_handler.h" 7 | 8 | +extern "C" int __cxa_thread_atexit(void (*func)(), void *obj, 9 | + void *dso_symbol) { 10 | + int __cxa_thread_atexit_impl(void (*)(), void *, void *); 11 | + return __cxa_thread_atexit_impl(func, obj, dso_symbol); 12 | +} 13 | + 14 | namespace rpc { 15 | 16 | this_handler_t &this_handler() { 17 | 18 | -------------------------------------------------------------------------------- /Documents/launch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd /home/unreal/AirSim/build_debug/output/bin 4 | tmux new-session -s airsim -n shell -d 5 | tmux new-window -t airsim:1 -n sitl -c /home/unreal/Firmware 6 | tmux new-window -t airsim:2 -n sim -c /home/unreal/out/LinuxNoEditor/Blocks/Binaries/Linux/ 7 | 8 | tmux send-keys -t airsim:1 "sudo ./build_posix_sitl_default/src/firmware/posix/px4 ~/Documents/px4_sitl_airsim" C-m 9 | sleep 1 10 | tmux send-keys -t airsim:2 "./Blocks-Linux-Shipping" C-m 11 | sleep 5 12 | tmux send-keys -t airsim:0 "LD_LIBRARY_PATH=../../../llvm-build/lib ./DroneShell" C-m 13 | 14 | tmux select-window -t airsim:0 15 | tmux attach-session -t airsim 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | airsim_nvidia_docker 2 | ==================== 3 | 4 | This setup is in no way ideal, and requires some hacky patches, but: 5 | 1. it works on my machine, and 6 | 2. its isolated 7 | 8 | Prerequisites: 9 | 10 | - docker (tested with 17.03.1-ce) 11 | - NVIDIA-Linux-x86_64-381.22.run (from NVIDIA, probably can be changed to match your nvidia driver version) 12 | - UnrealEngine-4.16.2-release.zip (Requires signup with Epic Games, downloaded from github) 13 | 14 | Build/Run: 15 | 16 | docker build -t airsim_nvidia . 17 | ./run.sh 18 | 19 | This starts up the container with a tmux session with three tabs: 20 | 21 | 0. PX4 software in the loop 22 | 1. AirSim 23 | 2. DroneShell, where you can query status and enter commands 24 | 25 | Issues: 26 | 27 | - Takes a very long time to build 28 | - Final container is pretty big (no excess stuff is removed) 29 | - Patches to both Unreal and AirSim 30 | - Could be more portable to NVIDIA drivers 31 | - Checks out AirSim & PX4 masters, which continuously change 32 | - PX4 and AirSim containers should be separate, but I couldn't get multi-container commmunication to work 33 | 34 | 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Kerry Snyder 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Documents/px4_sitl_airsim: -------------------------------------------------------------------------------- 1 | # modified from posix-configs/SITL/init/ekf2/iris 2 | uorb start 3 | param load 4 | dataman start 5 | param set BAT_N_CELLS 3 6 | param set CAL_ACC0_ID 1376264 7 | param set CAL_ACC0_XOFF 0.01 8 | param set CAL_ACC0_XSCALE 1.01 9 | param set CAL_ACC0_YOFF -0.01 10 | param set CAL_ACC0_YSCALE 1.01 11 | param set CAL_ACC0_ZOFF 0.01 12 | param set CAL_ACC0_ZSCALE 1.01 13 | param set CAL_ACC1_ID 1310728 14 | param set CAL_ACC1_XOFF 0.01 15 | param set CAL_GYRO0_ID 2293768 16 | param set CAL_GYRO0_XOFF 0.01 17 | param set CAL_MAG0_ID 196616 18 | param set CAL_MAG0_XOFF 0.01 19 | param set COM_DISARM_LAND 3 20 | param set COM_OBL_ACT 2 21 | param set COM_OBL_RC_ACT 0 22 | param set COM_OF_LOSS_T 5 23 | param set COM_RC_IN_MODE 1 24 | param set EKF2_AID_MASK 1 25 | param set EKF2_ANGERR_INIT 0.01 26 | param set EKF2_GBIAS_INIT 0.01 27 | param set EKF2_HGT_MODE 0 28 | param set EKF2_MAG_TYPE 1 29 | param set MAV_TYPE 2 30 | param set MC_PITCH_P 6 31 | param set MC_PITCHRATE_P 0.2 32 | param set MC_ROLL_P 6 33 | param set MC_ROLLRATE_P 0.2 34 | param set MIS_TAKEOFF_ALT 2.5 35 | param set MPC_HOLD_MAX_Z 2.0 36 | param set MPC_Z_VEL_I 0.15 37 | param set MPC_Z_VEL_P 0.6 38 | param set NAV_ACC_RAD 2.0 39 | param set NAV_DLL_ACT 2 40 | param set RTL_DESCEND_ALT 5.0 41 | param set RTL_LAND_DELAY 5 42 | param set RTL_RETURN_ALT 30.0 43 | param set SENS_BOARD_ROT 0 44 | param set SENS_BOARD_X_OFF 0.000001 45 | param set SYS_AUTOSTART 4010 46 | param set SYS_MC_EST_GROUP 2 47 | param set SYS_RESTART_TYPE 2 48 | # added from AirSim/docs/sitl.md 49 | param set LPE_LAT 47.641468 50 | param set LPE_LON -122.140165 51 | param set COM_OBL_ACT 1 52 | # params below are failsafes for actual flight, ok when flying in sim 53 | param set NAV_RCL_ACT 0 54 | param set NAV_DLL_ACT 0 55 | # done 56 | replay tryapplyparams 57 | simulator start -s 58 | tone_alarm start 59 | gyrosim start 60 | accelsim start 61 | barosim start 62 | adcsim start 63 | gpssim start 64 | pwm_out_sim mode_pwm 65 | sensors start 66 | commander start 67 | land_detector start multicopter 68 | navigator start 69 | ekf2 start 70 | mc_pos_control start 71 | mc_att_control start 72 | mixer load /dev/pwm_output0 ROMFS/px4fmu_common/mixers/quad_dc.main.mix 73 | mavlink start -u 14556 -r 4000000 74 | mavlink start -u 14557 -r 4000000 -m onboard -o 14540 75 | mavlink stream -r 50 -s POSITION_TARGET_LOCAL_NED -u 14556 76 | mavlink stream -r 50 -s LOCAL_POSITION_NED -u 14556 77 | mavlink stream -r 50 -s GLOBAL_POSITION_INT -u 14556 78 | mavlink stream -r 50 -s ATTITUDE -u 14556 79 | mavlink stream -r 50 -s ATTITUDE_QUATERNION -u 14556 80 | mavlink stream -r 50 -s ATTITUDE_TARGET -u 14556 81 | mavlink stream -r 50 -s SERVO_OUTPUT_RAW_0 -u 14556 82 | mavlink stream -r 20 -s RC_CHANNELS -u 14556 83 | mavlink stream -r 250 -s HIGHRES_IMU -u 14556 84 | mavlink stream -r 10 -s OPTICAL_FLOW_RAD -u 14556 85 | logger start -e -t 86 | mavlink boot_complete 87 | replay trystart 88 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:xenial 2 | RUN apt-get update && apt-get install -y mesa-utils binutils module-init-tools && rm -rf /var/lib/apt/lists/* 3 | ADD NVIDIA-Linux-x86_64-381.22.run /tmp/NVIDIA-DRIVER.run 4 | RUN sh /tmp/NVIDIA-DRIVER.run -a -N --ui=none --no-kernel-module 5 | RUN rm /tmp/NVIDIA-DRIVER.run 6 | 7 | RUN apt-get update && apt-get install -y git wget unzip build-essential software-properties-common cmake && rm -rf /var/lib/apt/lists/* 8 | RUN wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - 9 | RUN apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-3.9 main" 10 | RUN apt-get update && apt-get install -y --allow-unauthenticated clang-3.9 && rm -rf /var/lib/apt/lists/* 11 | 12 | RUN update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.9 60 --slave /usr/bin/clang++ clang++ /usr/bin/clang++-3.9 13 | RUN update-alternatives --install /usr/bin/cc cc /usr/bin/clang 100 14 | RUN update-alternatives --install /usr/bin/cxx cxx /usr/bin/clang++ 100 15 | 16 | ENV TZ America/New_York 17 | 18 | RUN echo $TZ > /etc/timezone && \ 19 | apt-get update && apt-get install -y tzdata && \ 20 | rm /etc/localtime && \ 21 | ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \ 22 | dpkg-reconfigure -f noninteractive tzdata && \ 23 | apt-get clean 24 | 25 | RUN apt-get update && apt-get install -y sudo && rm -rf /var/lib/apt/lists/* 26 | RUN useradd -ms /bin/bash unreal && echo "unreal:unreal" | chpasswd && adduser unreal sudo 27 | RUN echo "unreal ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers 28 | USER unreal 29 | 30 | RUN sudo apt-get update && sudo apt-get install -y libnss3 libpangocairo-1.0-0 libgconf-2-4 libxi-dev libxcursor-dev libxss-dev libxcomposite-dev libasound-dev libatk1.0-dev libxrandr-dev libxtst-dev libopenal-dev && sudo rm -rf /var/lib/apt/lists/* 31 | COPY UnrealEngine-4.16.2-release.zip /home/unreal/UnrealEngine-4.16.2-release.zip 32 | RUN cd ~/ && unzip UnrealEngine-4.16.2-release.zip && rm UnrealEngine-4.16.2-release.zip 33 | RUN sudo apt-get update && cd ~/UnrealEngine-4.16.2-release && ./Setup.sh && ./GenerateProjectFiles.sh 34 | 35 | RUN cd ~/ && git clone https://github.com/Microsoft/AirSim.git && cd AirSim && git checkout b9a978de563dc0c16ffe7a2dd3e40916b7fe0c2b && cd cmake && sudo bash ./getlibcxx.sh; exit 0 36 | 37 | RUN cd ~/AirSim/Unreal/Plugins/AirSim/Source && cp AirSim.Build.cs AirSim.Build.4.15.cs && cp AirSim.Build.4.16.cs AirSim.Build.cs 38 | COPY rpc_patch.patch /home/unreal/rpc_patch.patch 39 | RUN cd ~/AirSim && ./setup.sh 40 | RUN cd ~/AirSim/external/rpclib && patch -p1 < /home/unreal/rpc_patch.patch 41 | RUN cd ~/AirSim && ./build.sh 42 | ENV EIGEN_ROOT /home/unreal/AirSim/eigen 43 | 44 | RUN cd ~/UnrealEngine-4.16.2-release && ./GenerateProjectFiles.sh -project="/home/unreal/AirSim/Unreal/Environments/Blocks/Blocks.uproject" -game -engine 45 | 46 | RUN mkdir -p /home/unreal/out 47 | RUN cd ~/AirSim/Unreal/Environments/Blocks && ~/UnrealEngine-4.16.2-release/Engine/Build/BatchFiles/RunUAT.sh BuildCookRun -project="$PWD/Blocks.uproject" -platform=Linux -clientconfig=Shipping -cook -allmaps -build -stage -pak -archive -archivedirectory="/home/unreal/out" 48 | 49 | RUN sudo apt-get update && sudo apt-get -y install git build-essential cmake python unzip python-jinja2 python-empy python-pip && sudo rm -rf /var/lib/apt/lists/* 50 | RUN sudo pip install catkin_pkg 51 | RUN sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 90 52 | RUN sudo update-alternatives --install /usr/bin/cxx cxx /usr/bin/g++ 90 53 | RUN sudo update-alternatives --set cc /usr/bin/gcc 54 | RUN sudo update-alternatives --set cxx /usr/bin/g++ 55 | RUN cd ~/ && git clone https://github.com/PX4/Firmware.git && cd Firmware && make posix_sitl_default 56 | 57 | LABEL com.nvidia.volumes.needed="nvidia_driver" 58 | ENV PATH /usr/local/nvidia/bin:${PATH} 59 | ENV LD_LIBRARY_PATH /usr/local/nvidia/lib:/usr/local/nvidia/lib64:${LD_LIBRARY_PATH} 60 | 61 | RUN sudo apt-get update && sudo apt-get -y install tmux && sudo rm -rf /var/lib/apt/lists/* 62 | 63 | CMD bash /home/unreal/Documents/launch.sh 64 | --------------------------------------------------------------------------------