hello, i am trying to use PX4 with pymavlink but no matter how hard i tried , the drone is not working accprding to mav messages. I have tried to control the drone using qground control and it works properly with qgroundcontrol. But using pymavlink seems to be the issue. can anybody help me??
i have checked and PX4 works well with mavsdk, but not with pymavlink!!
here is the code that usese pymavlink
import time
from pymavlink import mavutil
master = mavutil.mavlink_connection("udp:127.0.0.1:14550")
master.wait_heartbeat()
print("Heartbeat from system (system %u component %u)" % (master.target_system, master.target_component))
master.mav.request_data_stream_send(master.target_system, master.target_component, mavutil.mavlink.MAV_DATA_STREAM_ALL, 1, 1)
# Wait for and print the altitude from GLOBAL_POSITION_INT messages
while True:
msg = master.recv_match(type='GLOBAL_POSITION_INT', blocking=True)
print(msg)
if msg:
altitude = msg.relative_alt / 1000.0
print("Altitude: %.2f meters" % altitude)
break
master.mav.command_long_send(
master.target_system, # target system
master.target_component, # target component
mavutil.mavlink.MAV_CMD_COMPONENT_ARM_DISARM, # command
1, # confirmation
1, # param1 (1 to indicate arm)
0, # param2 (unused)
0, # param3 (unused)
0, # param4 (unused)
0, # param5 (latitude, unused)
0, # param6 (longitude, unused)
0 # param7 (altitude, unused)
)
print("Arm command sent!")
# Wait for a COMMAND_ACK message
while True:
msg = master.recv_match(type='COMMAND_ACK', blocking=True)
if msg:
print(msg)
break
# master.mav.set_mode(4)
time.sleep(5)
master.mav.command_long_send(
master.target_system, # target system
master.target_component, # target component
mavutil.mavlink.MAV_CMD_NAV_TAKEOFF, # command
1, # confirmation
0, # param1 (unused)
0, # param2 (unused)
0, # param3 (unused)
0, # param4 (unused)
0, # param5 (latitude, unused)
0, # param6 (longitude, unused)
700 # param7 (altitude)
)
while True:
msg = master.recv_match(type='COMMAND_ACK', blocking=True)
if msg:
print(msg)
break
master.mav.request_data_stream_send(master.target_system, master.target_component, mavutil.mavlink.MAV_DATA_STREAM_ALL, 1, 1)
while True:
msg = master.recv_match(type='COMMAND_ACK', blocking=True)
if msg:
altitude = msg.relative_alt / 1000.0
print("Altitude: %.2f meters" % altitude)