mavlink icon indicating copy to clipboard operation
mavlink copied to clipboard

Clarification: Home Position Q

Open flybrianfly opened this issue 2 years ago • 2 comments

I'm writing code for my MAVLink library for my company's flight stack to send the home position when the vehicle is armed. This is actually to facilitate a companion path planning computer to know the origin of the NED frame to convert mission items from a global to a local NED frame.

The home position message specifies q as a normal vector perpendicular to the surface and aligned with the heading. This makes sense and I assume that q is a quaternion. Is there more information or an example for how q should be computed? Of course quaternions can come in multiple orders (i.e. rotation first, rotation last, etc), so I think a little more clarity would help with general applicability of this message across flight stacks.

Also the approach_x, approach_y, and approach_z variables are a little confusing and seem to imply that for a fixed-wing aircraft, takeoff and landing should happen in opposite directions? Which doesn't make sense to me.

flybrianfly avatar May 09 '22 16:05 flybrianfly

Hi @flybrianfly

Yes, q is a quaternion, but I don't know how it should work "for certain".

HOME_POSITION used to be set SET_HOME_POSITION which would allow you to set q directly. That is deprecated but is now set using MAV_CMD_DO_SET_HOME which does not have the quaternion. Further, in some flight stacks the home position is stored in a slot for the first mission item as a waypoint, and that does not have a quaternion. Upshot, possibly you cannot set it directly.

The implementation in PX4 is here: https://github.com/PX4/PX4-Autopilot/blob/master/src/modules/mavlink/streams/HOME_POSITION.hpp

matrix::Quatf q(matrix::Eulerf(0.f, 0.f, home.yaw));
q.copyTo(msg.q);

msg.approach_x = 0.f;
msg.approach_y = 0.f;
msg.approach_z = 0.f;

ArduPilot sets it to [1,0,0,0] here: https://github.com/ArduPilot/ardupilot/blob/master/libraries/GCS_MAVLink/GCS_Common.cpp#L2495

const float q[4] = {1.0f, 0.0f, 0.0f, 0.0f};

I don't understand quaternions. To me that means the value is unreliable and should probably be deprecated. I'll see if I can get a better answer.

@auturgy @julianoes If you have any thoughts on this, I'd appreciate them!

hamishwillee avatar May 11 '22 03:05 hamishwillee

Discussed in the MAV call. First shot at addressing it: https://github.com/mavlink/mavlink/pull/1843

hamishwillee avatar May 11 '22 08:05 hamishwillee