implement

This commit is contained in:
Matthew Kennedy 2020-07-26 02:55:35 -07:00
parent a27d682f14
commit 7003d6c7ba
2 changed files with 25 additions and 7 deletions

View File

@ -99,7 +99,11 @@ static bool startupPositionError = false;
#define STARTUP_NEUTRAL_POSITION_ERROR_THRESHOLD 5 #define STARTUP_NEUTRAL_POSITION_ERROR_THRESHOLD 5
static SensorType indexToTpsSensor(size_t index) { static SensorType indexToTpsSensor(size_t index, bool volkswagenEtbIdle) {
if (volkswagenEtbIdle) {
return SensorType::Tps2;
}
switch(index) { switch(index) {
case 0: return SensorType::Tps1; case 0: return SensorType::Tps1;
default: return SensorType::Tps2; default: return SensorType::Tps2;
@ -127,7 +131,8 @@ static percent_t currentEtbDuty;
// this macro clamps both positive and negative percentages from about -100% to 100% // this macro clamps both positive and negative percentages from about -100% to 100%
#define ETB_PERCENT_TO_DUTY(x) (clampF(-ETB_DUTY_LIMIT, 0.01f * (x), ETB_DUTY_LIMIT)) #define ETB_PERCENT_TO_DUTY(x) (clampF(-ETB_DUTY_LIMIT, 0.01f * (x), ETB_DUTY_LIMIT))
void EtbController::init(DcMotor *motor, int ownIndex, pid_s *pidParameters, const ValueProvider3D* pedalMap) { void EtbController::init(SensorType positionSensor, DcMotor *motor, int ownIndex, pid_s *pidParameters, const ValueProvider3D* pedalMap) {
m_positionSensor = positionSensor;
m_motor = motor; m_motor = motor;
m_myIndex = ownIndex; m_myIndex = ownIndex;
m_pid.initPidClass(pidParameters); m_pid.initPidClass(pidParameters);
@ -149,7 +154,7 @@ void EtbController::showStatus(Logging* logger) {
} }
expected<percent_t> EtbController::observePlant() const { expected<percent_t> EtbController::observePlant() const {
return Sensor::get(indexToTpsSensor(m_myIndex)); return Sensor::get(m_positionSensor);
} }
void EtbController::setIdlePosition(percent_t pos) { void EtbController::setIdlePosition(percent_t pos) {
@ -162,6 +167,12 @@ expected<percent_t> EtbController::getSetpoint() const {
return unexpected; return unexpected;
} }
// VW ETB idle mode uses an ETB only for idle (a mini-ETB sets the lower stop, and a normal cable
// can pull the throttle up off the stop.), so we directly control the throttle with the idle position.
if (CONFIG(volkswagenEtbIdle)) {
return m_idlePosition;
}
// If the pedal map hasn't been set, we can't provide a setpoint. // If the pedal map hasn't been set, we can't provide a setpoint.
if (!m_pedalMap) { if (!m_pedalMap) {
return unexpected; return unexpected;
@ -743,7 +754,11 @@ void doInitElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
pedal2tpsMap.init(config->pedalToTpsTable, config->pedalToTpsPedalBins, config->pedalToTpsRpmBins); pedal2tpsMap.init(config->pedalToTpsTable, config->pedalToTpsPedalBins, config->pedalToTpsRpmBins);
if (CONFIG(volkswagenEtbIdle)) {
engine->etbActualCount = 1;
} else {
engine->etbActualCount = Sensor::hasSensor(SensorType::Tps2) ? 2 : 1; engine->etbActualCount = Sensor::hasSensor(SensorType::Tps2) ? 2 : 1;
}
for (int i = 0 ; i < engine->etbActualCount; i++) { for (int i = 0 ; i < engine->etbActualCount; i++) {
auto motor = initDcMotor(i, CONFIG(etb_use_two_wires) PASS_ENGINE_PARAMETER_SUFFIX); auto motor = initDcMotor(i, CONFIG(etb_use_two_wires) PASS_ENGINE_PARAMETER_SUFFIX);
@ -751,7 +766,8 @@ void doInitElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
// If this motor is actually set up, init the etb // If this motor is actually set up, init the etb
if (motor) if (motor)
{ {
engine->etbControllers[i]->init(motor, i, &engineConfiguration->etb, &pedal2tpsMap); auto positionSensor = indexToTpsSensor(i, CONFIG(volkswagenEtbIdle));
engine->etbControllers[i]->init(positionSensor, motor, i, &engineConfiguration->etb, &pedal2tpsMap);
INJECT_ENGINE_REFERENCE(engine->etbControllers[i]); INJECT_ENGINE_REFERENCE(engine->etbControllers[i]);
} }
} }

View File

@ -19,6 +19,7 @@
#include "engine.h" #include "engine.h"
#include "closed_loop_controller.h" #include "closed_loop_controller.h"
#include "expected.h" #include "expected.h"
#include "sensor.h"
class DcMotor; class DcMotor;
class Logging; class Logging;
@ -26,7 +27,7 @@ class Logging;
class IEtbController : public ClosedLoopController<percent_t, percent_t> { class IEtbController : public ClosedLoopController<percent_t, percent_t> {
public: public:
DECLARE_ENGINE_PTR; DECLARE_ENGINE_PTR;
virtual void init(DcMotor *motor, int ownIndex, pid_s *pidParameters, const ValueProvider3D* pedalMap) = 0; virtual void init(SensorType positionSensor, DcMotor *motor, int ownIndex, 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 start() = 0; virtual void start() = 0;
@ -35,7 +36,7 @@ public:
class EtbController : public IEtbController { class EtbController : public IEtbController {
public: public:
void init(DcMotor *motor, int ownIndex, pid_s *pidParameters, const ValueProvider3D* pedalMap) override; void init(SensorType positionSensor, DcMotor *motor, int ownIndex, pid_s *pidParameters, const ValueProvider3D* pedalMap) override;
void setIdlePosition(percent_t pos) override; void setIdlePosition(percent_t pos) override;
void reset() override; void reset() override;
void start() override {} void start() override {}
@ -74,6 +75,7 @@ protected:
private: private:
int m_myIndex = 0; int m_myIndex = 0;
SensorType m_positionSensor = SensorType::Invalid;
DcMotor *m_motor = nullptr; DcMotor *m_motor = nullptr;
Pid m_pid; Pid m_pid;
bool m_shouldResetPid = false; bool m_shouldResetPid = false;