How to Set Drone Speed Using DroneKit: Simple Guide
To set drone speed using
dronekit, use the vehicle.airspeed or vehicle.groundspeed properties to define the desired speed in meters per second. Update these properties before sending movement commands to control how fast the drone moves.Syntax
In DroneKit, you set the drone's speed by assigning a value to vehicle.airspeed or vehicle.groundspeed. These values are floats representing speed in meters per second.
vehicle.airspeed = speed_value: Sets the airspeed for the drone's movement commands.vehicle.groundspeed = speed_value: Sets the groundspeed for the drone's movement commands.
Use these before sending commands like simple_goto() to control how fast the drone flies.
python
vehicle.airspeed = 5.0 # Set airspeed to 5 m/s vehicle.groundspeed = 5.0 # Set groundspeed to 5 m/s
Example
This example connects to a drone, sets the airspeed to 3 meters per second, and commands the drone to fly to a specific location at that speed.
python
from dronekit import connect, VehicleMode, LocationGlobalRelative import time # Connect to the vehicle vehicle = connect('127.0.0.1:14550', wait_ready=True) # Set the airspeed to 3 m/s vehicle.airspeed = 3.0 # Define target location (latitude, longitude, altitude) target_location = LocationGlobalRelative(-35.363261, 149.165230, 20) # Arm and takeoff to 20 meters altitude def arm_and_takeoff(aTargetAltitude): while not vehicle.is_armable: print(" Waiting for vehicle to initialise...") time.sleep(1) vehicle.mode = VehicleMode("GUIDED") vehicle.armed = True while not vehicle.armed: print(" Waiting for arming...") time.sleep(1) vehicle.simple_takeoff(aTargetAltitude) while True: print(f" Altitude: {vehicle.location.global_relative_frame.alt}") if vehicle.location.global_relative_frame.alt >= aTargetAltitude * 0.95: print("Reached target altitude") break time.sleep(1) arm_and_takeoff(20) # Fly to the target location at set airspeed vehicle.simple_goto(target_location) # Wait for 30 seconds to reach time.sleep(30) # Land the vehicle vehicle.mode = VehicleMode("LAND") # Close vehicle object vehicle.close()
Output
Waiting for vehicle to initialise...
Waiting for arming...
Altitude: 0.0
Altitude: 1.2
Altitude: 5.8
Altitude: 19.5
Reached target altitude
Common Pitfalls
Common mistakes when setting drone speed with DroneKit include:
- Setting
airspeedorgroundspeedafter sending movement commands, which has no effect on current commands. - Using speeds too high or too low without considering drone capabilities, risking unstable flight.
- Confusing
airspeed(speed relative to air) withgroundspeed(speed relative to ground), which behave differently in windy conditions.
Always set speed before movement commands and verify the drone supports the speed values.
python
## Wrong way: Setting speed after command vehicle.simple_goto(target_location) vehicle.airspeed = 10.0 # This won't affect the ongoing command ## Right way: Set speed before command vehicle.airspeed = 10.0 vehicle.simple_goto(target_location)
Quick Reference
Summary tips for setting drone speed with DroneKit:
- Use
vehicle.airspeedorvehicle.groundspeedto set speed in m/s. - Set speed before sending movement commands like
simple_goto(). - Check drone documentation for max/min speed limits.
- Test speed changes in safe environments to avoid crashes.
Key Takeaways
Set drone speed by assigning to vehicle.airspeed or vehicle.groundspeed before movement commands.
Use speeds in meters per second and respect your drone's speed limits.
Setting speed after movement commands won't affect current flight behavior.
Test speed settings carefully in safe areas to ensure stable flight.