monitor pid change requests
All checks were successful
Build .deb on release / Build-Deb (push) Successful in 1m50s
All checks were successful
Build .deb on release / Build-Deb (push) Successful in 1m50s
This commit is contained in:
parent
13b892ca7e
commit
0f6091a615
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -2573,7 +2573,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tesla-charge-controller"
|
name = "tesla-charge-controller"
|
||||||
version = "1.0.19"
|
version = "1.0.20"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-channel",
|
"async-channel",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "tesla-charge-controller"
|
name = "tesla-charge-controller"
|
||||||
version = "1.0.19"
|
version = "1.0.20"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MITNFA"
|
license = "MITNFA"
|
||||||
description = "Controls Tesla charge rate based on solar charge data"
|
description = "Controls Tesla charge rate based on solar charge data"
|
||||||
|
|
|
@ -95,9 +95,34 @@ impl TeslaChargeRateController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
struct PidLoop {
|
struct PidLoop {
|
||||||
previous_error: f64,
|
previous_error: f64,
|
||||||
|
proportional_gauge: Gauge,
|
||||||
|
derivative_gauge: Gauge,
|
||||||
|
change_request_gauge: Gauge,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for PidLoop {
|
||||||
|
fn default() -> Self {
|
||||||
|
describe_gauge!(
|
||||||
|
"tcrc_proportional",
|
||||||
|
"Proportional component of requested change to charge rate"
|
||||||
|
);
|
||||||
|
let proportional_gauge = gauge!("tcrc_proportional");
|
||||||
|
describe_gauge!(
|
||||||
|
"tcrc_proportional",
|
||||||
|
"Derivative component of requested change to charge rate"
|
||||||
|
);
|
||||||
|
let derivative_gauge = gauge!("tcrc_derivative");
|
||||||
|
describe_gauge!("tcrc_change_request", "Requested change to charge rate");
|
||||||
|
let change_request_gauge = gauge!("tcrc_change_request");
|
||||||
|
Self {
|
||||||
|
previous_error: 0.,
|
||||||
|
proportional_gauge,
|
||||||
|
derivative_gauge,
|
||||||
|
change_request_gauge,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PidLoop {
|
impl PidLoop {
|
||||||
|
@ -111,16 +136,22 @@ impl PidLoop {
|
||||||
let derivative = (error - self.previous_error) / delta_time;
|
let derivative = (error - self.previous_error) / delta_time;
|
||||||
let config = access_config();
|
let config = access_config();
|
||||||
|
|
||||||
|
let proportional_component = config.pid_controls.proportional_gain * error;
|
||||||
|
let derivative_component = config.pid_controls.derivative_gain * derivative;
|
||||||
|
|
||||||
let extra_offsets = if pl_state.internal_load_current > 1. {
|
let extra_offsets = if pl_state.internal_load_current > 1. {
|
||||||
1.
|
1.
|
||||||
} else {
|
} else {
|
||||||
0.
|
0.
|
||||||
};
|
};
|
||||||
|
|
||||||
let new_target = ((config.pid_controls.proportional_gain * error)
|
let offset = proportional_component + derivative_component + extra_offsets;
|
||||||
+ (config.pid_controls.derivative_gain * derivative))
|
|
||||||
+ extra_offsets
|
self.proportional_gauge.set(proportional_component);
|
||||||
+ (charge_state.charge_amps as f64);
|
self.derivative_gauge.set(derivative_component);
|
||||||
|
self.change_request_gauge.set(offset);
|
||||||
|
|
||||||
|
let new_target = offset + (charge_state.charge_amps as f64);
|
||||||
|
|
||||||
self.previous_error = error;
|
self.previous_error = error;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue