Skip to content

Commit

Permalink
int rpm -> float rpm
Browse files Browse the repository at this point in the history
  • Loading branch information
mck1117 committed Sep 25, 2024
1 parent 28fc04e commit 8952633
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 35 deletions.
6 changes: 1 addition & 5 deletions firmware/console/status_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,6 @@ static void updateFuelInfo() {
engine->outputChannels.veValue = engine->engineState.currentVe;
}

static void updateIgnition(float rpm) {
engine->outputChannels.coilDutyCycle = getCoilDutyCycle(rpm);
}

static void updateFlags() {
#if EFI_USB_SERIAL
engine->outputChannels.isUsbConnected = is_usb_serial_ready();
Expand Down Expand Up @@ -508,7 +504,7 @@ void updateTunerStudioState() {

updateSensors();
updateFuelInfo();
updateIgnition(rpm);
engine->outputChannels.coilDutyCycle = getCoilDutyCycle(rpm);
updateFlags();

// 104
Expand Down
10 changes: 4 additions & 6 deletions firmware/controllers/algo/antilag_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ bool AntilagSystemBase::isInsideALSSwitchCondition() {
}
}

bool AntilagSystemBase::isALSMinRPMCondition(int rpm) const {
bool AntilagSystemBase::isALSMinRPMCondition(float rpm) const {
return engineConfiguration->ALSMinRPM < rpm;
}

bool AntilagSystemBase::isALSMaxRPMCondition(int rpm) const {
bool AntilagSystemBase::isALSMaxRPMCondition(float rpm) const {
return engineConfiguration->ALSMaxRPM > rpm;
}

Expand All @@ -58,9 +58,7 @@ bool AntilagSystemBase::isALSMaxThrottleIntentCondition() const {
return engineConfiguration->ALSMaxTPS > throttleIntent;
}

bool AntilagSystemBase::isAntilagConditionMet(int rpm) {


bool AntilagSystemBase::isAntilagConditionMet(float rpm) {
ALSMinRPMCondition = isALSMinRPMCondition(rpm);
ALSMaxRPMCondition = isALSMaxRPMCondition(rpm);
ALSMinCLTCondition = isALSMinCLTCondition();
Expand All @@ -77,7 +75,7 @@ bool AntilagSystemBase::isAntilagConditionMet(int rpm) {
}

void AntilagSystemBase::update() {
int rpm = Sensor::getOrZero(SensorType::Rpm);
float rpm = Sensor::getOrZero(SensorType::Rpm);
isAntilagCondition = engineConfiguration->antiLagEnabled && isAntilagConditionMet(rpm);

#if EFI_ANTILAG_SYSTEM
Expand Down
8 changes: 4 additions & 4 deletions firmware/controllers/algo/antilag_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ class AntilagSystemBase : public antilag_system_state_s {
public:
void update();

bool isALSMinRPMCondition(int rpm) const;
bool isALSMaxRPMCondition(int rpm) const;
bool isALSMinRPMCondition(float rpm) const;
bool isALSMaxRPMCondition(float rpm) const;
bool isALSMinCLTCondition() const;
bool isALSMaxCLTCondition() const;
bool isALSMaxThrottleIntentCondition() const;
bool isInsideALSSwitchCondition();
/* enabled and all conditions above */
bool isAntilagConditionMet(int rpm);
/* enabled and all conditions above */
bool isAntilagConditionMet(float rpm);
};
2 changes: 1 addition & 1 deletion firmware/controllers/algo/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void Engine::updateSlowSensors() {
updateSwitchInputs();

#if EFI_SHAFT_POSITION_INPUT
int rpm = Sensor::getOrZero(SensorType::Rpm);
float rpm = Sensor::getOrZero(SensorType::Rpm);
triggerCentral.isEngineSnifferEnabled = rpm < engineConfiguration->engineSnifferRpmThreshold;
getEngineState()->sensorChartMode = rpm < engineConfiguration->sensorSnifferRpmThreshold ? engineConfiguration->sensorChartMode : SC_OFF;

Expand Down
7 changes: 4 additions & 3 deletions firmware/controllers/engine_cycle/main_trigger_callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@ void mainTriggerCallback(uint32_t trgEventIndex, efitick_t edgeTimestamp, angle_
return;
}

int rpm = engine->rpmCalculator.getCachedRpm();
float rpm = engine->rpmCalculator.getCachedRpm();
if (rpm == 0) {
// this happens while we just start cranking

// todo: check for 'trigger->is_synchnonized?'
return;
}
if (rpm == NOISY_RPM || rpm > UNREALISTIC_RPM) {

if (rpm == NOISY_RPM || !isValidRpm(rpm)) {
warning(ObdCode::OBD_Crankshaft_Position_Sensor_A_Circuit_Malfunction, "noisy trigger");
return;
}
Expand Down Expand Up @@ -106,7 +107,7 @@ void mainTriggerCallback(uint32_t trgEventIndex, efitick_t edgeTimestamp, angle_
/**
* For spark we schedule both start of coil charge and actual spark based on trigger angle
*/
onTriggerEventSparkLogic(rpm, edgeTimestamp, currentPhase, nextPhase);
onTriggerEventSparkLogic(edgeTimestamp, currentPhase, nextPhase);
}

#endif /* EFI_ENGINE_CONTROL */
2 changes: 1 addition & 1 deletion firmware/controllers/engine_cycle/rpm_calculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ void tdcMarkCallback(

// two instances of scheduling_s are needed to properly handle event overlap
int revIndex2 = getRevolutionCounter() % 2;
int rpm = Sensor::getOrZero(SensorType::Rpm);
float rpm = Sensor::getOrZero(SensorType::Rpm);
// todo: use tooth event-based scheduling, not just time-based scheduling
if (isValidRpm(rpm)) {
angle_t tdcPosition = tdcPosition();
Expand Down
16 changes: 7 additions & 9 deletions firmware/controllers/engine_cycle/spark_logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@ void turnSparkPinHigh(IgnitionEvent *event) {
}
}

static void scheduleSparkEvent(bool limitedSpark, IgnitionEvent *event,
int rpm, float dwellMs, float dwellAngle, float sparkAngle, efitick_t edgeTimestamp, float currentPhase, float nextPhase) {
static void scheduleSparkEvent(bool limitedSpark, IgnitionEvent *event, float dwellMs, float dwellAngle, float sparkAngle, efitick_t edgeTimestamp, float currentPhase, float nextPhase) {

float angleOffset = dwellAngle - currentPhase;
if (angleOffset < 0) {
Expand Down Expand Up @@ -361,11 +360,10 @@ static void prepareIgnitionSchedule() {
initializeIgnitionActions();
}

void onTriggerEventSparkLogic(int rpm, efitick_t edgeTimestamp, float currentPhase, float nextPhase) {
void onTriggerEventSparkLogic(efitick_t edgeTimestamp, float currentPhase, float nextPhase) {
ScopePerf perf(PE::OnTriggerEventSparkLogic);

if (!isValidRpm(rpm) || !engineConfiguration->isIgnitionEnabled) {
// this might happen for instance in case of a single trigger event after a pause
if (!engineConfiguration->isIgnitionEnabled) {
return;
}

Expand All @@ -377,7 +375,7 @@ void onTriggerEventSparkLogic(int rpm, efitick_t edgeTimestamp, float currentPha

const floatms_t dwellMs = engine->ignitionState.sparkDwell;
if (std::isnan(dwellMs) || dwellMs <= 0) {
warning(ObdCode::CUSTOM_DWELL, "invalid dwell to handle: %.2f at %d", dwellMs, rpm);
warning(ObdCode::CUSTOM_DWELL, "invalid dwell to handle: %.2f", dwellMs);
return;
}

Expand Down Expand Up @@ -454,10 +452,10 @@ void onTriggerEventSparkLogic(int rpm, efitick_t edgeTimestamp, float currentPha
continue;
}
auto ALSSkipRatio = engineConfiguration->ALSSkipRatio;
engine->ALSsoftSparkLimiter.setTargetSkipRatio(ALSSkipRatio);
engine->ALSsoftSparkLimiter.setTargetSkipRatio(ALSSkipRatio);
#endif // EFI_ANTILAG_SYSTEM

scheduleSparkEvent(limitedSpark, event, rpm, dwellMs, dwellAngle, sparkAngle, edgeTimestamp, currentPhase, nextPhase);
scheduleSparkEvent(limitedSpark, event, dwellMs, dwellAngle, sparkAngle, edgeTimestamp, currentPhase, nextPhase);
}
}
}
Expand Down Expand Up @@ -485,7 +483,7 @@ int getNumberOfSparks(ignition_mode_e mode) {
/**
* @see getInjectorDutyCycle
*/
percent_t getCoilDutyCycle(int rpm) {
percent_t getCoilDutyCycle(float rpm) {
floatms_t totalPerCycle = engine->ignitionState.sparkDwell * getNumberOfSparks(getCurrentIgnitionMode());
floatms_t engineCycleDuration = getCrankshaftRevolutionTimeMs(rpm) * (getEngineRotationState()->getOperationMode() == TWO_STROKE ? 1 : 2);
return 100 * totalPerCycle / engineCycleDuration;
Expand Down
4 changes: 2 additions & 2 deletions firmware/controllers/engine_cycle/spark_logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

#pragma once

void onTriggerEventSparkLogic(int rpm, efitick_t edgeTimestamp, float currentPhase, float nextPhase);
void onTriggerEventSparkLogic(efitick_t edgeTimestamp, float currentPhase, float nextPhase);
void turnSparkPinHigh(IgnitionEvent *event);
void fireSparkAndPrepareNextSchedule(IgnitionEvent *event);
int getNumberOfSparks(ignition_mode_e mode);
percent_t getCoilDutyCycle(int rpm);
percent_t getCoilDutyCycle(float rpm);
void initializeIgnitionActions();
2 changes: 1 addition & 1 deletion firmware/controllers/sensors/vr_pwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ static SimplePwm pwms[VR_THRESHOLD_COUNT];
#define VR_SUPPLY_VOLTAGE 3.3f
#endif

static void updateVrPwm(int rpm, size_t index) {
static void updateVrPwm(float rpm, size_t index) {
auto& cfg = engineConfiguration->vrThreshold[index];

if (!isBrainPinValid(cfg.pin)) {
Expand Down
2 changes: 1 addition & 1 deletion firmware/development/logic_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ static void reportWave(Logging *logging, int index) {
logging->appendPrintf("%s", LOG_DELIMITER);

efitimeus_t offsetUs = getWaveOffset(index);
int rpm = Sensor::getOrZero(SensorType::Rpm);
float rpm = Sensor::getOrZero(SensorType::Rpm);
if (rpm != 0) {
float oneDegreeUs = getOneDegreeTimeUs(rpm);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ TEST(ignition, oddCylinderWastedSpark) {
engineConfiguration->minimumIgnitionTiming = -25;

// expect to schedule the on-phase dwell and spark (not the wasted spark copy)
onTriggerEventSparkLogic(1200, nowNt1, 10, 30);
onTriggerEventSparkLogic(nowNt1, 10, 30);

// expect to schedule second events, the out-of-phase dwell and spark (the wasted spark copy)
onTriggerEventSparkLogic(1200, nowNt2, 360 + 10, 360 + 30);
onTriggerEventSparkLogic(nowNt2, 360 + 10, 360 + 30);
}

0 comments on commit 8952633

Please sign in to comment.