Skip to content
Snippets Groups Projects
Commit eefa1ae8 authored by C-Glick's avatar C-Glick
Browse files

Merge attitude_rate_control into master,

close !73
parent a36b1666
No related branches found
No related tags found
No related merge requests found
...@@ -93,6 +93,11 @@ void attitudeControllerResetRollAttitudePID(void); ...@@ -93,6 +93,11 @@ void attitudeControllerResetRollAttitudePID(void);
*/ */
void attitudeControllerResetPitchAttitudePID(void); void attitudeControllerResetPitchAttitudePID(void);
/**
* Reset controller yaw attitude PID
*/
void attitudeControllerResetYawAttitudePID(void);
/** /**
* Reset controller roll, pitch and yaw PID's. * Reset controller roll, pitch and yaw PID's.
*/ */
......
...@@ -54,7 +54,7 @@ bool controllerStudentTest(void) ...@@ -54,7 +54,7 @@ bool controllerStudentTest(void)
* @return float * @return float
*/ */
static float capAngle(float angle) { static float capAngle(float angle) {
//TODO MICROCART: Student written //TODO MICROCART: remove
float result = angle; float result = angle;
...@@ -102,19 +102,10 @@ void controllerStudent(control_t *control, setpoint_t *setpoint, const sensorDat ...@@ -102,19 +102,10 @@ void controllerStudent(control_t *control, setpoint_t *setpoint, const sensorDat
return; return;
} }
// update desired yaw from setpoint //set desired roll and pitch and yaw angles
// Rate-controlled YAW is moving YAW angle setpoint
if (setpoint->mode.yaw == modeVelocity) {
attitudeDesired.yaw += setpoint->attitudeRate.yaw * STUDENT_UPDATE_DT;
// absolute controlled yaw
} else {
attitudeDesired.yaw = setpoint->attitude.yaw;
}
attitudeDesired.yaw = capAngle(attitudeDesired.yaw);
//set desired roll and pitch
attitudeDesired.roll = setpoint->attitude.roll; attitudeDesired.roll = setpoint->attitude.roll;
attitudeDesired.pitch = setpoint->attitude.pitch; attitudeDesired.pitch = setpoint->attitude.pitch;
attitudeDesired.yaw = setpoint->attitude.yaw;
//set desired thrust //set desired thrust
thrustDesired = setpoint->thrust; thrustDesired = setpoint->thrust;
...@@ -138,6 +129,10 @@ void controllerStudent(control_t *control, setpoint_t *setpoint, const sensorDat ...@@ -138,6 +129,10 @@ void controllerStudent(control_t *control, setpoint_t *setpoint, const sensorDat
rateDesired.pitch = setpoint->attitudeRate.pitch; rateDesired.pitch = setpoint->attitudeRate.pitch;
attitudeControllerResetPitchAttitudePID(); attitudeControllerResetPitchAttitudePID();
} }
if(setpoint->mode.yaw == modeVelocity) {
rateDesired.yaw = setpoint->attitudeRate.yaw;
attitudeControllerResetYawAttitudePID();
}
//update the attitude rate PID, given the current angular rate //update the attitude rate PID, given the current angular rate
//read by the gyro and the desired rate //read by the gyro and the desired rate
......
...@@ -71,6 +71,8 @@ enum packet_type { ...@@ -71,6 +71,8 @@ enum packet_type {
hoverType = 5, hoverType = 5,
fullStateType = 6, fullStateType = 6,
positionType = 7, positionType = 7,
attitudeRateType = 8,
}; };
/* ---===== 2 - Decoding functions =====--- */ /* ---===== 2 - Decoding functions =====--- */
...@@ -367,6 +369,37 @@ static void positionDecoder(setpoint_t *setpoint, uint8_t type, const void *data ...@@ -367,6 +369,37 @@ static void positionDecoder(setpoint_t *setpoint, uint8_t type, const void *data
setpoint->attitude.yaw = values->yaw; 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 =====--- */ /* ---===== 3 - packetDecoders array =====--- */
const static packetDecoder_t packetDecoders[] = { const static packetDecoder_t packetDecoders[] = {
[stopType] = stopDecoder, [stopType] = stopDecoder,
...@@ -377,6 +410,7 @@ const static packetDecoder_t packetDecoders[] = { ...@@ -377,6 +410,7 @@ const static packetDecoder_t packetDecoders[] = {
[hoverType] = hoverDecoder, [hoverType] = hoverDecoder,
[fullStateType] = fullStateDecoder, [fullStateType] = fullStateDecoder,
[positionType] = positionDecoder, [positionType] = positionDecoder,
[attitudeRateType] = attitudeRateDecoder,
}; };
/* Decoder switch */ /* Decoder switch */
......
...@@ -157,6 +157,11 @@ void attitudeControllerResetRollAttitudePID(void) ...@@ -157,6 +157,11 @@ void attitudeControllerResetRollAttitudePID(void)
pidReset(&pidRoll); pidReset(&pidRoll);
} }
void attitudeControllerResetYawAttitudePID(void)
{
pidReset(&pidYaw);
}
void attitudeControllerResetPitchAttitudePID(void) void attitudeControllerResetPitchAttitudePID(void)
{ {
pidReset(&pidPitch); pidReset(&pidPitch);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment