Ardupilot: 开启多个无人机SITL仿真实例Shell脚本,使用MP地面站无人机编队仿真

将该脚本文件放入Ardupilot目录下,可将文件命名为swarm.sh

改变该文件权限: chmod u+x swarm.sh

例如: 开启三台Copter无人机仿真示例,可运行脚本: bash swarm.sh ArduCopter 3

#!/bin/bash

# run example: start run three ArduCopter sitl
# bash swarm.sh ArduCopter 3

# Vehicle start location
locs=(
        '22.06942420,113.11890360,0.0,0'
      '22.06941930,113.11901900,0.0,0'
      '22.06941930,113.11913700,0.0,0'
      '22.06941930,113.11926980,0.0,0'
      '22.06941680,113.11940660,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

 

posted @   前端人生  阅读(427)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示