ESPHome 2026.5.0b1
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
32 void set_autotuner_id(std::string id) { this->id_ = std::move(id); }
33
34 void set_noiseband(float noiseband) {
35 relay_function_.noiseband = noiseband;
36 // ZC detector uses 1/4 the noiseband of relay function (noise suppression)
37 frequency_detector_.noiseband = noiseband / 4;
38 }
39 void set_output_positive(float output_positive) { relay_function_.output_positive = output_positive; }
40 void set_output_negative(float output_negative) { relay_function_.output_negative = output_negative; }
41
42 protected:
97 PIDResult calculate_pid_(float kp_factor, float ki_factor, float kd_factor);
98 void print_rule_(const char *name, float kp_factor, float ki_factor, float kd_factor);
99 PIDResult get_ziegler_nichols_pid_() { return calculate_pid_(0.6f, 1.2f, 0.075f); }
100
102 float setpoint_ = NAN;
107 float ku_;
108 float pu_;
109 std::string id_;
110};
111
112} // 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)
PIDResult get_ziegler_nichols_pid_()
struct esphome::pid::PIDAutotuner::OscillationFrequencyDetector frequency_detector_
void set_autotuner_id(std::string 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