Problems trying to calibrate magnetometer, accelerometer...

182 views
Skip to first unread message

Nacho

unread,
May 5, 2021, 4:32:31 AM5/5/21
to MAVLink
Good morning everybody,

I'm new in MAVLink, so I'm having problems trying to set up a calibration for different sensors in Python (like it would be done in QGroundControl).

First I established a connection and received a Heartbeat (until here no problem), then I send a message to stream all data, set the preflight mode (not sure if it worked), and start calibrating the magnetometer. The autopilot beeps but it seems nothing else happens. Also I'm not quite sure on how to receive messages regarding the state of the magnetometer calibration.

I'm kind of lost and would appreciate any help to finally start the calibration for the different sensors.

from pymavlink import mavutil

the_connection = mavutil.mavlink_connection('/dev/tty.usbmodem01')
the_connection.wait_heartbeat()
print("Heartbeat from system (system %u component %u)" % (the_connection.target_system, the_connection.target_system),"\n")
the_connection.mav.request_data_stream_send(the_connection.target_system, the_connection.target_component, mavutil.mavlink.MAV_DATA_STREAM_ALL, 10, 1)

the_connection.mav.set_mode_send(the_connection.target_system,
                                 mavutil.mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED,
                                 mavutil.mavlink.MAV_MODE_PREFLIGHT)

the_connection.mav.command_long_send(the_connection.target_system, 0,
                                     mavutil.mavlink.MAV_CMD_DO_START_MAG_CAL, 0,
                                     0, 0, 1, 0, 0, 0, 0)



Hamish Willee

unread,
May 5, 2021, 7:33:00 PM5/5/21
to MAVLink
What flight stack are you using?
If you're working on ArduPilot then I'd suggest you re-share this question on the pymavlink gitter: https://gitter.im/ArduPilot/pymavlink
If you're working on PX4 I'd suggest you switch to MAVSDK which supports sensor calibration out of the box (this might work on Ardupilot but is completely untested).

Nacho

unread,
May 6, 2021, 2:49:12 AM5/6/21
to MAVLink

I'm using a PX4, connected by usb and just with a GPS Module. Is there a possibility to make it with Pymavlink? It's an assignment and they require me to do it that way. If there is no other way I will try on MAVSDK. 
Thanks for your answer and best regards.

Hamish Willee

unread,
May 6, 2021, 2:52:30 AM5/6/21
to MAVLink

> I'm using a PX4, connected by usb and just with a GPS Module. Is there a possibility to make it with Pymavlink? It's an assignment and they require me to do it that way. If there is no other way I will try on MAVSDK. Thanks for your answer and best regards.

You're welcome. You can almost certainly do it with Pymavlink. The reason I was suggesting MAVSDK is because it already works. So perhaps you could inspect the code and determine what it does - then reverse engineer and do the same thing in Pymavlink? You could also ask on the #mavsdk channel - they may be able to offer advice (but I would inspect the code first



Nacho

unread,
May 6, 2021, 2:55:09 AM5/6/21
to MAVLink
Certainly it's a very good idea, I will try it this way then. Thank you!

Nacho

unread,
May 6, 2021, 4:09:28 AM5/6/21
to MAVLink

I have a problem now with the message "MAG_CAL_PROGRESS"
When I type: the_connection.recv_match(type='MAG_CAL_PROGRESS',blocking=True).to_dict()
The program stands still and doesn't receive any data.

But sending the message "COMMAND_ACK"
The program writes:
name: 42424  value: 3 (MAV_CMD_DO_START_MAG_CAL)
name: 42425  value: 3 (MAV_CMD_DO_ACCEPT_MAG_CAL)

This means the program receives the commands but doesn't start calibrating.
Anyone know why it wouldn't start?
Thanks in advance.

Nacho

unread,
May 6, 2021, 4:57:52 AM5/6/21
to MAVLink
I just found out, when sending 

message = the_connection.recv_match(type='COMMAND_ACK',blocking=True).to_dict()
print('name: %s\tvalue: %d' % (message['command'], message['result']))

I obtained
name: 42424  value: 3 
name: 42425  value: 3

This value: 3 refers to the value 3 of MAV_RESULT, which is MAV_RESULT_UNSUPPORTED

What does it mean that the command is not supported?
Thanks in advance,
Nacho
Reply all
Reply to author
Forward
0 new messages