mirror of
https://github.com/avem-labs/Avem.git
synced 2023-09-01 15:18:49 +08:00
[Fixed]: PWM限幅
This commit is contained in:
parent
1ffe818e33
commit
b509cfb3e9
@ -29,6 +29,7 @@ typedef struct {
|
||||
float d;
|
||||
short output;
|
||||
__IO uint16_t *Channel1;
|
||||
__IO uint16_t *Channel2;
|
||||
} pid_st, *pid_pst;
|
||||
|
||||
void pid_SingleAxis(pid_pst package, float setPoint);
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define TTY_H
|
||||
|
||||
#define TTY_NONE() uart_sendStr("\033[m")
|
||||
#define TTY_RED() uart_sendStr("\033[0;32;31m")
|
||||
#define TTY_RED() uart_sendStr("\033[41;30m")
|
||||
#define TTY_LIGHT_RED() uart_sendStr("\033[1;31m")
|
||||
#define TTY_GREEN() uart_sendStr("\033[0;32;32m")
|
||||
#define TTY_LIGHT_GREEN() uart_sendStr("\033[1;32m")
|
||||
|
@ -19,10 +19,14 @@ void pid_SingleAxis(pid_pst temp, float setPoint) {
|
||||
temp->output = 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;
|
||||
temp->InnerLast = *temp->Gyro;
|
||||
else if (*temp->Channel1+temp->output < MOTOR_LOW) *temp->Channel1 = MOTOR_LOW;
|
||||
else *temp->Channel1 += (short)temp->output;
|
||||
|
||||
*temp->Channel1 += (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 -= (short)temp->output;
|
||||
|
||||
temp->InnerLast = *temp->Gyro;
|
||||
}
|
||||
|
||||
// float g_iErro, g_sumErro = 0;
|
||||
|
@ -94,7 +94,8 @@ int main() {
|
||||
.OutterLast = 0,
|
||||
.Feedback = &g_Roll,
|
||||
.i = 0,
|
||||
.Channel1 = &MOTOR1,
|
||||
.Channel1 = &MOTOR2,
|
||||
.Channel2 = &MOTOR4,
|
||||
.Gyro = &sourceData.gX,
|
||||
};
|
||||
|
||||
@ -133,11 +134,14 @@ int main() {
|
||||
|
||||
pid_SingleAxis(&g_pid_roll, 0);
|
||||
TTY_CLEAR();
|
||||
|
||||
TTY_RED();
|
||||
uart_sendStr(" Motor占空比: ");
|
||||
TTY_NONE();
|
||||
TTY_BLUE();
|
||||
uart_showData(MOTOR1);
|
||||
uart_showData(*g_pid_roll.Channel1);
|
||||
uart_sendStr("\t");
|
||||
uart_showData(*g_pid_roll.Channel2);
|
||||
TTY_NONE();
|
||||
|
||||
uart_sendStr("\n\rRoll:\t");
|
||||
|
Loading…
x
Reference in New Issue
Block a user