Add Engine class and integrate it into Projekt

Add clutch, brake, and throttle pin constants to Config.h.
Implement Engine class in Engine.h/Engine.cpp to read analog inputs,
compute engine RPM, vehicle speed, and apply forces.
Create an Engine instance in Projekt.ino, initialize it in setup,
and update it every 20ms, displaying RPM and speed.
This commit is contained in:
2026-06-16 11:08:56 +02:00
parent d26fb721f9
commit b957a0701b
4 changed files with 160 additions and 0 deletions
+48
View File
@@ -0,0 +1,48 @@
#pragma once
#include <Arduino.h>
namespace EngineConsts {
constexpr float GEAR_RATIO[6] = {
3.31f,
1.95f,
1.28f,
0.97f,
0.75f,
-3.66f
};
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
constexpr float ENGINE_FORCE_FACTOR = 3000.0f; // N przy maks. RPM i wciśniętym sprzęgle
constexpr float BRAKE_FORCE_MAX = 5000.0f; // N przy pełnym pedale hamulca
constexpr float DRAG_COEFF = 0.3f; // Cd
constexpr float FRONTAL_AREA = 2.2f; // m^2
}
class Engine {
public:
Engine(uint8_t throttlePin,
uint8_t clutchPin,
uint8_t brakePin);
void begin();
void update(float dt, uint8_t gearIdx);
int getRPM() const;
int getSpeedKmh() const;
private:
const uint8_t _throttlePin;
const uint8_t _clutchPin;
const uint8_t _brakePin;
float _engineRPM = EngineConsts::RPM_IDLE;
float _speedMs = 0.0f;
float readNormalized(uint8_t pin) const;
};