1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Wifiルータを中継APにして、TelloEduドローン2機の無人プログラム編隊飛行に成功(Macbook PC)

Last updated at Posted at 2021-07-27

__過去2本の記事__の続編に続いて、いよいよ2機のドローンに対して、Macbook PCから同時に操作コマンドを送信してみます。2機とも、離陸から着陸まで、意図した通りに動作しました。

###実行画面 (Macbook PC)

####実行コード

python3 two_drone_remote_ctl.py -drone1_ip 192.168.0.9 -drone2_ip 192.168.0.11
Terminal
electron@diynoMacBook-Pro TelloEduSwarm % python3 two_drone_remote_ctl.py -drone1_ip 192.168.0.9 -drone2_ip 192.168.0.11
1機目のドローンに接続します。('192.168.0.9', 8889)
2機目のドローンに接続します。('192.168.0.11', 8889)
electron@diynoMacBook-Pro TelloEduSwarm % 

###実行したスクリプトファイル

two_drone_remote_ctl.py
import socket, argparse, time    

# 各機体のIPアドレスを、コマンドライン引数から受け取る
parser = argparse.ArgumentParser(description='')  
parser.add_argument('-drone1_ip')  
parser.add_argument('-drone2_ip')  

args = parser.parse_args() 
fst_dron_ip = args.drone1_ip
snd_dron_ip = args.drone2_ip

#print("IPアドレス {0} 番のTelloEduドローンに操作コマンドを送ります。".format(tello_ip))

# TelloEduのポート番号は全機体、同じ定数文字列
tello_port = 8889
fst_drone_address = (fst_dron_ip, tello_port)
snd_drone_address = (snd_dron_ip, tello_port)

print("1機目のドローンに接続します。" + str(fst_drone_address))
print("2機目のドローンに接続します。" + str(snd_drone_address))

socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

# 両機にcommand指令を伝達
socket.sendto('command'.encode('utf-8'), fst_drone_address)
socket.sendto('command'.encode('utf-8'), snd_drone_address)

# 前の動作が終わるまで、sleepで待機
time.sleep(3)

# 両機、同時に離陸
socket.sendto('takeoff'.encode('utf-8'), fst_drone_address)
socket.sendto('takeoff'.encode('utf-8'), snd_drone_address)

time.sleep(3)

# 機体1: 右20, 前20, 上20の座表地点に向けて、右斜め上に移動
socket.sendto('rc 20 20 20 0'.encode('utf-8'), fst_drone_address)
# 機体2: 左20, 前20, 上20の座表地点に向けて、右斜め上に移動
socket.sendto('rc -20 20 20 0'.encode('utf-8'), snd_drone_address)

time.sleep(3)

# 機体1: 時計回りに45度回転座
socket.sendto('cw 45'.encode('utf-8'), fst_drone_address)
# 機体2: 反時計回りに45度回転座
socket.sendto('ccw 45'.encode('utf-8'), snd_drone_address)

time.sleep(3)

# 機体1: 50前進
socket.sendto('forward 50'.encode('utf-8'), fst_drone_address)
# 機体2: 50前進
socket.sendto('forward 50'.encode('utf-8'), snd_drone_address)

time.sleep(3)

# 機体1: 100上昇
socket.sendto('up 100'.encode('utf-8'), fst_drone_address)
# 機体2: 100上昇
socket.sendto('up 100'.encode('utf-8'), snd_drone_address)

time.sleep(3)

# 機体1: 20上昇
socket.sendto('up 20'.encode('utf-8'), fst_drone_address)
# 機体2: 20降下
socket.sendto('down 20'.encode('utf-8'), snd_drone_address)

time.sleep(3)

# 機体1: 20降下
socket.sendto('down 20'.encode('utf-8'), fst_drone_address)
# 機体2: 20上昇
socket.sendto('up 20'.encode('utf-8'), snd_drone_address)

time.sleep(3)

# 両機、同時に着陸
socket.sendto('land'.encode('utf-8'), fst_drone_address)
socket.sendto('land'.encode('utf-8'), snd_drone_address)

time.sleep(3)
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?