live data for wastegate #3588
i want to persist state so no 'const' sorry
This commit is contained in:
parent
ca1e420073
commit
c75291f415
|
@ -40,18 +40,20 @@ expected<float> BoostController::observePlant() const {
|
|||
return Sensor::get(SensorType::Map);
|
||||
}
|
||||
|
||||
expected<float> BoostController::getSetpoint() const {
|
||||
expected<float> BoostController::getSetpoint() {
|
||||
// If we're in open loop only mode, disregard any target computation.
|
||||
// Open loop needs to work even in case of invalid closed loop config
|
||||
if (engineConfiguration->boostType != CLOSED_LOOP) {
|
||||
return 0;
|
||||
closedLoopPart = 0;
|
||||
return closedLoopPart;
|
||||
}
|
||||
|
||||
float rpm = GET_RPM();
|
||||
|
||||
auto tps = Sensor::get(SensorType::DriverThrottleIntent);
|
||||
isTpsValid = tps.Valid;
|
||||
|
||||
if (!tps) {
|
||||
if (!isTpsValid) {
|
||||
return unexpected;
|
||||
}
|
||||
|
||||
|
@ -62,14 +64,16 @@ expected<float> BoostController::getSetpoint() const {
|
|||
return m_closedLoopTargetMap->getValue(rpm / RPM_1_BYTE_PACKING_MULT, tps.Value / TPS_1_BYTE_PACKING_MULT);
|
||||
}
|
||||
|
||||
expected<percent_t> BoostController::getOpenLoop(float target) const {
|
||||
expected<percent_t> BoostController::getOpenLoop(float target) {
|
||||
// Boost control open loop doesn't care about target - only TPS/RPM
|
||||
UNUSED(target);
|
||||
|
||||
float rpm = GET_RPM();
|
||||
auto tps = Sensor::get(SensorType::DriverThrottleIntent);
|
||||
|
||||
if (!tps) {
|
||||
isTpsValid = tps.Valid;
|
||||
|
||||
if (!isTpsValid) {
|
||||
return unexpected;
|
||||
}
|
||||
|
||||
|
@ -106,13 +110,16 @@ percent_t BoostController::getClosedLoopImpl(float target, float manifoldPressur
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (manifoldPressure < engineConfiguration->minimumBoostClosedLoopMap) {
|
||||
isBelowClosedLoopThreshold = manifoldPressure < engineConfiguration->minimumBoostClosedLoopMap;
|
||||
if (isBelowClosedLoopThreshold) {
|
||||
// We're below the CL threshold, inhibit CL for now
|
||||
m_pid.reset();
|
||||
return 0;
|
||||
closedLoopPart = 0;
|
||||
return closedLoopPart;
|
||||
}
|
||||
|
||||
return m_pid.getOutput(target, manifoldPressure, SLOW_CALLBACK_PERIOD_MS / 1000.0f);
|
||||
closedLoopPart = m_pid.getOutput(target, manifoldPressure, SLOW_CALLBACK_PERIOD_MS / 1000.0f);
|
||||
return closedLoopPart;
|
||||
}
|
||||
|
||||
expected<percent_t> BoostController::getClosedLoop(float target, float manifoldPressure) {
|
||||
|
|
|
@ -9,10 +9,11 @@
|
|||
#include "periodic_task.h"
|
||||
#include "closed_loop_controller.h"
|
||||
#include "pid.h"
|
||||
#include "boost_control_generated.h"
|
||||
|
||||
struct IPwm;
|
||||
|
||||
class BoostController : public ClosedLoopController<float, percent_t> {
|
||||
class BoostController : public boost_control_s, public ClosedLoopController<float, percent_t> {
|
||||
public:
|
||||
void init(IPwm* pmw, const ValueProvider3D* openLoopMap, const ValueProvider3D* closedLoopTargetMap, pid_s* pidParams);
|
||||
void update();
|
||||
|
@ -23,9 +24,9 @@ public:
|
|||
|
||||
// Helpers for individual parts of boost control
|
||||
expected<float> observePlant() const override;
|
||||
expected<float> getSetpoint() const override;
|
||||
expected<float> getSetpoint() override;
|
||||
|
||||
expected<percent_t> getOpenLoop(float target) const override;
|
||||
expected<percent_t> getOpenLoop(float target) override;
|
||||
expected<percent_t> getClosedLoop(float target, float manifoldPressure) override;
|
||||
|
||||
void setOutput(expected<percent_t> outputValue) override;
|
||||
|
@ -33,7 +34,6 @@ public:
|
|||
private:
|
||||
percent_t getClosedLoopImpl(float target, float manifoldPressure);
|
||||
|
||||
bool m_shouldResetPid = false;
|
||||
Pid m_pid;
|
||||
|
||||
const ValueProvider3D* m_openLoopMap = nullptr;
|
||||
|
|
|
@ -248,7 +248,7 @@ void EtbController::setWastegatePosition(percent_t pos) {
|
|||
m_wastegatePosition = pos;
|
||||
}
|
||||
|
||||
expected<percent_t> EtbController::getSetpoint() const {
|
||||
expected<percent_t> EtbController::getSetpoint() {
|
||||
switch (m_function) {
|
||||
case ETB_Throttle1:
|
||||
case ETB_Throttle2:
|
||||
|
@ -342,7 +342,7 @@ expected<percent_t> EtbController::getSetpointEtb() const {
|
|||
return clampF(1, targetPosition, maxPosition);
|
||||
}
|
||||
|
||||
expected<percent_t> EtbController::getOpenLoop(percent_t target) const {
|
||||
expected<percent_t> EtbController::getOpenLoop(percent_t target) {
|
||||
float ff = 0;
|
||||
|
||||
// Don't apply open loop for wastegate/idle valve, only real ETB
|
||||
|
|
|
@ -43,12 +43,12 @@ public:
|
|||
// Helpers for individual parts of throttle control
|
||||
expected<percent_t> observePlant() const override;
|
||||
|
||||
expected<percent_t> getSetpoint() const override;
|
||||
expected<percent_t> getSetpoint() override;
|
||||
expected<percent_t> getSetpointEtb() const;
|
||||
expected<percent_t> getSetpointWastegate() const;
|
||||
expected<percent_t> getSetpointIdleValve() const;
|
||||
|
||||
expected<percent_t> getOpenLoop(percent_t target) const override;
|
||||
expected<percent_t> getOpenLoop(percent_t target) override;
|
||||
expected<percent_t> getClosedLoop(percent_t setpoint, percent_t observation) override;
|
||||
expected<percent_t> getClosedLoopAutotune(percent_t setpoint, percent_t actualThrottlePosition);
|
||||
|
||||
|
|
|
@ -216,7 +216,7 @@ float IdleController::getRunningOpenLoop(float clt, SensorResult tps) const {
|
|||
return clampF(0, running, 100);
|
||||
}
|
||||
|
||||
float IdleController::getOpenLoop(Phase phase, float clt, SensorResult tps, float crankingTaperFraction) const {
|
||||
float IdleController::getOpenLoop(Phase phase, float clt, SensorResult tps, float crankingTaperFraction) {
|
||||
float cranking = getCrankingOpenLoop(clt);
|
||||
|
||||
// if we're cranking, nothing more to do.
|
||||
|
|
|
@ -26,7 +26,7 @@ struct IIdleController {
|
|||
virtual int getTargetRpm(float clt) const = 0;
|
||||
virtual float getCrankingOpenLoop(float clt) const = 0;
|
||||
virtual float getRunningOpenLoop(float clt, SensorResult tps) const = 0;
|
||||
virtual float getOpenLoop(Phase phase, float clt, SensorResult tps, float crankingTaperFraction) const = 0;
|
||||
virtual float getOpenLoop(Phase phase, float clt, SensorResult tps, float crankingTaperFraction) = 0;
|
||||
virtual float getClosedLoop(Phase phase, float tps, int rpm, int target) = 0;
|
||||
virtual float getCrankingTaperFraction() const = 0;
|
||||
};
|
||||
|
@ -49,7 +49,7 @@ public:
|
|||
// OPEN LOOP CORRECTIONS
|
||||
float getCrankingOpenLoop(float clt) const override;
|
||||
float getRunningOpenLoop(float clt, SensorResult tps) const override;
|
||||
float getOpenLoop(Phase phase, float clt, SensorResult tps, float crankingTaperFraction) const override;
|
||||
float getOpenLoop(Phase phase, float clt, SensorResult tps, float crankingTaperFraction) override;
|
||||
|
||||
float getIdleTimingAdjustment(int rpm);
|
||||
float getIdleTimingAdjustment(int rpm, int targetRpm, Phase phase);
|
||||
|
|
|
@ -49,7 +49,7 @@ expected<angle_t> VvtController::observePlant() const {
|
|||
return engine->triggerCentral.getVVTPosition(m_bank, m_cam);
|
||||
}
|
||||
|
||||
expected<angle_t> VvtController::getSetpoint() const {
|
||||
expected<angle_t> VvtController::getSetpoint() {
|
||||
int rpm = GET_RPM();
|
||||
float load = getFuelingLoad();
|
||||
float target = m_targetMap->getValue(rpm, load);
|
||||
|
@ -61,7 +61,7 @@ expected<angle_t> VvtController::getSetpoint() const {
|
|||
return target;
|
||||
}
|
||||
|
||||
expected<percent_t> VvtController::getOpenLoop(angle_t target) const {
|
||||
expected<percent_t> VvtController::getOpenLoop(angle_t target) {
|
||||
// TODO: could we do VVT open loop?
|
||||
UNUSED(target);
|
||||
return 0;
|
||||
|
|
|
@ -29,8 +29,8 @@ public:
|
|||
// ClosedLoopController implementation
|
||||
expected<angle_t> observePlant() const override;
|
||||
|
||||
expected<angle_t> getSetpoint() const override;
|
||||
expected<percent_t> getOpenLoop(angle_t target) const override;
|
||||
expected<angle_t> getSetpoint() override;
|
||||
expected<percent_t> getOpenLoop(angle_t target) override;
|
||||
expected<percent_t> getClosedLoop(angle_t setpoint, angle_t observation) override;
|
||||
void setOutput(expected<percent_t> outputValue) override;
|
||||
|
||||
|
|
|
@ -44,13 +44,13 @@ private:
|
|||
}
|
||||
|
||||
// Get the setpoint: where should the controller put the plant?
|
||||
virtual expected<TInput> getSetpoint() const = 0;
|
||||
virtual expected<TInput> getSetpoint() = 0;
|
||||
|
||||
// Get the current observation: what is the current state of the world?
|
||||
virtual expected<TInput> observePlant() const = 0;
|
||||
|
||||
// Get the open-loop output: output state based on only the setpoint
|
||||
virtual expected<TOutput> getOpenLoop(TInput setpoint) const = 0;
|
||||
virtual expected<TOutput> getOpenLoop(TInput setpoint) = 0;
|
||||
|
||||
// Get the closed-loop output: output state based on setpoint and observation
|
||||
virtual expected<TOutput> getClosedLoop(TInput setpoint, TInput observation) = 0;
|
||||
|
|
|
@ -26,9 +26,9 @@ public:
|
|||
MOCK_METHOD(const pid_state_s*, getPidState, (), (const, override));
|
||||
|
||||
// ClosedLoopController mocks
|
||||
MOCK_METHOD(expected<percent_t>, getSetpoint, (), (const, override));
|
||||
MOCK_METHOD(expected<percent_t>, getSetpoint, (), (override));
|
||||
MOCK_METHOD(expected<percent_t>, observePlant, (), (const, override));
|
||||
MOCK_METHOD(expected<percent_t>, getOpenLoop, (percent_t setpoint), (const, override));
|
||||
MOCK_METHOD(expected<percent_t>, getOpenLoop, (percent_t setpoint), (override));
|
||||
MOCK_METHOD(expected<percent_t>, getClosedLoop, (percent_t setpoint, percent_t observation), (override));
|
||||
MOCK_METHOD(void, setOutput, (expected<percent_t> outputValue), (override));
|
||||
};
|
||||
|
|
|
@ -354,7 +354,7 @@ TEST(idle_v2, closedLoopDeadzone) {
|
|||
struct IntegrationIdleMock : public IdleController {
|
||||
MOCK_METHOD(int, getTargetRpm, (float clt), (const, override));
|
||||
MOCK_METHOD(ICP, determinePhase, (int rpm, int targetRpm, SensorResult tps, float vss, float crankingTaperFraction), (const, override));
|
||||
MOCK_METHOD(float, getOpenLoop, (ICP phase, float clt, SensorResult tps, float crankingTaperFraction), (const, override));
|
||||
MOCK_METHOD(float, getOpenLoop, (ICP phase, float clt, SensorResult tps, float crankingTaperFraction), (override));
|
||||
MOCK_METHOD(float, getClosedLoop, (ICP phase, float tps, int rpm, int target), (override));
|
||||
MOCK_METHOD(float, getCrankingTaperFraction, (), (const, override));
|
||||
};
|
||||
|
|
|
@ -9,9 +9,9 @@ using ::testing::Eq;
|
|||
|
||||
class TestController : public ClosedLoopController<float, float> {
|
||||
public:
|
||||
MOCK_METHOD(expected<float>, getSetpoint, (), (const, override));
|
||||
MOCK_METHOD(expected<float>, getSetpoint, (), (override));
|
||||
MOCK_METHOD(expected<float>, observePlant, (), (const, override));
|
||||
MOCK_METHOD(expected<float>, getOpenLoop, (float setpoint), (const, override));
|
||||
MOCK_METHOD(expected<float>, getOpenLoop, (float setpoint), (override));
|
||||
MOCK_METHOD(expected<float>, getClosedLoop, (float setpoint, float observation), (override));
|
||||
MOCK_METHOD(void, setOutput, (expected<float> outputValue), (override));
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue