| Line | Branch | Decision | Exec | Source |
|---|---|---|---|---|
| 1 | /* | |||
| 2 | * @file vvt.h | |||
| 3 | * | |||
| 4 | * @date Jun 26, 2016 | |||
| 5 | * @author Andrey Belomutskiy, (c) 2012-2020 | |||
| 6 | */ | |||
| 7 | ||||
| 8 | #pragma once | |||
| 9 | ||||
| 10 | #include "closed_loop_controller.h" | |||
| 11 | #include "pwm_generator_logic.h" | |||
| 12 | #include "efi_pid.h" | |||
| 13 | #include "vvt_generated.h" | |||
| 14 | ||||
| 15 | class ValueProvider3D; | |||
| 16 | ||||
| 17 | void initVvtActuators(); | |||
| 18 | void startVvtControlPins(); | |||
| 19 | void stopVvtControlPins(); | |||
| 20 | OutputPin* getVvtOutputPin(int index); | |||
| 21 | ||||
| 22 | #define BANK_BY_INDEX(index) (index / CAMS_PER_BANK) | |||
| 23 | #define CAM_BY_INDEX(index) (index % CAMS_PER_BANK) | |||
| 24 | #define INDEX_BY_BANK_CAM(bank, cam) ((bank) * CAMS_PER_BANK + (cam)) | |||
| 25 | ||||
| 26 | class VvtController : public EngineModule, public ClosedLoopController<angle_t, percent_t>, public vvt_s { | |||
| 27 | public: | |||
| 28 | VvtController(int index); | |||
| 29 | ||||
| 30 | void init(const ValueProvider3D* targetMap, IPwm* pwm); | |||
| 31 | ||||
| 32 | // EngineModule implementation | |||
| 33 | void onFastCallback() override; | |||
| 34 | void onConfigurationChange(engine_configuration_s const * previousConfig) override; | |||
| 35 | ||||
| 36 | // ClosedLoopController implementation | |||
| 37 | expected<angle_t> observePlant() override; | |||
| 38 | ||||
| 39 | expected<angle_t> getSetpoint() override; | |||
| 40 | expected<percent_t> getOpenLoop(angle_t target) override; | |||
| 41 | expected<percent_t> getClosedLoop(angle_t setpoint, angle_t observation) override; | |||
| 42 | void setOutput(expected<percent_t> outputValue) override; | |||
| 43 | ||||
| 44 | 2 | uint8_t getCamIndex() { | ||
| 45 | 2 | return m_cam; | ||
| 46 | } | |||
| 47 | ||||
| 48 | private: | |||
| 49 | const int index; | |||
| 50 | // Bank index, 0 or 1 | |||
| 51 | const uint8_t m_bank; | |||
| 52 | // Cam index, 0 = intake, 1 = exhaust | |||
| 53 | const uint8_t m_cam; | |||
| 54 | ||||
| 55 | Pid m_pid; | |||
| 56 | ||||
| 57 | // todo: live data? | |||
| 58 | bool m_engineRunningLongEnough = false; | |||
| 59 | bool m_isRpmHighEnough = false; | |||
| 60 | bool m_isCltWarmEnough = false; | |||
| 61 | ||||
| 62 | const ValueProvider3D* m_targetMap = nullptr; | |||
| 63 | IPwm* m_pwm = nullptr; | |||
| 64 | }; | |||
| 65 | ||||
| 66 | // Unique types for each VVT so they can be engine modules | |||
| 67 | struct VvtController1 : public VvtController { | |||
| 68 | VvtController1() : VvtController(0) { } | |||
| 69 | }; | |||
| 70 | ||||
| 71 | struct VvtController2 : public VvtController { | |||
| 72 | VvtController2() : VvtController(1) { } | |||
| 73 | }; | |||
| 74 | ||||
| 75 | struct VvtController3 : public VvtController { | |||
| 76 | VvtController3() : VvtController(2) { } | |||
| 77 | }; | |||
| 78 | ||||
| 79 | struct VvtController4 : public VvtController { | |||
| 80 | VvtController4() : VvtController(3) { } | |||
| 81 | }; | |||
| 82 |