Skip to content

Instantly share code, notes, and snippets.

Last active May 23, 2024 02:33
Show Gist options
  • Save sandyUni/6380bbaaa3306446ab10e499016b2093 to your computer and use it in GitHub Desktop.
Save sandyUni/6380bbaaa3306446ab10e499016b2093 to your computer and use it in GitHub Desktop.
# setup XTDRONE with gitee connection
# this script assumes you already have ros and gazebo installed
# for more infomation, please refers to and
set -x
sudo apt-get install -y ninja-build exiftool python-argparse python-empy python-toml python-numpy python-yaml python-dev python-pip ninja-build protobuf-compiler libeigen3-dev genromfs xmlstarlet libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
pip2 install pandas jinja2 pyserial cerberus pyulog numpy toml pyquaternion
pip3 install packaging numpy empy toml pyyaml jinja2
sudo apt-get install git build-essential
ROS_DIST=`ls /opt/ros` || echo "ros not installed in the default folder: /opt/ros, please make sure you have sourced it"
if [ -n $ROS_DIST ]
source /opt/ros/$ROS_DIST/ || echo "soure error, do you use bash shell? or have your ros correctly installed?"
echo "Your ros version is $(rosversion -d)"
ROS_DIST=$(rosversion -d)
ROS_PATH=$(which -a roscore)
if [ -z $ROS_PATH ]
echo "can not find roscore, exit"
exit 3
ROS_PATH_BIN="$(dirname "$ROS_PATH")"
ROS_PATH_DIST="$(dirname "$ROS_PATH_BIN")"
# setup mavros and mavros-extras in ./
echo "install mavros and mavros-extras"
sudo apt-get install ros-$ROS_DIST-mavros ros-$ROS_DIST-extras
wget -N || (echo "can not download file, exit" && exit 4 )
sudo ./
# steup px4
if [ -d PX4_Firmware ]
echo "PX4_Firmware fodler already exists, we will use it insead of git a new one"
cd PX4_Firmware
git clone
cd PX4_Firmware
git checkout -b xtdrone/dev v1.11.0-beta1 || ( echo "checkout faied, exit." && exit 2 )
cat > ../submodule.tmp << EOF
[submodule "mavlink/include/mavlink/v2.0"]
path = mavlink/include/mavlink/v2.0
url =
branch = master
[submodule "src/drivers/uavcan/libuavcan"]
path = src/drivers/uavcan/libuavcan
url =
branch = px4
[submodule "Tools/jMAVSim"]
path = Tools/jMAVSim
url =
branch = master
[submodule "Tools/sitl_gazebo"]
path = Tools/sitl_gazebo
url =
branch = master
[submodule "src/lib/matrix"]
path = src/lib/matrix
url =
branch = master
[submodule "src/lib/ecl"]
path = src/lib/ecl
url =
branch = master
[submodule "boards/atlflight/cmake_hexagon"]
path = boards/atlflight/cmake_hexagon
url =
branch = px4
[submodule "src/drivers/gps/devices"]
path = src/drivers/gps/devices
url =
branch = master
[submodule "src/modules/micrortps_bridge/micro-CDR"]
path = src/modules/micrortps_bridge/micro-CDR
url =
branch = px4
[submodule "platforms/nuttx/NuttX/nuttx"]
path = platforms/nuttx/NuttX/nuttx
url =
branch = px4_firmware_nuttx-9.1.0+
[submodule "platforms/nuttx/NuttX/apps"]
path = platforms/nuttx/NuttX/apps
url =
branch = px4_firmware_nuttx-9.1.0+
[submodule "platforms/qurt/dspal"]
path = platforms/qurt/dspal
url =
[submodule "Tools/flightgear_bridge"]
path = Tools/flightgear_bridge
url =
branch = master
[submodule "Tools/jsbsim_bridge"]
path = Tools/jsbsim_bridge
url =
[submodule "src/examples/gyro_fft/CMSIS_5"]
path = src/examples/gyro_fft/CMSIS_5
url =
mv .gitmodules .gitmodules.swp
mv -f ../submodule.tmp .gitmodules
# cat > ../submodule.tmp.PX4_Firmware << EOF
# [submodule "jMAVlib"]
# path = jMAVlib
# url =
# branch = master
# mv Tools/jMAVSim/.gitmodules Tools/jMAVSim/.gitmodules.swp
# mv -f ../submodule.tmp.PX4_Firmware Tools/jMAVSim/.gitmodules Tools/jMAVSim/.gitmodules
DONT_RUN=1 make px4_sitl_default gazebo
cd ..
# download XTDrone source
echo "download XTDrone source"
echo "current folder: $(pwd)"
if [ -d XTDrone ]
echo "Directory XTDrone already exists, use it insead of git cloning"
cd XTDrone
git clone
cd XTDrone
git submodule update --init --recursive
cp sensing/gimbal/gazebo_gimbal_controller_plugin.cpp $WORK_DIR/PX4_Firmware/Tools/sitl_gazebo/src/
cp sitl_config/init.d-posix/rcS $WORK_DIR/PX4_Firmware/ROMFS/px4fmu_common/init.d-posix/
cp sitl_config/worlds/* $WORK_DIR/PX4_Firmware/Tools/sitl_gazebo/worlds/
cp -r sitl_config/models/* $WORK_DIR/PX4_Firmware/Tools/sitl_gazebo/models/
# this following command will not run because the setupfile will
# cp -r sitl_config/models/{3d_gpu_lidar,3d_lidar,hokuyo_lidar,kinect,stereo_camera} $WORK_DIR/.gazebo/models/
cp sitl_config/launch/* $WORK_DIR/PX4_Firmware/launch/
cd ../
# generate source file
echo "Generating source file.. "
SOURCE_STR="#THIS file is auto-generated by"$'\n'
#ros related
SOURCE_STR=$SOURCE_STR"source $ROS_PATH_DIST/setup.bash"$'\n'
SOURCE_STR=$SOURCE_STR"source $WORK_DIR/PX4_Firmware/Tools/setup_gazebo.bash $WORK_DIR/PX4_Firmware $WORK_DIR/PX4_Firmware/build/px4_sitl_default"
# gazebo related
SOURCE_STR=$SOURCE_STR"if [ -n \$GAZEBO_MODEL_PATH ]"$'\n'"then"$'\n'"export GAZEBO_MODEL_PATH=\$GAZEBO_MODEL_PATH:$WORK_DIR/XTDrone/sitl_config/models/"$'\n'"else"$'\n'"export GAZEBO_MODEL_PATH=$WORK_DIR/XTDrone/sitl_config/models/"$'\n'"fi"$'\n'
echo "$SOUCE_NAME"' is ready, to setup your XTDrone environment, run the command' "\"source $SOUCE_NAME\""
echo 'NOTE: if you want to use gazebo to open world file in XTDrone/sitl_config/worlds, RUN' "\"source $SOUCE_NAME\" firstly."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment