Core¶
Copyright MIT GNU General Public License v3.0
MIT BWSI Autonomous Drone Racing Course - UAV Neo
File Name: drone_core.py File Description: Contains the Drone class, the top level of the drone_core library.
- class drone_core.Drone¶
The top level drone module containing several submodules which interface with and control the different pieces of the drone hardware.
- abstractmethod get_delta_time() float¶
Returns the number of seconds elapsed in the previous frame.
- Returns:
The number of seconds between the start of the previous frame and the start of the current frame.
Example:
counter += uav.get_delta_time()
- abstractmethod go() None¶
Starts the drone, beginning in default mode.
Note
go blocks execution until the program is exited.
- abstractmethod set_start_update(start: Callable[[], None], update: Callable[[], None], update_slow: Callable[[], None] | None = None) None¶
Sets the start and update functions used in user program mode.
- Parameters:
start – A function called once when the drone enters user program mode.
update – A function called every frame in user program mode.
update_slow – A function called once per fixed time interval in user program mode (by default once per second).
Example:
rc = Drone() def start(): print("This function is called once") def update(): print("This function is called every frame") rc.set_start_update(start, update) rc.go()
- abstractmethod set_update_slow_time(time: float = 1.0) None¶
Changes the time between calls to update_slow.
- Parameters:
time – The time in seconds between calls to update_slow.
Example:
uav.set_update_slow_time(2)
- drone_core.create_drone(isSimulation: bool | None = None) Drone¶
Generates a drone object based on the isSimulation argument or execution flags.
- Parameters:
isSimulation – If True, create a DroneSim. If None, decide based on the command line arguments.
- Returns:
A DroneSim object for use with the Unity simulation.
Note
If isSimulation is None, this function will return a DroneSim if the program was executed with the “-s” flag.
If the program was executed with the “-d” flag, a display window is created.
If the program was executed with the “-h” flag, it is run in headless mode, which disables the display module.