tach sweep experiment

This commit is contained in:
Matthew Kennedy 2024-09-04 22:38:12 -07:00
parent 4d02171f6d
commit 2ff394e3e9
3 changed files with 51 additions and 4 deletions

View File

@ -41,7 +41,7 @@ void TachometerModule::onFastCallback() {
}
// What is the angle per tach output period?
float cycleTimeMs = 60000.0f / Sensor::getOrZero(SensorType::Rpm);
float cycleTimeMs = 60000.0f / getRpm();
float periodTimeMs = cycleTimeMs / periods;
tachFreq = 1000.0f / periodTimeMs;
@ -62,6 +62,37 @@ void TachometerModule::onFastCallback() {
tachControl.setFrequency(tachFreq);
}
float TachometerModule::getRpm() {
float trueRpm = Sensor::getOrZero(SensorType::Rpm);
if (!m_doTachSweep) {
return trueRpm;
}
float elapsed = m_stateChangeTimer.getElapsedSeconds();
float sweepPosition = elapsed / engineConfiguration->tachSweepTime;
if (sweepPosition > 1) {
// We've done a full sweep time, we're done!
m_doTachSweep = false;
return trueRpm;
} else if (sweepPosition < 0.5f) {
// First half of the ramp, ramp up from 0 -> max
return interpolateClamped(0, 0.5f, 0, engineConfiguration->tachSweepMax, sweepPosition);
} else {
// Use y2 = trueRpm instead of 0 so that it ramps back down smoothly
// to the current RPM if the engine started during ther ramp
return interpolateClamped(0.5f, 1, engineConfiguration->tachSweepMax, trueRpm, sweepPosition);
}
}
void TachometerModule::onIgnitionStateChanged(bool ignitionOn) {
if (ignitionOn && engineConfiguration->tachSweepTime != 0) {
m_stateChangeTimer.reset();
m_doTachSweep = true;
}
}
void initTachometer() {
tachHasInit = false;

View File

@ -9,8 +9,23 @@
void initTachometer();
struct TachometerModule : public EngineModule {
class TachometerModule : public EngineModule {
public:
// TODO: can/should this be slow callback instead?
void onFastCallback() override;
void onIgnitionStateChanged(bool ignitionOn) override;
private:
float getRpm();
bool m_doTachSweep = false;
enum class TachState {
Normal,
RampUp,
RampDown,
};
TachState m_state = TachState::Normal;
Timer m_stateChangeTimer;
};

View File

@ -744,7 +744,8 @@ output_pin_e acFanPin;Optional Radiator Fan used with A/C
Gpio[EGT_CHANNEL_COUNT iterate] max31855_cs;
brain_input_pin_e flexSensorPin;Continental/GM flex fuel sensor, 50-150hz type;
uint16_t unused720
uint8_t autoscale tachSweepTime;Total time for the tach to sweep up then back down at startup. Set to 0 to disable sweep.;"s", 0.1, 0, 0, 10, 1
uint8_t autoscale tachSweepMax;Maximum RPM for the startup tach sweep.;"rpm", 50, 9, 0, 12500, 0
pin_output_mode_e stepperDirectionPinMode;
spi_device_e mc33972spiDevice;