What is happening
I’m trying to navigate a drone in GUIDED mode, using Dronekit for Python.
When I set a speed and navigate to a certain position, the speed is not correctly set. Instead, the drone always uses the speed set in the parameters.
For the first attempts, I used Copter v4.5.7. I also tried upgrading to v4.6.0, as well as downgrading to v4.4.4 (i remembered flying a copter in 4.4.4 once where everything worked), all to no avail.
Detailed description
First, I set the speed using MAV_CMD_DO_CHANGE_SPEED
, then set the position using SET_POSITION_TARGET_GLOBAL_INT
, then set the speed again. I’m calling it twice since I’m not entirely sure if it needs to be before or after the position command.
I’m using Dronekit v2.9.2. The speed is set with the following code:
msg = self.vehicle.message_factory.command_long_encode(
0, 0, # target system, target component
mavutil.mavlink.MAV_CMD_DO_CHANGE_SPEED, # command
0, # confirmation
1, # speed type, ignore on ArduCopter
speed, # speed
0, 0, 0, 0, 0 # ignore other parameters
)
self.vehicle.send_mavlink(msg)
self.vehicle.flush()
, the position with this code:
msg = self.vehicle.message_factory.set_position_target_global_int_encode(
0, # time_boot_ms (not used)
0, 0, # target system, target component
mavutil.mavlink.MAV_FRAME_GLOBAL_RELATIVE_ALT_INT, # frame
0b0000101111111000, # type_mask ("1" means "ignore")
round(aLocation.lat * 1e7), # lat_int - X Position in WGS84 frame in 1e7 * meters
round(aLocation.lon * 1e7), # lon_int - Y Position in WGS84 frame in 1e7 * meters
aLocation.alt,
# alt - Altitude in meters in AMSL altitude, not WGS84 if absolute or relative, above terrain if GLOBAL_TERRAIN_ALT_INT
0, # X velocity in NED frame in m/s
0, # Y velocity in NED frame in m/s
0, # Z velocity in NED frame in m/s
0, 0, 0, # afx, afy, afz acceleration (not supported yet, ignored in GCS_Mavlink)
math.radians(yaw), self.vehicle._yawspeed) # yaw, yaw_rate (not supported yet, ignored in GCS_Mavlink)
self.vehicle.send_mavlink(msg)
The parameters can be found here:
, the flight logs here (the drone was always supposed to fly at 1 m/s):