ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
pid_autotuner.h
Go to the documentation of this file.
1#pragma once
2
5#include "pid_controller.h"
6
7#include <vector>
8
9namespace esphome::pid {
10
12 public:
13 struct PIDResult {
14 float kp;
15 float ki;
16 float kd;
17 };
19 float output;
20 optional<PIDResult> result_params;
21 };
22
23 void config(float output_min, float output_max) {
26 }
27 PIDAutotuneResult update(float setpoint, float process_variable);
28 bool is_finished() const { return state_ != AUTOTUNE_RUNNING; }
29
30 void dump_config();
31
33 void set_autotuner_id(const LogString *id) { this->id_ = id; }
34
35 void set_noiseband(float noiseband) {
36 relay_function_.noiseband = noiseband;
37 // ZC detector uses 1/4 the noiseband of relay function (noise suppression)
38 frequency_detector_.noiseband = noiseband / 4;
39 }
40 void set_output_positive(float output_positive) { relay_function_.output_positive = output_positive; }
41 void set_output_negative(float output_negative) { relay_function_.output_negative = output_negative; }
42
43 protected:
98 PIDResult calculate_pid_(float kp_factor, float ki_factor, float kd_factor);
99 void print_rule_(const char *name, float kp_factor, float ki_factor, float kd_factor);
100 PIDResult get_ziegler_nichols_pid_() { return calculate_pid_(0.6f, 1.2f, 0.075f); }
101
103 float setpoint_ = NAN;
108 float ku_;
109 float pu_;
110 const LogString *id_{reinterpret_cast<const LogString *>("")}; // empty until set, like the old std::string
111};
112
113} // namespace esphome::pid
struct esphome::pid::PIDAutotuner::OscillationAmplitudeDetector amplitude_detector_
enum esphome::pid::PIDAutotuner::State state_
void config(float output_min, float output_max)
void set_output_positive(float output_positive)
void set_noiseband(float noiseband)
struct esphome::pid::PIDAutotuner::RelayFunction relay_function_
PIDResult calculate_pid_(float kp_factor, float ki_factor, float kd_factor)
void print_rule_(const char *name, float kp_factor, float ki_factor, float kd_factor)
void set_output_negative(float output_negative)
void set_autotuner_id(const LogString *id)
Name shown in log lines; must outlive the autotuner.
struct esphome::pid::PIDAutotuner::OscillationFrequencyDetector frequency_detector_
uint16_t id
static void uint32_t
void update(float error, RelayFunction::RelayFunctionState relay_state)
enum esphome::pid::PIDAutotuner::OscillationFrequencyDetector::FrequencyDetectorState state
enum esphome::pid::PIDAutotuner::RelayFunction::RelayFunctionState state