Etb wastegate hookup (#1888)
* remove * cleanup * implement ETB parts * hook up to boost controller * tests
This commit is contained in:
parent
c0d45d5b82
commit
42bfad807b
|
@ -15,14 +15,11 @@
|
||||||
#include "boost_control.h"
|
#include "boost_control.h"
|
||||||
#include "sensor.h"
|
#include "sensor.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "io_pins.h"
|
|
||||||
#include "engine_configuration.h"
|
|
||||||
#include "pwm_generator_logic.h"
|
|
||||||
#include "engine_controller.h"
|
|
||||||
#include "pin_repository.h"
|
#include "pin_repository.h"
|
||||||
#include "pwm_generator_logic.h"
|
#include "pwm_generator_logic.h"
|
||||||
#include "pid_auto_tune.h"
|
#include "pid_auto_tune.h"
|
||||||
#include "local_version_holder.h"
|
#include "electronic_throttle.h"
|
||||||
|
|
||||||
#define NO_PIN_PERIOD 500
|
#define NO_PIN_PERIOD 500
|
||||||
|
|
||||||
#if defined(HAS_OS_ACCESS)
|
#if defined(HAS_OS_ACCESS)
|
||||||
|
@ -148,6 +145,8 @@ void BoostController::setOutput(expected<float> output) {
|
||||||
if (m_pwm) {
|
if (m_pwm) {
|
||||||
m_pwm->setSimplePwmDutyCycle(duty);
|
m_pwm->setSimplePwmDutyCycle(duty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setEtbWastegatePosition(duty PASS_ENGINE_PARAMETER_SUFFIX);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BoostController::PeriodicTask() {
|
void BoostController::PeriodicTask() {
|
||||||
|
|
|
@ -199,6 +199,10 @@ void EtbController::setIdlePosition(percent_t pos) {
|
||||||
m_idlePosition = pos;
|
m_idlePosition = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EtbController::setWastegatePosition(percent_t pos) {
|
||||||
|
m_wastegatePosition = pos;
|
||||||
|
}
|
||||||
|
|
||||||
expected<percent_t> EtbController::getSetpoint() const {
|
expected<percent_t> EtbController::getSetpoint() const {
|
||||||
switch (m_function) {
|
switch (m_function) {
|
||||||
case ETB_Throttle1:
|
case ETB_Throttle1:
|
||||||
|
@ -223,8 +227,7 @@ expected<percent_t> EtbController::getSetpointIdleValve() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
expected<percent_t> EtbController::getSetpointWastegate() const {
|
expected<percent_t> EtbController::getSetpointWastegate() const {
|
||||||
// TODO: implement me!
|
return clampF(0, m_wastegatePosition, 100);
|
||||||
return unexpected;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
expected<percent_t> EtbController::getSetpointEtb() const {
|
expected<percent_t> EtbController::getSetpointEtb() const {
|
||||||
|
@ -721,9 +724,7 @@ void etbAutocal(size_t throttleIndex) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto etb = engine->etbControllers[throttleIndex];
|
if (auto etb = engine->etbControllers[throttleIndex]) {
|
||||||
|
|
||||||
if (etb) {
|
|
||||||
etb->autoCalibrateTps();
|
etb->autoCalibrateTps();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -894,12 +895,18 @@ void initElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
|
|
||||||
void setEtbIdlePosition(percent_t pos DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
void setEtbIdlePosition(percent_t pos DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||||
for (int i = 0; i < ETB_COUNT; i++) {
|
for (int i = 0; i < ETB_COUNT; i++) {
|
||||||
auto etb = engine->etbControllers[i];
|
if (auto etb = engine->etbControllers[i]) {
|
||||||
|
|
||||||
if (etb) {
|
|
||||||
etb->setIdlePosition(pos);
|
etb->setIdlePosition(pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setEtbWastegatePosition(percent_t pos DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||||
|
for (int i = 0; i < ETB_COUNT; i++) {
|
||||||
|
if (auto etb = engine->etbControllers[i]) {
|
||||||
|
etb->setWastegatePosition(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* EFI_ELECTRONIC_THROTTLE_BODY */
|
#endif /* EFI_ELECTRONIC_THROTTLE_BODY */
|
||||||
|
|
|
@ -33,6 +33,7 @@ public:
|
||||||
virtual bool init(etb_function_e function, DcMotor *motor, pid_s *pidParameters, const ValueProvider3D* pedalMap) = 0;
|
virtual bool init(etb_function_e function, DcMotor *motor, pid_s *pidParameters, const ValueProvider3D* pedalMap) = 0;
|
||||||
virtual void reset() = 0;
|
virtual void reset() = 0;
|
||||||
virtual void setIdlePosition(percent_t pos) = 0;
|
virtual void setIdlePosition(percent_t pos) = 0;
|
||||||
|
virtual void setWastegatePosition(percent_t pos) = 0;
|
||||||
virtual void update() = 0;
|
virtual void update() = 0;
|
||||||
virtual void autoCalibrateTps() = 0;
|
virtual void autoCalibrateTps() = 0;
|
||||||
};
|
};
|
||||||
|
@ -41,6 +42,7 @@ class EtbController : public IEtbController {
|
||||||
public:
|
public:
|
||||||
bool init(etb_function_e function, DcMotor *motor, pid_s *pidParameters, const ValueProvider3D* pedalMap) override;
|
bool init(etb_function_e function, DcMotor *motor, pid_s *pidParameters, const ValueProvider3D* pedalMap) override;
|
||||||
void setIdlePosition(percent_t pos) override;
|
void setIdlePosition(percent_t pos) override;
|
||||||
|
void setWastegatePosition(percent_t pos) override;
|
||||||
void reset() override;
|
void reset() override;
|
||||||
|
|
||||||
// Update the controller's state: read sensors, send output, etc
|
// Update the controller's state: read sensors, send output, etc
|
||||||
|
@ -91,6 +93,7 @@ private:
|
||||||
const ValueProvider3D* m_pedalMap = nullptr;
|
const ValueProvider3D* m_pedalMap = nullptr;
|
||||||
|
|
||||||
float m_idlePosition = 0;
|
float m_idlePosition = 0;
|
||||||
|
float m_wastegatePosition = 0;
|
||||||
|
|
||||||
// Autotune helpers
|
// Autotune helpers
|
||||||
bool m_lastIsPositive = false;
|
bool m_lastIsPositive = false;
|
||||||
|
@ -109,7 +112,9 @@ private:
|
||||||
|
|
||||||
void initElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
void initElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||||
void doInitElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
void doInitElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
||||||
|
|
||||||
void setEtbIdlePosition(percent_t pos DECLARE_ENGINE_PARAMETER_SUFFIX);
|
void setEtbIdlePosition(percent_t pos DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||||
|
void setEtbWastegatePosition(percent_t pos DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||||
|
|
||||||
void setDefaultEtbBiasCurve(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
void setDefaultEtbBiasCurve(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||||
void setDefaultEtbParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
void setDefaultEtbParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE);
|
||||||
|
|
|
@ -15,6 +15,7 @@ public:
|
||||||
MOCK_METHOD(void, update, (), (override));
|
MOCK_METHOD(void, update, (), (override));
|
||||||
MOCK_METHOD(bool, init, (etb_function_e function, DcMotor* motor, pid_s* pidParameters, const ValueProvider3D* pedalMap), (override));
|
MOCK_METHOD(bool, init, (etb_function_e function, DcMotor* motor, pid_s* pidParameters, const ValueProvider3D* pedalMap), (override));
|
||||||
MOCK_METHOD(void, setIdlePosition, (percent_t pos), (override));
|
MOCK_METHOD(void, setIdlePosition, (percent_t pos), (override));
|
||||||
|
MOCK_METHOD(void, setWastegatePosition, (percent_t pos), (override));
|
||||||
MOCK_METHOD(void, autoCalibrateTps, (), (override));
|
MOCK_METHOD(void, autoCalibrateTps, (), (override));
|
||||||
|
|
||||||
// ClosedLoopController mocks
|
// ClosedLoopController mocks
|
||||||
|
|
|
@ -106,16 +106,23 @@ TEST(BoostControl, ClosedLoop) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(BoostControl, SetOutput) {
|
TEST(BoostControl, SetOutput) {
|
||||||
StrictMock<MockPwm> pwm;
|
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
|
||||||
BoostController bc;
|
|
||||||
|
|
||||||
|
StrictMock<MockPwm> pwm;
|
||||||
|
StrictMock<MockEtb> etb;
|
||||||
|
BoostController bc;
|
||||||
|
INJECT_ENGINE_REFERENCE(&bc);
|
||||||
|
|
||||||
|
// ETB wastegate position & PWM should both be set
|
||||||
|
EXPECT_CALL(etb, setWastegatePosition(0.25f));
|
||||||
EXPECT_CALL(pwm, setSimplePwmDutyCycle(0.25f));
|
EXPECT_CALL(pwm, setSimplePwmDutyCycle(0.25f));
|
||||||
|
|
||||||
// Don't crash if not init'd (don't deref null ptr m_pwm)
|
// Don't crash if not init'd (don't deref null ptr m_pwm)
|
||||||
EXPECT_NO_THROW(bc.setOutput(25.0f));
|
EXPECT_NO_THROW(bc.setOutput(25.0f));
|
||||||
|
|
||||||
// Init with mock PWM device
|
// Init with mock PWM device and ETB
|
||||||
bc.init(&pwm, nullptr, nullptr, nullptr);
|
bc.init(&pwm, nullptr, nullptr, nullptr);
|
||||||
|
engine->etbControllers[0] = &etb;
|
||||||
|
|
||||||
bc.setOutput(25.0f);
|
bc.setOutput(25.0f);
|
||||||
}
|
}
|
||||||
|
|
|
@ -289,6 +289,25 @@ TEST(etb, setpointIdleValveController) {
|
||||||
EXPECT_FLOAT_EQ(100, etb.getSetpoint().value_or(-1));
|
EXPECT_FLOAT_EQ(100, etb.getSetpoint().value_or(-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(etb, setpointWastegateController) {
|
||||||
|
EtbController etb;
|
||||||
|
|
||||||
|
etb.init(ETB_Wastegate, nullptr, nullptr, nullptr);
|
||||||
|
|
||||||
|
etb.setWastegatePosition(0);
|
||||||
|
EXPECT_FLOAT_EQ(0, etb.getSetpoint().value_or(-1));
|
||||||
|
etb.setWastegatePosition(50);
|
||||||
|
EXPECT_FLOAT_EQ(50, etb.getSetpoint().value_or(-1));
|
||||||
|
etb.setWastegatePosition(100);
|
||||||
|
EXPECT_FLOAT_EQ(100, etb.getSetpoint().value_or(-1));
|
||||||
|
|
||||||
|
// Out of range should be clamped
|
||||||
|
etb.setWastegatePosition(-10);
|
||||||
|
EXPECT_FLOAT_EQ(0, etb.getSetpoint().value_or(-1));
|
||||||
|
etb.setWastegatePosition(110);
|
||||||
|
EXPECT_FLOAT_EQ(100, etb.getSetpoint().value_or(-1));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(etb, etbTpsSensor) {
|
TEST(etb, etbTpsSensor) {
|
||||||
// Throw some distinct values on the TPS sensors so we can identify that we're getting the correct one
|
// Throw some distinct values on the TPS sensors so we can identify that we're getting the correct one
|
||||||
Sensor::setMockValue(SensorType::Tps1, 25.0f);
|
Sensor::setMockValue(SensorType::Tps1, 25.0f);
|
||||||
|
|
Loading…
Reference in New Issue