2021-03-14 16:31:46 -07:00
|
|
|
/*
|
|
|
|
* @file vvt.h
|
|
|
|
*
|
|
|
|
* @date Jun 26, 2016
|
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "closed_loop_controller.h"
|
|
|
|
#include "pwm_generator_logic.h"
|
2022-01-31 18:51:32 -08:00
|
|
|
#include "efi_pid.h"
|
2023-07-03 10:25:48 -07:00
|
|
|
#include "vvt_generated.h"
|
2021-03-14 16:31:46 -07:00
|
|
|
|
|
|
|
class ValueProvider3D;
|
|
|
|
|
2022-09-27 19:21:18 -07:00
|
|
|
void initVvtActuators();
|
2021-03-14 16:31:46 -07:00
|
|
|
void startVvtControlPins();
|
|
|
|
void stopVvtControlPins();
|
2023-09-06 05:11:39 -07:00
|
|
|
OutputPin* getVvtOutputPin(int index);
|
2021-03-14 16:31:46 -07:00
|
|
|
|
2023-10-07 09:34:32 -07:00
|
|
|
#define BANK_BY_INDEX(index) (index / CAMS_PER_BANK)
|
|
|
|
#define CAM_BY_INDEX(index) (index % CAMS_PER_BANK)
|
2023-10-26 10:04:30 -07:00
|
|
|
#define INDEX_BY_BANK_CAM(bank, cam) ((bank) * CAMS_PER_BANK + (cam))
|
2023-10-07 09:34:32 -07:00
|
|
|
|
2023-07-19 22:16:29 -07:00
|
|
|
class VvtController : public EngineModule, public ClosedLoopController<angle_t, percent_t>, public vvt_s {
|
2021-03-14 16:31:46 -07:00
|
|
|
public:
|
2023-10-07 09:34:32 -07:00
|
|
|
VvtController(int index);
|
2021-03-14 16:31:46 -07:00
|
|
|
|
2023-07-19 22:16:29 -07:00
|
|
|
void init(const ValueProvider3D* targetMap, IPwm* pwm);
|
|
|
|
|
|
|
|
// EngineModule implementation
|
|
|
|
void onFastCallback() override;
|
2023-09-26 17:49:33 -07:00
|
|
|
void onConfigurationChange(engine_configuration_s const * previousConfig) override;
|
2021-03-14 16:31:46 -07:00
|
|
|
|
|
|
|
// ClosedLoopController implementation
|
2023-10-19 18:06:09 -07:00
|
|
|
expected<angle_t> observePlant() override;
|
2021-03-14 16:31:46 -07:00
|
|
|
|
2021-11-23 12:52:43 -08:00
|
|
|
expected<angle_t> getSetpoint() override;
|
|
|
|
expected<percent_t> getOpenLoop(angle_t target) override;
|
2021-03-14 16:31:46 -07:00
|
|
|
expected<percent_t> getClosedLoop(angle_t setpoint, angle_t observation) override;
|
|
|
|
void setOutput(expected<percent_t> outputValue) override;
|
|
|
|
|
2023-10-07 09:54:45 -07:00
|
|
|
uint8_t getCamIndex() {
|
|
|
|
return m_cam;
|
|
|
|
}
|
|
|
|
|
2021-03-14 16:31:46 -07:00
|
|
|
private:
|
2023-10-07 09:34:32 -07:00
|
|
|
const int index;
|
2023-07-19 22:16:29 -07:00
|
|
|
// Bank index, 0 or 1
|
2023-10-07 09:34:32 -07:00
|
|
|
const uint8_t m_bank;
|
2023-07-19 22:16:29 -07:00
|
|
|
// Cam index, 0 = intake, 1 = exhaust
|
2023-10-07 09:34:32 -07:00
|
|
|
const uint8_t m_cam;
|
2023-07-19 22:16:29 -07:00
|
|
|
|
2021-03-14 16:31:46 -07:00
|
|
|
Pid m_pid;
|
2023-07-19 22:16:29 -07:00
|
|
|
|
2021-03-14 16:31:46 -07:00
|
|
|
const ValueProvider3D* m_targetMap = nullptr;
|
2023-07-19 22:16:29 -07:00
|
|
|
IPwm* m_pwm = nullptr;
|
|
|
|
};
|
2021-03-14 16:31:46 -07:00
|
|
|
|
2023-07-19 22:16:29 -07:00
|
|
|
// Unique types for each VVT so they can be engine modules
|
|
|
|
struct VvtController1 : public VvtController {
|
2023-10-07 09:34:32 -07:00
|
|
|
VvtController1() : VvtController(0) { }
|
2023-07-19 22:16:29 -07:00
|
|
|
};
|
2021-03-25 04:39:23 -07:00
|
|
|
|
2023-07-19 22:16:29 -07:00
|
|
|
struct VvtController2 : public VvtController {
|
2023-10-07 09:34:32 -07:00
|
|
|
VvtController2() : VvtController(1) { }
|
2023-07-19 22:16:29 -07:00
|
|
|
};
|
2021-03-25 04:39:23 -07:00
|
|
|
|
2023-07-19 22:16:29 -07:00
|
|
|
struct VvtController3 : public VvtController {
|
2023-10-07 09:34:32 -07:00
|
|
|
VvtController3() : VvtController(2) { }
|
2023-07-19 22:16:29 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct VvtController4 : public VvtController {
|
2023-10-07 09:34:32 -07:00
|
|
|
VvtController4() : VvtController(3) { }
|
2021-03-14 16:31:46 -07:00
|
|
|
};
|