trim table for throttle #2 (#4472)

* add table and wire it up

* trim table ui

* initialization

* changelog

* add a test
This commit is contained in:
Matthew Kennedy 2022-08-28 05:28:20 -07:00 committed by GitHub
parent b3dfbd5a1d
commit 0d99d828e3
6 changed files with 62 additions and 5 deletions

View File

@ -27,6 +27,7 @@ Release template (copy/paste this for new release):
### Added ### Added
- Time delay before DFCO #4292 - Time delay before DFCO #4292
- Manual electronic throttle synchronization #3680
### Fixed ### Fixed
- Inverted vvt control #4464 - Inverted vvt control #4464

View File

@ -94,6 +94,7 @@
#endif /* ETB_MAX_COUNT */ #endif /* ETB_MAX_COUNT */
static pedal2tps_t pedal2tpsMap; static pedal2tps_t pedal2tpsMap;
static Map3D<6, 6, int8_t, uint8_t, uint8_t> throttle2TrimTable;
constexpr float etbPeriodSeconds = 1.0f / ETB_LOOP_FREQUENCY; constexpr float etbPeriodSeconds = 1.0f / ETB_LOOP_FREQUENCY;
@ -384,9 +385,8 @@ float EtbController::getLuaAdjustment() const {
} }
} }
percent_t EtbController2::getThrottleTrim(float /*rpm*/, percent_t /*targetPosition*/) const { percent_t EtbController2::getThrottleTrim(float rpm, percent_t targetPosition) const {
// TODO: implement me #3680 return m_throttle2Trim.getValue(rpm, targetPosition);
return 0;
} }
expected<percent_t> EtbController::getOpenLoop(percent_t target) { expected<percent_t> EtbController::getOpenLoop(percent_t target) {
@ -614,8 +614,13 @@ void EtbController::autoCalibrateTps() {
*/ */
#include "periodic_thread_controller.h" #include "periodic_thread_controller.h"
#include <utility>
template <typename TBase> template <typename TBase>
struct EtbImpl final : public TBase { struct EtbImpl final : public TBase {
template <typename... TArgs>
EtbImpl(TArgs&&... args) : TBase(std::forward<TArgs>(args)...) { }
void update() override { void update() override {
#if EFI_TUNER_STUDIO #if EFI_TUNER_STUDIO
if (TBase::m_isAutocal) { if (TBase::m_isAutocal) {
@ -688,7 +693,7 @@ struct EtbImpl final : public TBase {
// real implementation (we mock for some unit tests) // real implementation (we mock for some unit tests)
static EtbImpl<EtbController1> etb1; static EtbImpl<EtbController1> etb1;
static EtbImpl<EtbController2> etb2; static EtbImpl<EtbController2> etb2(throttle2TrimTable);
static_assert(ETB_COUNT == 2); static_assert(ETB_COUNT == 2);
static EtbController* etbControllers[] = { &etb1, &etb2 }; static EtbController* etbControllers[] = { &etb1, &etb2 };
@ -961,6 +966,7 @@ void doInitElectronicThrottle() {
#endif /* EFI_PROD_CODE */ #endif /* EFI_PROD_CODE */
pedal2tpsMap.init(config->pedalToTpsTable, config->pedalToTpsPedalBins, config->pedalToTpsRpmBins); pedal2tpsMap.init(config->pedalToTpsTable, config->pedalToTpsPedalBins, config->pedalToTpsRpmBins);
throttle2TrimTable.init(config->throttle2TrimTable, config->throttle2TrimTpsBins, config->throttle2TrimRpmBins);
bool shouldInitThrottles = Sensor::hasSensor(SensorType::AcceleratorPedalPrimary); bool shouldInitThrottles = Sensor::hasSensor(SensorType::AcceleratorPedalPrimary);
bool anyEtbConfigured = false; bool anyEtbConfigured = false;

View File

@ -115,5 +115,13 @@ class EtbController1 : public EtbController { };
class EtbController2 : public EtbController { class EtbController2 : public EtbController {
public: public:
EtbController2(const ValueProvider3D& throttle2TrimTable)
: m_throttle2Trim(throttle2TrimTable)
{
}
percent_t getThrottleTrim(float rpm, percent_t /*targetPosition*/) const override; percent_t getThrottleTrim(float rpm, percent_t /*targetPosition*/) const override;
private:
const ValueProvider3D& m_throttle2Trim;
}; };

View File

@ -1715,7 +1715,11 @@ uint8_t[8] tcu_tccUnlockSpeed;;"MPH", 1, 0, 0, 255, 0
uint8_t[8] tcu_32SpeedBins;;"KPH", 1, 0, 0, 255, 0 uint8_t[8] tcu_32SpeedBins;;"KPH", 1, 0, 0, 255, 0
uint8_t[8] tcu_32Vals;;"%", 1, 0, 0, 255, 0 uint8_t[8] tcu_32Vals;;"%", 1, 0, 0, 255, 0
int8_t[6 x 6] autoscale throttle2TrimTable;;"%", 0.1, 0, -10, 10, 1
uint8_t[6] throttle2TrimTpsBins;;"%", 1, 0, 0, 120, 0
uint8_t[6] autoscale throttle2TrimRpmBins;;"RPM", 100, 0, 0, 25000, 0
end_struct end_struct
! Pedal Position Sensor ! Pedal Position Sensor

View File

@ -952,6 +952,11 @@ curve = 32Curve, "3-2 Shift Solenoid Percent by Speed"
gridOrient = 250, 0, 340 ; Space 123 rotation of grid in degrees. gridOrient = 250, 0, 340 ; Space 123 rotation of grid in degrees.
upDownLabel = "(Later)", "(Sooner)" upDownLabel = "(Later)", "(Sooner)"
table = throttle2TrimTbl, throttle2TrimMap, "ETB #2 Trim", 1
xBins = throttle2TrimRpmBins, RPMValue
yBins = throttle2TrimTpsBins, TPSValue
zBins = throttle2TrimTable
gridOrient = 250, 0, 340 ; Space 123 rotation of grid in degrees.
#if LAMBDA #if LAMBDA
table = lambdaTableTbl, lambdaTableMap, "Target Lambda Table", 1 table = lambdaTableTbl, lambdaTableMap, "Target Lambda Table", 1
@ -1551,6 +1556,7 @@ menuDialog = main
subMenu = etbDialog, "Electronic throttle body" @@if_ts_show_etb subMenu = etbDialog, "Electronic throttle body" @@if_ts_show_etb
subMenu = etbTpsBiasCurve, "ETB bias curve (feed forward)" @@if_ts_show_etb subMenu = etbTpsBiasCurve, "ETB bias curve (feed forward)" @@if_ts_show_etb
subMenu = pedalToTpsTbl, "ETB pedal target" @@if_ts_show_etb subMenu = pedalToTpsTbl, "ETB pedal target" @@if_ts_show_etb
subMenu = throttle2TrimTbl, "ETB #2 Trim", { tps2_1AdcChannel != @@ADC_CHANNEL_NONE@@ } @@if_ts_show_etb
subMenu = std_separator subMenu = std_separator
subMenu = vvtPidDialog, "VVT outputs and PID", { vvtMode1 != @@vvt_mode_e_VVT_INACTIVE@@ } subMenu = vvtPidDialog, "VVT outputs and PID", { vvtMode1 != @@vvt_mode_e_VVT_INACTIVE@@ }

View File

@ -15,6 +15,7 @@
using ::testing::_; using ::testing::_;
using ::testing::Ne; using ::testing::Ne;
using ::testing::Return;
using ::testing::StrictMock; using ::testing::StrictMock;
TEST(etb, initializationNoPedal) { TEST(etb, initializationNoPedal) {
@ -323,6 +324,37 @@ TEST(etb, testSetpointOnlyPedal) {
EXPECT_EQ(90, etb.getSetpoint().value_or(-1)); EXPECT_EQ(90, etb.getSetpoint().value_or(-1));
} }
TEST(etb, setpointSecondThrottleTrim) {
EngineTestHelper eth(TEST_ENGINE);
// Don't use ETB for idle, we aren't testing that yet - just pedal table for now
engineConfiguration->useETBforIdleControl = false;
// Mock pedal map that's just passthru pedal -> target
StrictMock<MockVp3d> pedalMap;
EXPECT_CALL(pedalMap, getValue(_, _))
.WillRepeatedly([](float xRpm, float y) {
return y;
});
// Should get called with the un-adjusted setpoint
StrictMock<MockVp3d> throttleTrimTable;
EXPECT_CALL(throttleTrimTable, getValue(0, 47))
.WillOnce(Return(4));
// Must have TPS & PPS initialized for ETB setup
Sensor::setMockValue(SensorType::Tps1Primary, 0);
Sensor::setMockValue(SensorType::Tps1, 0.0f, true);
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
EtbController2 etb(throttleTrimTable);
etb.init(ETB_Throttle1, nullptr, nullptr, &pedalMap, true);
Sensor::setMockValue(SensorType::AcceleratorPedal, 47, true);
EXPECT_EQ(51, etb.getSetpoint().value_or(-1));
}
TEST(etb, setpointIdle) { TEST(etb, setpointIdle) {
EngineTestHelper eth(TEST_ENGINE); EngineTestHelper eth(TEST_ENGINE);