File tree Expand file tree Collapse file tree 3 files changed +16
-9
lines changed
Expand file tree Collapse file tree 3 files changed +16
-9
lines changed Original file line number Diff line number Diff line change 1313static uint16_t lastTicks_RPM [MOTORS_COUNT ];
1414static uint16_t lastTicks_ROS [MOTORS_COUNT ];
1515
16- static uint16_t encoder_period_ms = 20 ;
16+ static uint16_t encoder_period_ms = 5 ;
1717static float encoder_ticks_per_rev = 820.0f ;
1818
1919static osTimerId_t encoderTimerHandle ;
@@ -46,7 +46,7 @@ void ulEncoder_Init(void) {
4646 drvEncoder_Init ();
4747
4848 if (!ulDatabase_getUint16 (ENCODER_CONTROL_PERIOD_MS , & encoder_period_ms ) || encoder_period_ms == 0 ) {
49- encoder_period_ms = 20 ;
49+ encoder_period_ms = 5 ;
5050 }
5151
5252 if (!ulDatabase_getFloat (ENCODER_TICKS_PER_REVOLUTION , & encoder_ticks_per_rev ) || encoder_ticks_per_rev < 1.0f ) {
Original file line number Diff line number Diff line change 22#include <math.h>
33#include <stdbool.h>
44
5+ /**
6+ * @file ulGD.c
7+ * @brief Online Gradient Descent (GD) Auto-tuner for PID Controllers.
8+ *
9+ * This module implements an adaptive learning algorithm based on the MIT Rule / Gradient Descent.
10+ * It automatically adjusts PID gains (Kp, Ki) in real-time to minimize error.
11+ */
12+
513void ulGD_Init (ulGD_t * gd )
614{
715 /* Tuning Speed */
8- gd -> alpha_p = 0.005f ; // Kp learning rate
9- gd -> alpha_i = 0.0005f ; // Ki learning rate
16+ gd -> alpha_p = 0.001f ; // Kp learning rate
17+ gd -> alpha_i = 0.0001f ; // Ki learning rate
1018
1119 /* Safety Limits */
1220 gd -> kp_min = 0.040f ;
Original file line number Diff line number Diff line change 1010
1111static osTimerId_t motors_timer_handle ;
1212
13- #define MOTORS_CONTROL_PERIOD_MS 20
13+ #define MOTORS_CONTROL_PERIOD_MS 5
1414
1515const float dt_sec = MOTORS_CONTROL_PERIOD_MS / 1000.0f ;
1616
@@ -129,10 +129,9 @@ void ulMotorsController_Init(ulMotorsController_t* ctrl)
129129
130130 ulPID_Init (& ctrl -> pids [i ], kp , ki , kd );
131131
132- ctrl -> pids [i ].deadzone = 0.02f ;
132+ ctrl -> pids [i ].deadzone = 0.05f ;
133133 ctrl -> pids [i ].slew_rate = 25.0f ;
134- ctrl -> pids [i ].d_alpha = 0.2f ;
135- ctrl -> pids [i ].sp_alpha = 0.1f ;
134+ ctrl -> pids [i ].d_alpha = 0.05f ;
136135
137136 ulGD_Init (& ctrl -> gd [i ]);
138137
@@ -348,6 +347,6 @@ void ulMotorsController_Task(void* argument)
348347
349348 ulMotorsController_UpdateFromDB (& g_motors_ctrl );
350349
351- osDelay (10 );
350+ osDelay (20 );
352351 }
353352}
You can’t perform that action at this time.
0 commit comments