Skip to content

Commit

Permalink
Cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralim committed Oct 15, 2023
1 parent 9052820 commit 48fabbd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
14 changes: 7 additions & 7 deletions source/Core/BSP/Pinecilv2/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@
#define DEBUG_UART_OUTPUT
#define HAS_POWER_DEBUG_MENU
#define HARDWARE_MAX_WATTAGE_X10 750
#define BLE_ENABLED // We have a BLE stack
#define NEEDS_VBUS_PROBE 0 // No vbus probe, its not connected in pcb
#define CANT_DIRECT_READ_SETTINGS // We cant memcpy settings due to flash cache
#define TIP_CONTROL_PID // We use PID rather than integrator
#define TIP_PID_KP 3000
#define TIP_PID_KI 5
#define TIP_PID_KD 300
#define BLE_ENABLED // We have a BLE stack
#define NEEDS_VBUS_PROBE 0 // No vbus probe, its not connected in pcb
#define CANT_DIRECT_READ_SETTINGS // We cant memcpy settings due to flash cache
#define TIP_CONTROL_PID // We use PID rather than integrator
#define TIP_PID_KP 45 // Reasonable compromise for most tips so far
#define TIP_PID_KI 9 // About as high for stability across tips
#define TIP_PID_KD 200 // Helps dampen smaller tips; ~= nothing for larger tips

#endif /* Pinecilv2 */

Expand Down
12 changes: 8 additions & 4 deletions source/Core/Threads/PIDThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,23 @@ template <class T, T Kp, T Ki, T Kd, T integral_limit_scale> struct PID {
const T target_delta = set_point - new_reading;

// Proportional term
const T kp_result = (Kp * target_delta) / 100;
const T kp_result = Kp * target_delta;

// Integral term
integration_running_sum += ((target_delta * interval_ms) / 3000);
// Integral term as we use mixed sampling rates, we cant assume a constant sample interval
// Thus we multiply this out by the interval time to ~= dv/dt
// Then the shift by 1000 is ms -> Seconds

integration_running_sum += (target_delta * interval_ms * Ki) / 1000;

// We constrain integration_running_sum to limit windup
// This is not overly required for most use cases but can prevent large overshoot in constrained implementations
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;
T ki_result = integration_running_sum / 100;

// Derivative term
T derivative = (target_delta - previous_error_term);
Expand Down

7 comments on commit 48fabbd

@goga1978
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi)

much better than the last release!

@goga1978
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

document_5287587366851066437.mp4

@Ralim
Copy link
Owner Author

@Ralim Ralim commented on 48fabbd Oct 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, its been poked on and off for a while but also had life get in the way a bit.
Trying to get back and stop chasing the old code and just go all the way back to the old faithful (PID).
If you have suggestions / notes post them in the PR so they are easier to find ^_^

@goga1978
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR - what is it?

@goga1978
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more accurate readings can be obtained if the temperature is measured to tenths of a degree. say 250.1 s

@goga1978
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

document_5287587366851066479stm.mp4

@Ralim
Copy link
Owner Author

@Ralim Ralim commented on 48fabbd Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR - what is it?

PR is Pull Request.
Comments on commits are lost easily and not able to be replied to by mobile.
Discussion around code should be done on the associated Pull Request.
If there is not one yet; then the code isn't generally ready for review.

more accurate readings can be obtained if the temperature is measured to tenths of a degree. say 250.1 s

Of course this is true, but that is very out of scope for this pull request. That should be filed as an issue for 2.23 or 2.24

I do not know what that video is for?

Please sign in to comment.