Drone Control
This tutorial will guide you through controlling a drone in the AirGen simulation environment within the GRID platform. You’ll learn fundamental operations including takeoff, altitude control, navigating using different movement methods, path planning, and landing.
Notebook for this example can be found: Here
Getting Started: Initializing Your Drone
First, let’s initialize a drone object in the AirGen environment. This is our entry point to controlling aerial vehicles in the simulation.
This code creates an instance of a drone that we can control in our simulation. The AirGenDrone
class provides an interface to the underlying vehicle simulation.
Basic Flight Operations
Taking Off and Setting Altitude
After initializing our drone, the first steps are to take off and reach a safe operating altitude:
In AirGen, altitude uses a negative Z-axis convention, which means negative values represent positions above the ground. The second parameter (5) specifies the velocity in meters per second.
Flight Patterns Using Different Control Methods
AirGen provides multiple methods to control drone movement. Let’s explore three different approaches to fly the same square pattern.
Method 1: Velocity Control
The first method uses velocity control, where we specify the speed and direction for each segment:
The moveByVelocityAsync
method takes four parameters:
vx
: Velocity in the X direction (east/west)vy
: Velocity in the Y direction (north/south)vz
: Velocity in the Z direction (up/down)duration
: Time to maintain this velocity in seconds
Method 2: Position Control
The second method uses absolute position control, where we specify exact coordinates for the drone to reach:
The moveToPositionAsync
method takes four parameters:
x, y, z
: Target position coordinatesvelocity
: Speed at which to move to the target position
Method 3: Path Control
The third method uses path control, where we define a series of waypoints for the drone to follow:
The moveOnPathAsync
method is more complex and takes several parameters:
waypoints
: List of Vector3r points defining the pathvelocity
: Speed in m/stimeout_sec
: Maximum time to complete the operationdrivetrain
: Control mode for the drone’s movementyaw_mode
: Controls how the drone’s heading changes during flightlookahead
: Distance to look ahead on the pathadaptive_lookahead
: Whether to adapt the lookahead distance based on velocity
Controlling Orientation During Flight
You can control the drone’s orientation (yaw) while following a path:
By changing the drivetrain parameter to ForwardOnly
, the drone will automatically adjust its yaw to face the direction of travel, similar to how an airplane flies.
Landing Sequence
When finished with flight operations, it’s important to land the drone safely:
The landing sequence first descends to a safe height (2 meters) and then performs the landing operation.