Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/modules/src/crtp_commander_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ enum packet_type {
velocityWorldType = 8,
zDistanceType = 9,
hoverType = 10,
manualType = 11,
};

/* ---===== 2 - Decoding functions =====--- */
Expand All @@ -89,6 +90,46 @@ static void stopDecoder(setpoint_t *setpoint, uint8_t type, const void *data, si
return;
}

struct manualPacket_s {
float roll; //deg or deg/s depending on 'rate'
float pitch; //deg or deg/s depending on 'rate'
float yawrate; // deg/s
uint16_t thrust;
char rate; // True if roll/pitch in velocity mode
} __attribute__((packed));

/* manualDecoder
*
*/
static void manualDecoder(setpoint_t *setpoint, uint8_t type, const void *data, size_t datalen)
{
const struct manualPacket_s *values = data;


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

if(values->rate == true)
{
setpoint->mode.roll = modeVelocity;
setpoint->mode.pitch = modeVelocity;
setpoint->attitudeRate.roll = values->roll;
setpoint->attitudeRate.pitch = values->pitch;
}
else
{
setpoint->mode.roll = modeAbs;
setpoint->mode.pitch = modeAbs;
setpoint->attitude.roll = values->roll;
setpoint->attitude.pitch = values->pitch;
}

setpoint->mode.yaw = modeVelocity;

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

setpoint->thrust = values->thrust;
}

struct velocityPacket_s {
float vx; // m in the world frame of reference
float vy; // ...
Expand Down Expand Up @@ -493,6 +534,7 @@ const static packetDecoder_t packetDecoders[] = {
[velocityWorldType] = velocityDecoder,
[zDistanceType] = zDistanceDecoder,
[hoverType] = hoverDecoder,
[manualType] = manualDecoder,
};

/* Decoder switch */
Expand Down