rusefi-1/firmware/controllers/math/pid.h

58 lines
1.3 KiB
C
Raw Normal View History

2015-07-10 06:01:56 -07:00
/**
* @file pid.h
*
* @date Sep 16, 2014
2017-01-03 03:05:22 -08:00
* @author Andrey Belomutskiy, (c) 2012-2017
2015-07-10 06:01:56 -07:00
*/
#ifndef PID_H_
#define PID_H_
2016-02-06 09:02:24 -08:00
#include "global.h"
2016-01-20 20:03:03 -08:00
#include "engine_configuration_generated_structures.h"
2017-05-25 05:49:04 -07:00
#include "datalogging.h"
2016-02-06 09:02:24 -08:00
#if EFI_PROD_CODE || EFI_SIMULATOR
#include "tunerstudio_configuration.h"
#endif
2016-01-20 20:03:03 -08:00
2015-07-10 06:01:56 -07:00
class Pid {
public:
2016-02-06 09:02:24 -08:00
Pid();
2016-01-20 20:03:03 -08:00
Pid(pid_s *pid, float minResult, float maxResult);
2016-02-06 09:02:24 -08:00
void init(pid_s *pid, float minResult, float maxResult);
2016-09-15 20:01:48 -07:00
bool isSame(pid_s *pid);
2016-02-06 09:02:24 -08:00
2017-01-22 14:03:31 -08:00
float getValue(float target, float input);
2017-05-25 05:49:04 -07:00
// todo: dTime should be taken from pid_s
2015-07-10 06:01:56 -07:00
float getValue(float target, float input, float dTime);
void updateFactors(float pFactor, float iFactor, float dFactor);
void reset(void);
float getP(void);
float getI(void);
float getD(void);
2016-02-06 09:02:24 -08:00
float getOffset(void);
2016-01-24 13:01:28 -08:00
float getIntegration(void);
float getPrevError(void);
2016-02-06 09:02:24 -08:00
#if EFI_PROD_CODE || EFI_SIMULATOR
void postState(TunerStudioOutputChannels *tsOutputChannels);
#endif
2015-07-10 06:01:56 -07:00
float minResult;
float maxResult;
2017-05-22 19:32:08 -07:00
float iTerm;
float dTerm; // we are remembering this only for debugging purposes
2017-05-25 05:49:04 -07:00
void showPidStatus(Logging *logging, const char*msg, int dTime);
2017-05-28 19:10:35 -07:00
void sleep();
2017-04-10 12:16:00 -07:00
private:
pid_s *pid;
2015-07-10 06:01:56 -07:00
float prevError;
2017-05-25 05:56:36 -07:00
// these are only used for logging
float prevTarget;
float prevInput;
float prevResult;
2015-07-10 06:01:56 -07:00
};
#endif /* PID_H_ */