I want to implement mission load through pymavlink and let the drone take off normally according to the site. This is my code but I did not succeed in getting the load task successful,I got stuck the first time in the for loop, and the loop did not continue。
This is output of the console
############
Heartbeat from system (system 1 component 1)
10
MISSION_REQUEST {target_system : 255, target_component : 0, seq : 0}
Sending waypoint 0
############
This is my code:
master = mavutil.mavlink_connection(‘udp:0.0.0.0:14550’)
master.wait_heartbeat()
print(“Heartbeat from system (system %u component %u)” % (master.target_system, master.target_system))
def load_mission_txt():
loader = mavwp.MAVWPLoader()
loader_count = loader.load("./mission.txt") # load mission
print(loader_count) # count waypoints of mission.txt
master.waypoint_count_send(loader_count) # waypoint count send
try:
for i in range(loader_count): # looping to send each waypoint information
msg = master.recv_match(type=['MISSION_REQUEST'], blocking=True)
print(msg)
master.mav.send(loader.wp(msg.seq))
print('Sending waypoint {0}'.format(msg.seq))
mission_ack_msg = master.recv_match(type=['MISSION_ACK'], blocking=True)
except TimeoutError:
print('upload mission timeout')
else:
print("upload mission successful")