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
+3 -1
View File
@@ -13,7 +13,6 @@ constexpr float GEAR_RATIO[6] = {
constexpr float FINAL_DRIVE = 3.74f; // przekładnia różnicowa
constexpr float WHEEL_RADIUS = 0.30f; // m
constexpr float CAR_MASS = 1200.0f; // kg
constexpr float RPM_IDLE = 800.0f; // obroty jałowe
constexpr float RPM_MAX = 7000.0f; // maksymalne obroty
@@ -31,6 +30,8 @@ public:
void begin();
void setCarMass(float mass) { _carMass = mass; }
void update(float dt, uint8_t gearIdx);
int getRPM() const;
@@ -46,6 +47,7 @@ private:
float _engineRPM = EngineConsts::RPM_IDLE;
float _speedMs = 0.0f;
float _carMass = 1200.0f;
float readNormalized(uint8_t pin) const;
};