You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
toaster-oven-bluepill/Core/Src/app_pid.h

55 lines
1.2 KiB

/**
* adapted from the Arduino PID library
*
* Created on 2020/01/08.
*/
#ifndef ARDUINOPID_H
#define ARDUINOPID_H
#include <stdint.h>
enum PIDCtlMode {
PID_MANUAL = 0,
PID_AUTOMATIC = 1,
};
enum PIDDirection {
PID_DIRECT = 0,
PID_REVERSE = 1,
};
struct PID {
/*working variables*/
uint32_t lastTime;
float Input, Output, Setpoint;
float ITerm, lastInput;
float kp, ki, kd;
uint32_t SampleTimeTicks;
float outMin, outMax;
float iTermMin, iTermMax;
enum PIDCtlMode ctlMode; // false
enum PIDDirection controllerDirection;
};
#define PID_DEFAULT() { .SampleTimeMs = 1000, .ctlMode=PID_MANUAL, .controllerDirection=PID_DIRECT }
void PID_Compute(struct PID *self, float input);
void PID_SetTunings(struct PID *self, float Kp, float Ki, float Kd);
void PID_SetSampleTime(struct PID *self, uint32_t new_sample_time);
void PID_SetOutputLimits(struct PID *self, float min, float max);
void PID_SetITermLimits(struct PID *self, float min, float max);
void PID_SetCtlMode(struct PID *self, enum PIDCtlMode mode);
void PID_Initialize(struct PID *self);
void PID_SetSetpoint(struct PID *self, float setpoint);
void PID_SetControllerDirection(struct PID *self, enum PIDDirection direction);
#endif //ARDUINOPID_H