diff --git a/crazyflie_software/crazyflie-firmware-2021.06/src/modules/src/crtp_commander_generic.c b/crazyflie_software/crazyflie-firmware-2021.06/src/modules/src/crtp_commander_generic.c index fd8745653d2389f2bbb3ab6be904a67211edef88..9d038cc5cef93c1fedca5e75ffc24ea7ad3e9524 100644 --- a/crazyflie_software/crazyflie-firmware-2021.06/src/modules/src/crtp_commander_generic.c +++ b/crazyflie_software/crazyflie-firmware-2021.06/src/modules/src/crtp_commander_generic.c @@ -71,6 +71,7 @@ enum packet_type { hoverType = 5, fullStateType = 6, positionType = 7, + attitudeRateType = 8, }; /* ---===== 2 - Decoding functions =====--- */ @@ -367,6 +368,37 @@ static void positionDecoder(setpoint_t *setpoint, uint8_t type, const void *data setpoint->attitude.yaw = values->yaw; } +/* + * Attitude rate decoder, + * packet contains the desired attitude rate in addition to the thrust value + */ +struct attitudeRatePacket_s{ + float rollRate; // deg/s + float pitchRate; // deg/s + float yawRate; // deg/s + float thrust; // thrust percentage 0 - 60,000 +} __attribute__((packed)); +static void attitudeRateDecoder(setpoint_t *setpoint, uint8_t type, const void *data, size_t datalen){ + + const struct attitudeRatePacket_s *values = data; + + ASSERT(datalen == sizeof(struct attitudeRatePacket_s)); + + setpoint->mode.x = modeDisable; + setpoint->mode.y = modeDisable; + setpoint->mode.z = modeDisable; + + setpoint->mode.roll = modeVelocity; + setpoint->mode.pitch = modeVelocity; + setpoint->mode.yaw = modeVelocity; + + setpoint->attitudeRate.roll = values->rollRate; + setpoint->attitudeRate.pitch = values->pitchRate; + setpoint->attitudeRate.yaw = values->yawRate; + + setpoint->thrust = values->thrust; +} + /* ---===== 3 - packetDecoders array =====--- */ const static packetDecoder_t packetDecoders[] = { [stopType] = stopDecoder, @@ -377,6 +409,7 @@ const static packetDecoder_t packetDecoders[] = { [hoverType] = hoverDecoder, [fullStateType] = fullStateDecoder, [positionType] = positionDecoder, + [attitudeRateType] = attitudeRateDecoder, }; /* Decoder switch */