diff --git a/gym_pybullet_drones/envs/BetaAviary.py b/gym_pybullet_drones/envs/BetaAviary.py index c5f36426f..6cf6caee6 100644 --- a/gym_pybullet_drones/envs/BetaAviary.py +++ b/gym_pybullet_drones/envs/BetaAviary.py @@ -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 @@ -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 diff --git a/gym_pybullet_drones/examples/beta.py b/gym_pybullet_drones/examples/beta.py index 8d822262d..f7da8dd5e 100644 --- a/gym_pybullet_drones/examples/beta.py +++ b/gym_pybullet_drones/examples/beta.py @@ -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 @@ -19,7 +19,7 @@ $ .. -In a separate terminal, run: +Run as: $ cd gym-pybullet-drones/gym_pybullet_drones/examples/ $ python beta.py