Ardupilot: 开启多个无人机SITL仿真实例Shell脚本

发布时间 2023-06-27 08:57:10作者: 前端人生
将该脚本文件放入Ardupilot目录下,文件名称为swarm.sh ' #!/bin/bash # run example: start run three ArduCopter sitl # bash swarm.sh ArduCopter 3 # Vehicle start location locs=( '22.71343050,114.40813420,0.0,0' '22.71343050,114.40915080,0.0,0' '22.71344530,114.41021830,0.0,0' '22.71345030,114.41111680,0.0,0' '22.71346020,114.41186790,0.0,0' ) # mavproxy out udp port, Mission Planner connect this port, user can modify udp='udp:192.168.124.11:14550' types=("ArduCopter" "ArduPlane" "ArduRover") type=$1 # in types num=`expr $2 + 0` # sitl count have_type=0 if [ $# -lt 2 ]; then echo 'Input arg error!'; exit 0; fi # check sitl instance count if [ $num -gt ${#locs[*]} ]; then num=${#locs[*]}; fi # check type for t in ${types[*]} do echo $t$type if [ $t = $type ]; then have_type=1; break; fi done # check pass, start run all sitl # create shell term: gnome-terminal --titile='' --window -e "Run Command" --tab --title='' -e "Run Command" ... if [ $have_type -eq 1 ] then echo 'Vehicle Count='${num} if [ $num -gt 0 ] then # gnome-terminal: create new terminal cmd='gnome-terminal --title="UAV0" --window -e ' index=0 sim='' tab='' for loc in ${locs[*]} do sim=${sim}${tab}'"Tools/autotest/sim_vehicle.py -v '${type}' -I '${index}' -l '${loc}' --auto-sysid --out='${udp}'"' index=`expr $index + 1` if [ $index -eq $num ]; then break; fi tab=' --tab --title="UAV'${index}'" -e ' done runcmd=${cmd}${sim} echo $runcmd eval $runcmd #run cmd else echo 'Vehicle Count Error! Max Count: '${#locs[*]} fi else echo 'Vehicle Type Error!' echo 'Vehicle Type: ' for t in ${types[*]}: do echo ' '${t} done fi # gnome-terminal --title="UAV" -- sim_vehicle.py -v ArduCopter -I 3 -l 22.71344530,114.41021830,0.0,0 --auto-sysid --out=udp:192.168.124.11:14550 `