Hello,
I am trying get the EXTENDED_SYS_STATE message so I could have access to landed_state to check if the drone is on ground or not. I tried using a code that worked in the past to get another message and it’s fields, but it strangely does not work when I replace with the EXTENDED_SYS_STATE respective information.
# -*- coding: utf-8 -*-
from __future__ import print_function
import time
from dronekit import connect, VehicleMode, LocationGlobalRelative
# Set up option parsing to get connection string
import argparse
parser = argparse.ArgumentParser(description='Commands vehicle using vehicle.simple_goto.')
parser.add_argument('--connect',
help="Vehicle connection target string. If not specified, SITL automatically started and used.")
args = parser.parse_args()
connection_string = args.connect
sitl = None
# Connect to the Vehicle
print('Connecting to vehicle on: %s' % connection_string)
vehicle = connect(connection_string, wait_ready=True)
while True:
@vehicle.on_message('EXTENDED_SYS_STATE')
def listener(self, name, message):
print(message.landed_state)
vehicle.close()
the command I use to run the script and the output I receive is this :
I am using a simulated drone create from a fork from the ardupilot master and dronekit. Is there something different about this message that I need to add other functions in dronekit to make it work?
I didn’t place a print for “Connected to vehicle” like you, but it does connected, I added other functions to test that.
May I ask you why the decorator I used is wrong? I have used it for other messages and it worked, like
SYSTEM_TIME to get the time_unix_usec field and the dronekit wiki suggests using this decorator for messages
You’re decorating a function inside a loop.
One time is enough.
The decorator is not wrong, you’re using it wrong.
I prefer .add_message_listener since it is removable, choose what suits best for your application.
If it is not printing anything, means that you could not be able to connect to the vehicle.
At least you should see:
If you don’t see the above message, means that you did not connect to the vehicle.
If you’re not seeing the output value of msg.landed_state line by line, means that vehicle is not producing that message.
Can you see that message from MAVProxy?
Type:
watch EXTENDED_SYS_STATE
I tried with both Copter and Plane, but can’t catch it either. Could be a VTOL feature, IDK, but does not matter since you should be able to catch the message and field value itself with the above technique.
Make sure your vehicle is sending that message with MAVProxy.
So the vehicle is emitting that message only if you request it.
So periodically send that COMMAND_LONG message to the vehicle from your script and try to catch the response.
I updated the code, give it a try.
Hello, I used the updated version, but it doesn’t give any value, the terminal where I am running the script, the only output is Connected to vehicle: udp:“numbers” and in the other where the drone is being simulated, just keep outputting Got COMMAND_ACK: REQUEST_MESSAGE: ACCEPTED.
I also tried the long MAV_CMD_REQUEST_MESSAGE 245 0 0 0 0 0 0 0 but the console only showed Got COMMAND_ACK: REQUEST_MESSAGE: ACCEPTED
Ok, Noticed something.
While running the script, if I go to MavProxy Console and send long MAV_CMD_REQUEST_MESSAGE 245 0 0 0 0 0 0 0 0 , the terminal with the script prints the value of EXTENDED_SYS_STATE.landed_state. I also armed the drone and lifted from the ground and sent the command again, and the printed value changed. Now just figure how to make the script to all this by itself
If there is no delay in the loop that sends the message request, it will be sent many times in rapid succession, which is probably not desired behavior. You could make the loop faster by decreasing the delay if you wanted to retrieve the extended system data more frequently.
If a blocking infinite loop like that is undesirable, you could spin it off into a thread or use a measured timeout within another loop to send it at a reasonable rate.