Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
g122622 committed Apr 27, 2024
1 parent c07ac3d commit 3f12f4a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions main/FlightController/controllerTick.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created Date: 2024-03-29 22:57:12
* Author: Guoyi
* -----
* Last Modified: 2024-04-07 22:27:48
* Last Modified: 2024-04-27 17:31:24
* Modified By: Guoyi
* -----
* Copyright (c) 2024 Guoyi Inc.
Expand All @@ -25,7 +25,7 @@

uint32_t tickCount = 0;

void controllerTick()
void controllerTick(int dt)
{
/* 从全局变量读取用户指令 */

Expand All @@ -48,19 +48,19 @@ void controllerTick()
float gyroErr = -GyroData.z;

/* 执行PID算法 */
float gyroPID = performPID(&gyroPIDConfig, gyroErr, 5);
float rollPID = performPID(&rollPIDConfig, rollErr, 5);
float pitchPID = performPID(&pitchPIDConfig, pitchErr, 5);
float gyroPID = performPID(&gyroPIDConfig, gyroErr, dt);
float rollPID = performPID(&rollPIDConfig, rollErr, dt);
float pitchPID = performPID(&pitchPIDConfig, pitchErr, dt);

/* 将PID输出值转为电机PWM百分比 */
float mult = 0.5;
float basic = 70;
if ((tickCount % 100) == 0)
{
printf("m%d, PWM: %f \t", 1, mult * (-rollPID + pitchPID) + basic);
printf("m%d, PWM: %f \t", 2, mult * (-rollPID - pitchPID) + basic);
printf("m%d, PWM: %f \t", 3, mult * (+rollPID - pitchPID) + basic);
printf("m%d, PWM: %f \n", 4, mult * (+rollPID + pitchPID) + basic);
// printf("m%d, PWM: %f \t", 1, mult * (-rollPID + pitchPID) + basic);
// printf("m%d, PWM: %f \t", 2, mult * (-rollPID - pitchPID) + basic);
// printf("m%d, PWM: %f \t", 3, mult * (+rollPID - pitchPID) + basic);
// printf("m%d, PWM: %f \n", 4, mult * (+rollPID + pitchPID) + basic);
}
// if (tickCount == 600)
// {
Expand Down
6 changes: 3 additions & 3 deletions main/tasks/controllerTickLoop.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created Date: 2024-03-11 13:27:21
* Author: Guoyi
* -----
* Last Modified: 2024-04-24 17:36:38
* Last Modified: 2024-04-27 17:06:58
* Modified By: Guoyi
* -----
* Copyright (c) 2024 Guoyi Inc.
Expand All @@ -27,8 +27,8 @@ void controllerTickLoop(void *argument)
vTaskDelay(200 / portTICK_PERIOD_MS);
while (1)
{
vTaskDelay(5 / portTICK_PERIOD_MS);
controllerTick();
vTaskDelay(10 / portTICK_PERIOD_MS);
controllerTick(10);
}
}

Expand Down

0 comments on commit 3f12f4a

Please sign in to comment.