Make car mass configurable at runtime

Replace the compile‑time CAR_MASS constant with a runtime‑settable
_member _carMass. Add Engine::setCarMass, default it to 1200 kg, and
use it in the acceleration calculation. Prompt the user for the
car mass on startup via Serial and update the enable/disable messages.
This commit is contained in:
2026-06-17 00:13:16 +02:00
parent c053a296a5
commit 6c0a1fc15b
3 changed files with 33 additions and 4 deletions
+1 -1
View File
@@ -33,7 +33,7 @@ void Engine::update(float dt, uint8_t gearIdx) {
const float dragForce = 0.5f * DRAG_COEFF * FRONTAL_AREA * (_speedMs * _speedMs);
const int direction = (gearIdx == -1) ? -1 : 1;
const float netForce = direction * engineForce - brakeForce - dragForce;
const float acceleration = netForce / CAR_MASS;
const float acceleration = netForce / _carMass;
_speedMs += acceleration * dt;
if (_speedMs < 0.0f) _speedMs = 0.0f;