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 9d038cc5cef93c1fedca5e75ffc24ea7ad3e9524..a4b1f55c47b4b46387a0a6fd2fb5348b3465c9e1 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 @@ -72,6 +72,7 @@ enum packet_type { fullStateType = 6, positionType = 7, attitudeRateType = 8, + attitudeType = 9, }; /* ---===== 2 - Decoding functions =====--- */ @@ -399,6 +400,37 @@ static void attitudeRateDecoder(setpoint_t *setpoint, uint8_t type, const void * setpoint->thrust = values->thrust; } +/* + * Custom Attitude decoder, bypasses the normal attitude control path, + * packet contains the desired attitude angle in addition to the thrust value + */ +struct attitudePacket_s{ + float rollAngle; // deg + float pitchAngle; // deg + float yawAngle; // deg + float thrust; // thrust percentage 0 - 60,000 +} __attribute__((packed)); +static void attitudeDecoder(setpoint_t *setpoint, uint8_t type, const void *data, size_t datalen){ + + const struct attitudePacket_s *values = data; + + ASSERT(datalen == sizeof(struct attitudePacket_s)); + + setpoint->mode.x = modeDisable; + setpoint->mode.y = modeDisable; + setpoint->mode.z = modeDisable; + + setpoint->mode.roll = modeAbs; + setpoint->mode.pitch = modeAbs; + setpoint->mode.yaw = modeAbs; + + setpoint->attitude.roll = values->rollAngle; + setpoint->attitude.pitch = values->pitchAngle; + setpoint->attitude.yaw = values->yawAngle; + + setpoint->thrust = values->thrust; +} + /* ---===== 3 - packetDecoders array =====--- */ const static packetDecoder_t packetDecoders[] = { [stopType] = stopDecoder, @@ -410,6 +442,7 @@ const static packetDecoder_t packetDecoders[] = { [fullStateType] = fullStateDecoder, [positionType] = positionDecoder, [attitudeRateType] = attitudeRateDecoder, + [attitudeType] = attitudeDecoder, }; /* Decoder switch */