[Fixed] 计算输出时没有将float转为short, 虽然编译没有报错

This commit is contained in:
but0n 2016-10-10 18:58:19 +08:00
parent 405a77a78a
commit be3721abc2

14
pid.md
View File

@ -77,15 +77,15 @@ void pid_SingleAxis(pid_pst temp, float setPoint) {
//Inner Loop PD
temp->p = temp->output + *temp->Gyro * 3.5f;
temp->d = *temp->Gyro - temp->InnerLast;
temp->output = INNER_LOOP_KP * temp->p + INNER_LOOP_KD * temp->d;
temp->output = (short)INNER_LOOP_KP * temp->p + INNER_LOOP_KD * temp->d;
if (*temp->Channel1+temp->output > MOTOR_MAX) *temp->Channel1 = MOTOR_MAX;
else if (*temp->Channel1+temp->output < MOTOR_LOW) *temp->Channel1 = MOTOR_LOW;
else *temp->Channel1 += (short)temp->output;
if (*temp->Channel1 + temp->output > MOTOR_MAX) *temp->Channel1 = MOTOR_MAX;
else if (*temp->Channel1 + temp->output < MOTOR_LOW) *temp->Channel1 = MOTOR_LOW;
else *temp->Channel1 += temp->output;
if (*temp->Channel2-temp->output > MOTOR_MAX) *temp->Channel2 = MOTOR_MAX;
else if (*temp->Channel2-temp->output < MOTOR_LOW) *temp->Channel2 = MOTOR_LOW;
else *temp->Channel2 -= (short)temp->output;
if (*temp->Channel2 - temp->output > MOTOR_MAX) *temp->Channel2 = MOTOR_MAX;
else if (*temp->Channel2 - temp->output < MOTOR_LOW) *temp->Channel2 = MOTOR_LOW;
else *temp->Channel2 -= temp->output;
temp->InnerLast = *temp->Gyro;
}