EDITED/UPDATED
Hi guys, first off a caution, and a thanks for any replies - I've modded my code quite a bit, but asking about a current glitch that's got me stumped..
Question:
What would hold out the "currentRPM" or "targetRpm" variable from updating with throttle input?
Issue:
Engine RPM (sound) no longer increases with throttle input.
Also, no RPM on LCD dash screen.
Found so far:
Truck drives as it should, all throttles, brakes etc work fine.
Engine volume correctly increases to max with throttle input, but is 100% idle.
My "currentRpm" variable is no longer changing/updating with throttle input.
Or "_currentRpm".
Neither is "targetRpm".
Variables such as "engineload", "currentThrottle", "currentspeed", "drivestate", "engineState" etc all work and react as they should.
Using a VSCode diff operation (compared to unmodded code) doesn't show any differences in the RPM control section (around line 3370ish):
Code:
// Engine RPM **************************************************************************************
// Engine RPM **************************************************************************************
if (escIsBraking && currentSpeed < clutchEngagingPoint)
targetRpm = 0; // keep engine @idle rpm, if braking at very low speed
if (targetRpm > 500)
targetRpm = 500;
// Accelerate engine
if (targetRpm > (_currentRpm + acc) && (_currentRpm + acc) < maxRpm && engineState == RUNNING && engineRunning)
{
if (!airBrakeTrigger)
{ // No acceleration, if brake release noise still playing
if (!gearDownShiftingInProgress)
_currentRpm += acc;
else
_currentRpm += acc / 2; // less aggressive rpm rise while downshifting
if (_currentRpm > maxRpm)
_currentRpm = maxRpm;
}
}
// Decelerate engine
if (targetRpm < _currentRpm)
{
_currentRpm -= dec;
if (_currentRpm < minRpm)
_currentRpm = minRpm;
}
#if (defined VIRTUAL_3_SPEED || defined VIRTUAL_16_SPEED_SEQUENTIAL) and not defined STEAM_LOCOMOTIVE_MODE
// Limit top speed, depending on manual gear ratio. Ensures, that the engine will not blow up!
if (!automatic && !doubleClutch)
speedLimit = maxRpm * 10 / virtualManualGearRatio[selectedGear];
#endif
// Speed (sample rate) output
engineSampleRate = map(_currentRpm, minRpm, maxRpm, maxSampleInterval, minSampleInterval); // Idle
// if ( xSemaphoreTake( xRpmSemaphore, portMAX_DELAY ) )
//{
currentRpm = _currentRpm;
// xSemaphoreGive( xRpmSemaphore ); // Now free or "Give" the semaphore for others.
// }
}
// Prevent Wastegate from being triggered while downshifting
if (gearDownShiftingInProgress)
wastegateMillis = millis();
// Trigger Wastegate, if throttle rapidly dropped
if (lastThrottle - _currentThrottle > 70 && !escIsBraking && millis() - wastegateMillis > 1000)
{
wastegateMillis = millis();
wastegateTrigger = true;
}
#if defined JAKEBRAKE_ENGINE_SLOWDOWN && defined JAKE_BRAKE_SOUND
// Use jake brake to slow down engine while releasing throttle in neutral or during upshifting while applying throttle
// for some vehicles like Volvo FH open pipe. See example: https://www.youtube.com/watch?v=MU1iwzl33Zw&list=LL&index=4
if (!wastegateTrigger)
blowoffMillis = millis();
// blowoffTrigger = ((gearUpShiftingInProgress || neutralGear) && millis() - blowoffMillis > 20 && millis() - blowoffMillis < 250);
#endif
lastThrottle = _currentThrottle;
}
//
if (escIsBraking && currentSpeed < clutchEngagingPoint)
targetRpm = 0; // keep engine @idle rpm, if braking at very low speed
if (targetRpm > 500)
targetRpm = 500;
// Accelerate engine
if (targetRpm > (_currentRpm + acc) && (_currentRpm + acc) < maxRpm && engineState == RUNNING && engineRunning)
{
if (!airBrakeTrigger)
{ // No acceleration, if brake release noise still playing
if (!gearDownShiftingInProgress)
_currentRpm += acc;
else
_currentRpm += acc / 2; // less aggressive rpm rise while downshifting
if (_currentRpm > maxRpm)
_currentRpm = maxRpm;
}
}
// Decelerate engine
if (targetRpm < _currentRpm)
{
_currentRpm -= dec;
if (_currentRpm < minRpm)
_currentRpm = minRpm;
}
#if (defined VIRTUAL_3_SPEED || defined VIRTUAL_16_SPEED_SEQUENTIAL) and not defined STEAM_LOCOMOTIVE_MODE
// Limit top speed, depending on manual gear ratio. Ensures, that the engine will not blow up!
if (!automatic && !doubleClutch)
speedLimit = maxRpm * 10 / virtualManualGearRatio[selectedGear];
#endif
// Speed (sample rate) output
engineSampleRate = map(_currentRpm, minRpm, maxRpm, maxSampleInterval, minSampleInterval); // Idle
// if ( xSemaphoreTake( xRpmSemaphore, portMAX_DELAY ) )
//{
currentRpm = _currentRpm;
// xSemaphoreGive( xRpmSemaphore ); // Now free or "Give" the semaphore for others.
// }
}
// Prevent Wastegate from being triggered while downshifting
if (gearDownShiftingInProgress)
wastegateMillis = millis();
// Trigger Wastegate, if throttle rapidly dropped
if (lastThrottle - _currentThrottle > 70 && !escIsBraking && millis() - wastegateMillis > 1000)
{
wastegateMillis = millis();
wastegateTrigger = true;
}
#if defined JAKEBRAKE_ENGINE_SLOWDOWN && defined JAKE_BRAKE_SOUND
// Use jake brake to slow down engine while releasing throttle in neutral or during upshifting while applying throttle
// for some vehicles like Volvo FH open pipe. See example: https://www.youtube.com/watch?v=MU1iwzl33Zw&list=LL&index=4
if (!wastegateTrigger)
blowoffMillis = millis();
// blowoffTrigger = ((gearUpShiftingInProgress || neutralGear) && millis() - blowoffMillis > 20 && millis() - blowoffMillis < 250);
#endif
lastThrottle = _currentThrottle;
}
//
The last mods I made were quite simple, basically if not neutralGear then no engine shutdown or startup. Deleted these commands but issue persists.
I fear I've corrupted some other file with an accidental keypress or something, have also compared other files such as the included vehicle and the specific engine rev sound.
I've been monitoring variables, using diff operations to compare files, reverting to unmodded files and making individual changes, but still no luck.
I was able to force the "targetRpm" variable to a fixed value which brought the rpm sound up (basically targetRpm = 300).
I've spent about 20hrs on this issue (12 today!) so far and only getting more frustrated/confused.
Any suggestions or techniques to solve?
Src code file attached.
Would be much appreciated
Cheers
Dave
UPDATE: I've found I can import my src code file into an original code folder and the throttle RPM works as it used to. If I copy over the rest of my .h files, the issue occurs again. Seems the problem lies outside my main code, or a conflict arises somewhere with the header files. Have begun investigating which file it may be..
UPDATE#2: Original Dash.h file corrected the RPM sound issue, but because dash function was disabled.
I then disabled the dash in my modded code and the RPM issue disappears, but I'm left with no dash function. Investigation continues..