Skip to content

Commit

Permalink
Fully automated SITL betaflight
Browse files Browse the repository at this point in the history
  • Loading branch information
JacopoPan committed Oct 13, 2023
1 parent fc4a87e commit 2291bac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 10 additions & 0 deletions gym_pybullet_drones/envs/BetaAviary.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from gymnasium import spaces
import socket
import struct
import os
import subprocess
import time

from transforms3d.quaternions import rotate_vector, qconjugate

Expand Down Expand Up @@ -79,6 +82,13 @@ def __init__(self,
output_folder=output_folder
)

# Spawn SITL Betaflight instances (must have been created with assets/clone_bfs/sh first)
for i in range(num_drones):
FOLDER = os.path.dirname(os.path.abspath(__file__))+'/../../betaflight_sitl/bf'+str(i)+'/'
cmd = f"gnome-terminal -- bash -c 'cd {FOLDER} && ./obj/main/betaflight_SITL.elf; exec bash'"
subprocess.Popen(cmd, shell=True)
time.sleep(2)

# Initialize connection to BetaFlight Controller
self.UDP_IP = udp_ip
self.ARM_TIME = 1
Expand Down
8 changes: 4 additions & 4 deletions gym_pybullet_drones/examples/beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
executables for as many drones as needed (e.g. 2):
$ ./gym_pybullet_drones/assets/clone_bfs.sh 2
Example
Note
-------
Run as many SITL Betaflight as drones in the simulation
in separate terminals (navigate the each `bf0`, `bf1`, etc. folder first):
This example will automatically start as many SITL Betaflight as drones
in the simulation in separate terminals:
$ cd betaflights/bf0/
$ ./obj/main/betaflight_SITL.elf
Expand All @@ -19,7 +19,7 @@
$ ..
In a separate terminal, run:
Run as:
$ cd gym-pybullet-drones/gym_pybullet_drones/examples/
$ python beta.py
Expand Down

0 comments on commit 2291bac

Please sign in to comment.