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:
+1
-1
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user