Skip to content

Commit

Permalink
#211: Add zDistance commander packet to fly at absolute height
Browse files Browse the repository at this point in the history
  • Loading branch information
ataffanel committed Mar 30, 2017
1 parent b8a5b88 commit 5048114
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/modules/src/crtp_commander_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ typedef void (*packetDecoder_t)(setpoint_t *setpoint, uint8_t type, const void *
enum packet_type {
stopType = 0,
velocityWorldType = 1,
zDistanceType = 2,
};

/* ---===== 2 - Decoding functions =====--- */
Expand Down Expand Up @@ -103,11 +104,44 @@ static void velocityDecoder(setpoint_t *setpoint, uint8_t type, const void *data
setpoint->attitudeRate.yaw = values->yawrate;
}

/* velocityDecoder
* Set the Crazyflie velocity in the world coordinate system
*/
struct zDistancePacket_s {
float roll; // rad
float pitch; // ...
float yawrate; // rad/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 velocityPacket_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;
}

/* ---===== 3 - packetDecoders array =====--- */
const static packetDecoder_t packetDecoders[] = {
[stopType] = stopDecoder,
[velocityWorldType] = velocityDecoder,
[zDistanceType] = zDistanceDecoder,
};

/* Decoder switch */
Expand Down

0 comments on commit 5048114

Please sign in to comment.