Hi,
Following another post without answer (Python script chain of commands with transitions/triggers to Mavlink - RC plane), I’m working on “slices” to go to my final goal.
Actually, I need to read and print the Altitude of my plane and use this altitude as a trigger to send some “RC PWM” commands “Altitude 50m => commands”
After searching a lot, I have to say that I’m lost, I’ve got that code below but can’t “print” the result of the “Altitude” coming from “GLOBAL_POSITION_INT”. The result in Mavproxy is “Command accepted” but nothing more
#!/usr/bin/python3
import time
import sys
from pymavlink import mavutil
# connect to the flight controller
master = mavutil.mavlink_connection('tcp:127.0.0.1:5762')
# wait for a heartbeat
master.wait_heartbeat()
# inform user
print("Connected to system:", master.target_system, ", component:", master.target_component)
# Wait for the first heartbeat to set the system and component ID of remote system for the link
master.wait_heartbeat()
print("Heartbeat from system (system %u component %u)" % (master.target_system, master.target_component))
# Define command_long_encode message to send MAV_CMD_SET_MESSAGE_INTERVAL command
message = master.mav.command_long_encode(
master.target_system, # Target system ID
master.target_component, # Target component ID
mavutil.mavlink.MAV_CMD_SET_MESSAGE_INTERVAL, # ID of command to send
0, # Confirmation
mavutil.mavlink.MAVLINK_MSG_ID_GLOBAL_POSITION_INT, # param1: Message ID to be streamed
1000000, # param2: Interval in microseconds
0, # param3 (unused)
0, # param4 (unused)
0, # param5 (unused)
0, # param5 (unused)
0 # param6 (unused)
)
# Send the COMMAND_LONG
master.mav.send(message)
# Wait for a response (blocking) to the MAV_CMD_SET_MESSAGE_INTERVAL command and print result
response = master.recv_match(type='COMMAND_ACK', blocking=True)
if response and response.command == mavutil.mavlink.MAV_CMD_SET_MESSAGE_INTERVAL and response.result == mavutil.mavlink.MAV_RESULT_ACCEPTED:
print("Command accepted")
else:
print("Command failed")
I can’t identify wich field to print in this code.
If anyone can give any help as I’m stuck, many thanks !
Nicolas