Z_distance commander coordinates logic

Post Reply
Posts: 14
Joined: Wed Jan 20, 2021 4:03 pm

Z_distance commander coordinates logic

Post by Max_Kemmeren »

Dear all,

I have a small question. I have been using the Z_distance command to set a setpoint (roll,pitch, yaw rate, z_distance). My question is why the yaw rate that I command is inverted to its negative value. This seems inconsistent to the coordinate system found on the bitcraze website.

As positive yaw rate should increase the yaw angle right? But when commanded to do a positive yaw rate, the commander makes it a negative rate see below.

/* zDistanceDecoder
* Set the Crazyflie absolute height and roll/pitch angles
struct zDistancePacket_s {
float roll; // deg
float pitch; // ...
float yawrate; // deg/s
float zDistance; // m in the world frame of reference
} __attribute__((packed));
static void zDistanceDecoder(setpoint_t *setpoint, uint8_t type, const void *data, size_t datalen)
const struct zDistancePacket_s *values = data;

ASSERT(datalen == sizeof(struct zDistancePacket_s));

setpoint->mode.z = modeAbs;

setpoint->position.z = values->zDistance;

setpoint->mode.yaw = modeVelocity;

setpoint->attitudeRate.yaw = -values->yawrate;

setpoint->mode.roll = modeAbs;
setpoint->mode.pitch = modeAbs;

setpoint->attitude.roll = values->roll;
setpoint->attitude.pitch = values->pitch;

Is this a mistake or what is the reasoning?
Posts: 2463
Joined: Tue Feb 06, 2007 12:36 pm

Re: Z_distance commander coordinates logic

Post by arnaud »

This is legacy and unfortunately I do not have an answer for that other than this was required to get the yaw to work in the right direction. Since we are keeping the radio packets backwards compatible, this is not something that can be changed without breaking backwards compatibility.

Another oddity with the yaw is that it is also inverted at the other side of the PID controller: https://github.com/bitcraze/crazyflie-f ... pid.c#L114.

We have planned to clean-up and document the units used in the Crazyflie as well as the control path, this will most likely be part of it.
Post Reply