Skip to content

Commit

Permalink
Tuning
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralim committed Oct 15, 2023
1 parent 280a532 commit ba19ad6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions source/Core/BSP/Pinecilv2/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@
#define NEEDS_VBUS_PROBE 0
#define CANT_DIRECT_READ_SETTINGS
#define TIP_CONTROL_PID // We use PID rather than integrator
#define TIP_PID_KP 4000
#define TIP_PID_KI 20
#define TIP_PID_KD 0
#define TIP_PID_KP 2000
#define TIP_PID_KI 3
#define TIP_PID_KD 200

#endif /* Pinecilv2 */

Expand Down
14 changes: 7 additions & 7 deletions source/Core/Threads/PIDThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void startPIDTask(void const *argument __unused) {
}

#ifdef TIP_CONTROL_PID
template <class T, T Kp, T Ki, T Kd> struct PID {
template <class T, T Kp, T Ki, T Kd, T integral_limit_scale> struct PID {
T previous_error_term;
T integration_running_sum;

Expand All @@ -101,13 +101,13 @@ template <class T, T Kp, T Ki, T Kd> struct PID {
const T kp_result = (Kp * target_delta) / 100;

// Integral term
integration_running_sum += (target_delta * interval_ms) / 1000;
integration_running_sum += ((target_delta * interval_ms) / 3000);

// We constrain integration_running_sum to limit windup
if (integration_running_sum > 2 * max_output) {
integration_running_sum = 2 * max_output;
} else if (integration_running_sum < -2 * max_output) {
integration_running_sum = -2 * max_output;
if (integration_running_sum > integral_limit_scale * max_output) {
integration_running_sum = integral_limit_scale * max_output;
} else if (integration_running_sum < -integral_limit_scale * max_output) {
integration_running_sum = -integral_limit_scale * max_output;
}
// Calculate the integral term, we use a shift 100 to get precision in integral as we often need small amounts
T ki_result = (Ki * integration_running_sum) / 100;
Expand Down Expand Up @@ -162,7 +162,7 @@ int32_t getPIDResultX10Watts(TemperatureType_t set_point, TemperatureType_t curr
static TickType_t lastCall = 0;

#ifdef TIP_CONTROL_PID
static PID<TemperatureType_t, TIP_PID_KP, TIP_PID_KI, TIP_PID_KD> pid = {0, 0};
static PID<TemperatureType_t, TIP_PID_KP, TIP_PID_KI, TIP_PID_KD, 5> pid = {0, 0};

const TickType_t interval = (xTaskGetTickCount() - lastCall);

Expand Down

0 comments on commit ba19ad6

Please sign in to comment.