Hello everyone,
We are currently attempting to change the speed of a fixed-wing UAV using the MAV_CMD_DO_CHANGE_SPEED command in guided mode within a simulation. However, despite our efforts, nothing seems to happen. We are unsure whether it is possible to adjust the speed in this manner in the simulation.
Below is the code we are using to change the speed:
def set_speed(connection, target_speed, throttle=-1, speed_type=0, retry_interval=2, tolerance=1):
while True:
msg = connection.recv_match(type=‘VFR_HUD’, blocking=True, timeout=5)
if msg:
current_speed = msg.groundspeed
print(f"Current speed: {current_speed} m/s")
else:
print(“Failed to receive current speed message.”)
continue
if abs(current_speed - target_speed) < tolerance:
print("Speed set successfully.")
break
connection.mav.command_long_send(
connection.target_system, # target_system
connection.target_component, # target_component
mavutil.mavlink.MAV_CMD_DO_CHANGE_SPEED, # command
0, # confirmation
speed_type, # speed type (0 for airspeed, 1 for groundspeed)
target_speed, # new speed in m/s
throttle, # throttle percentage (-1 means no change)
0, 0, 0, 0, 0 # param4-7 (not used)
)
print(f"Setting speed to: {target_speed} m/s with throttle: {throttle}%")
time.sleep(retry_interval)
Could someone please help us identify where we might be going wrong, or confirm if it is even possible to change the speed of a fixed-wing UAV in guided mode within the simulation? If it is not possible, is there a way to modify the ArduPilot code or the SITL simulation to achieve our goal?
Thank you in advance for your assistance!