2020-01-31 11:29:52 -08:00
|
|
|
/*
|
|
|
|
* boost_control.h
|
|
|
|
*
|
|
|
|
* Created on: 18. aug. 2019
|
|
|
|
* Author: Ola Ruud
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "periodic_task.h"
|
2020-05-06 05:40:42 -07:00
|
|
|
#include "closed_loop_controller.h"
|
|
|
|
#include "pid.h"
|
2020-01-31 11:29:52 -08:00
|
|
|
|
2021-07-06 18:44:59 -07:00
|
|
|
struct IPwm;
|
2020-05-06 05:40:42 -07:00
|
|
|
|
2021-11-15 03:44:40 -08:00
|
|
|
class BoostController : public ClosedLoopController<float, percent_t>, public EnginePtr {
|
2020-05-06 05:40:42 -07:00
|
|
|
public:
|
2021-07-01 06:21:18 -07:00
|
|
|
void init(IPwm* pmw, const ValueProvider3D* openLoopMap, const ValueProvider3D* closedLoopTargetMap, pid_s* pidParams);
|
2021-01-18 04:04:14 -08:00
|
|
|
void update();
|
2020-05-06 05:40:42 -07:00
|
|
|
|
|
|
|
// Called when the configuration may have changed. Controller will
|
|
|
|
// reset if necessary.
|
|
|
|
void onConfigurationChange(pid_s* previousConfiguration);
|
|
|
|
|
|
|
|
// Helpers for individual parts of boost control
|
|
|
|
expected<float> observePlant() const override;
|
|
|
|
expected<float> getSetpoint() const override;
|
|
|
|
|
|
|
|
expected<percent_t> getOpenLoop(float target) const override;
|
|
|
|
expected<percent_t> getClosedLoop(float target, float manifoldPressure) override;
|
|
|
|
|
|
|
|
void setOutput(expected<percent_t> outputValue) override;
|
|
|
|
|
|
|
|
private:
|
2021-09-07 11:07:47 -07:00
|
|
|
percent_t getClosedLoopImpl(float target, float manifoldPressure);
|
|
|
|
|
2020-05-06 05:40:42 -07:00
|
|
|
bool m_shouldResetPid = false;
|
|
|
|
Pid m_pid;
|
|
|
|
|
|
|
|
const ValueProvider3D* m_openLoopMap = nullptr;
|
|
|
|
const ValueProvider3D* m_closedLoopTargetMap = nullptr;
|
2021-07-01 06:21:18 -07:00
|
|
|
IPwm* m_pwm = nullptr;
|
2020-05-06 05:40:42 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
void startBoostPin();
|
2021-04-21 11:28:48 -07:00
|
|
|
void initBoostCtrl(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
2020-01-31 11:29:52 -08:00
|
|
|
void setDefaultBoostParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
|
|
|
void onConfigurationChangeBoostCallback(engine_configuration_s *previousConfiguration);
|
2021-01-18 04:04:14 -08:00
|
|
|
|
|
|
|
void updateBoostControl();
|