Pendelzug Erstversion

new file:   .gitignore
new file:   .vscode/extensions.json
new file:   ErsterTest.code-workspace
new file:   include/README
new file:   lib/AnalogFiveButtons/AnalogFiveButtons.cpp
new file:   lib/AnalogFiveButtons/AnalogFiveButtons.h
new file:   lib/Imotor/Imotor.cpp
new file:   lib/Imotor/Imotor.h
new file:   lib/L298n/L298n.cpp
new file:   lib/L298n/L298n.h
new file:   lib/README
new file:   lib/fahrt/fahrt.cpp
new file:   lib/fahrt/fahrt.h
new file:   lib/gleis/gleis.cpp
new file:   lib/gleis/gleis.h
new file:   lib/gleisabschnitt/gleisabschnitt.cpp
new file:   lib/gleisabschnitt/gleisabschnitt.h
new file:   lib/locomotive/locomotive.cpp
new file:   lib/locomotive/locomotive.h
new file:   lib/motor/dfquad.h
new file:   lib/motor/motor.cpp
new file:   lib/motor/motor.h
new file:   lib/weiche/weiche.cpp
new file:   lib/weiche/weiche.h
new file:   platformio.ini
new file:   src/main.cpp
new file:   test/README
This commit is contained in:
2023-05-14 21:22:04 +02:00
commit 349d1d644e
27 changed files with 1051 additions and 0 deletions

77
lib/fahrt/fahrt.cpp Normal file
View File

@@ -0,0 +1,77 @@
# include<Arduino.h>
#include<fahrt.h>
#include<locomotive.h>
Fahrt::Fahrt(Locomotive locomotive, MotorDirection Direction, Gleis gleis, Gleisabschnitt gleisabschnitt): _locomotive(locomotive), _gleis(gleis), _gleisabschnitt(gleisabschnitt)
{
_direction = Direction;
_speed = locomotive.getDefaultSpeed();
_bremsweg=0;
}
Fahrt::Fahrt(Locomotive locomotive, byte speed, MotorDirection Direction, Gleis gleis, Gleisabschnitt gleisabschnitt): _locomotive(locomotive), _gleis(gleis), _gleisabschnitt(gleisabschnitt)
{
_direction = Direction;
_speed = speed;
_bremsweg=0;
}
Fahrt::Fahrt(Locomotive locomotive, byte speed, MotorDirection Direction, Gleis gleis, Gleisabschnitt gleisabschnitt, float bremsweg): _locomotive(locomotive), _gleis(gleis), _gleisabschnitt(gleisabschnitt)
{
_direction = Direction;
_speed = speed;
_bremsweg=bremsweg;
}
void Fahrt::Vorbereiten()
{
_gleis.Waehlen();
_abschnittErkannt=false;
Serial.print ("Auftrag: Speed=");
Serial.print (_speed);
Serial.print (" Bremsweg=");
Serial.print (_bremsweg);
Serial.println();
}
void Fahrt::Start()
{
_locomotive.setDirection(_direction);
_locomotive.Accelerate(_speed);
}
void Fahrt::Loop()
{
_locomotive.loop();
if (_gleisabschnitt.IstBesetzt() && !_abschnittErkannt)
{
delay(20);
if (_gleisabschnitt.IstBesetzt() && !_abschnittErkannt)
{
if (_bremsweg==0)
_locomotive.Break();
else
_locomotive.Accelerate(0, _bremsweg);
_abschnittErkannt=true;
}
}
}
bool Fahrt::IstAngekommen()
{
return (_locomotive.currentSpeed()==0);
}
float Fahrt::ChangeBremsweg(float DeltaBremsweg)
{
_bremsweg += DeltaBremsweg;
return(_bremsweg);
}
byte Fahrt::ChangeSpeed(byte DeltaSpeed)
{
_speed += DeltaSpeed;
return(_speed);
}

33
lib/fahrt/fahrt.h Normal file
View File

@@ -0,0 +1,33 @@
#ifndef Fahrt_h
#define Fahrt_h
#include<locomotive.h>
#include<gleis.h>
#include <Imotor.h>
class Fahrt
{
public:
Fahrt(Locomotive locomotive, MotorDirection Direction, Gleis gleis, Gleisabschnitt gleisabschnitt);
Fahrt(Locomotive locomotive, byte speed, MotorDirection Direction, Gleis gleis, Gleisabschnitt gleisabschnitt);
Fahrt(Locomotive locomotive, byte speed, MotorDirection Direction, Gleis gleis, Gleisabschnitt gleisabschnitt, float bremsweg);
void Vorbereiten();
void Start();
void Loop();
bool IstAngekommen();
float ChangeBremsweg(float DeltaBremsweg);
byte ChangeSpeed(byte DeltaSpeed);
private:
Locomotive _locomotive;
MotorDirection _direction;
Gleis _gleis;
Gleisabschnitt _gleisabschnitt;
bool _abschnittErkannt;
byte _speed;
float _bremsweg;
};
#endif