Programm fuer ersten Testlauf

ohne PWM und ohne ADC
This commit is contained in:
Toberfra 2022-02-09 14:36:58 +01:00
parent c190169d4e
commit eb302f45b3
12 changed files with 199 additions and 159 deletions

View File

@ -1,23 +1,89 @@
#include "KlappenAblauf.h"
// Constructors/Destructors
//
KlappenAblauf::~KlappenAblauf()
{
}
//
// Methods
//
statusKlappen KlappenAblauf::setOpen(bool open)
{
if(aktuellerState == WARTE){
if(open)
aktuellerState = START_AUF;
else
aktuellerState = START_ZU;
return OK;
}
return ERROR_BUSY;
}
statusKlappen KlappenAblauf::setOpen(bool open , int id)
{
KlappenAblauf *zeiger;
zeiger = (KlappenAblauf *) searchIdElement(id);
if(zeiger)
return zeiger->setOpen(open);
return ERROR_ID;
}
void KlappenAblauf::memberSetup(){
AnalogDigital::memberSetup();
fsmInit();
}
void KlappenAblauf::memberLoop(){
AnalogDigital::memberLoop();
fsmStep();
}
void KlappenAblauf::fsmInit(){
aktuellerState = INIT;
}
// Accessor methods
//
void KlappenAblauf::fsmStep(){
switch (aktuellerState)
{
case INIT:
aktuellerState = WARTE;
break;
// Other methods
//
case WARTE:
break;
case START_AUF:
setMotorAktion(1);
timer = 5000;
aktuellerState = FAEHRT;
break;
case START_ZU:
setMotorAktion(-1);
timer = 5000;
aktuellerState = FAEHRT;
break;
case FAEHRT:
timer -= getDeltamsec();
if(timer <= 0){
setMotorAktion(0);
aktuellerState = FERTIG;
}
break;
case FERTIG:
aktuellerState = WARTE;
break;
default:
aktuellerState = INIT;
break;
}
}

View File

@ -2,7 +2,7 @@
#ifndef KLAPPENABLAUF_H
#define KLAPPENABLAUF_H
#include "statusKlappen.h"
#include "analogDigital.h"
/**
@ -33,7 +33,17 @@ public:
// Public attributes
//
/**
* @param open
*/
statusKlappen setOpen(bool open);
static statusKlappen setOpen(bool open , int id);
protected:
void memberSetup();
void memberLoop();
// Static Protected attributes
//
@ -41,11 +51,23 @@ protected:
//
private:
// Static Private attributes
//
// Private attributes
//
int16_t timer;
typedef enum fsmStatesEnum{
INIT,
WARTE,
START_AUF,
START_ZU,
FAEHRT,
FERTIG,
}fsmStates;
fsmStates aktuellerState;
void fsmInit();
void fsmStep();
};

View File

@ -1,17 +1,7 @@
#include "KlappenSteuerung.h"
// Constructors/Destructors
//
/**
* @param pinA
* @param pinB
* @param pinPwm
* @param pinSense
* @param id
*/
KlappenSteuerung::KlappenSteuerung(int pinA, int pinB, int pinSense, int id)
{
setMotorPins(pinA , pinB);
@ -21,25 +11,6 @@
}
KlappenSteuerung::~KlappenSteuerung()
{
}
void KlappenSteuerung::setupStatic(){
AnalogDigital::setupStatic();
}
//
// Methods
//
// Accessor methods
//
// Other methods
//
@ -49,13 +20,3 @@ void KlappenSteuerung::setupStatic(){
/**
* @param open
*/
void KlappenSteuerung::setOpen(bool open)
{
}

View File

@ -5,67 +5,25 @@
#include "statusKlappen.h"
#include "KlappenAblauf.h"
/**
* class KlappenSteuerung
*
*/
class KlappenSteuerung : public KlappenAblauf
{
public:
// Constructors/Destructors
//
/**
* Empty Constructor
*/
//KlappenSteuerung();
/**
* Empty Destructor
*/
virtual ~KlappenSteuerung();
// Static Public attributes
//
// Public attributes
//
static void setupStatic();
/**
* @param pinA
* @param pinB
* @param pinSense
* @param id
*/
KlappenSteuerung(int pinA, int pinB, int pinSense, int id);
/**
*/
//static void setup();
/**
*/
//static void loop();
/**
* @param open
*/
void setOpen(bool open);
protected:
int pinSense;
statusKlappen status;
//void memberSetup();
//void memberLoop();

View File

@ -1,11 +1,21 @@
#include"arduinoAnpassung.h"
#include <Arduino.h>
unsigned long ArduinoAnpassung::alteZeit;
unsigned int ArduinoAnpassung::deltaZeit;
ArduinoAnpassung::~ArduinoAnpassung(){
}
void ArduinoAnpassung::setup(){
zeit();
zeit();
MyList *zeiger;
zeiger = ArduinoAnpassung::getErstesElement();
while(zeiger){
@ -15,6 +25,7 @@ void ArduinoAnpassung::setup(){
}
void ArduinoAnpassung::loop(){
zeit();
MyList *zeiger;
zeiger = ArduinoAnpassung::getErstesElement();
while(zeiger){
@ -23,5 +34,30 @@ void ArduinoAnpassung::loop(){
}
}
void ArduinoAnpassung::memberSetup(){
}
void ArduinoAnpassung::memberLoop(){
}
void ArduinoAnpassung::zeit(){
unsigned long neueZeit;
neueZeit = millis();
deltaZeit = (unsigned int) (neueZeit - alteZeit);
alteZeit = neueZeit;
}
unsigned int ArduinoAnpassung::getDeltamsec(){
return deltaZeit;
}

View File

@ -6,15 +6,20 @@
class ArduinoAnpassung : public MyList{
public:
~ArduinoAnpassung();
static void setup();
static void loop();
void memberSetup();
void memberLoop();
virtual void memberLoop();
virtual void memberSetup();
static unsigned int getDeltamsec();
protected:
@ -24,5 +29,11 @@ private:
static void zeit();
static unsigned long alteZeit;
static unsigned int deltaZeit;
};
#endif

View File

@ -34,17 +34,9 @@ void loop() {
}
void Ablauf(){
static unsigned long alteZeit;
static unsigned int summeZeit;
unsigned long neueZeit;
unsigned int deltaZeit;
neueZeit = millis();
deltaZeit = (unsigned int) (neueZeit - alteZeit);
alteZeit = neueZeit;
summeZeit += deltaZeit;
summeZeit += KlappenSteuerung::getDeltamsec();
if(summeZeit >= 1000){ // eine Sekunde
summeZeit -= 1000;
AblaufSekunde();
@ -59,11 +51,11 @@ void AblaufSekunde(){
//digitalWrite(LED_BUILTIN , !(sekunden & 3));
switch(sekunden){
case 1:
klappe1.setOpen(true);
KlappenSteuerung::setOpen(true , 5);
break;
case 11:
klappe1.setOpen(false);
KlappenSteuerung::setOpen(false , 5);
break;
case 20:

View File

@ -19,10 +19,8 @@ void Motor::setMotorPwmPin(uint8_t pinPwm){
void Motor::setup(){
ArduinoAnpassung::setup();
Timer1.initialize(1000); // 10kHz
//Timer1.attachInterrupt(Motor::interruptEinsprung);
Timer1.pwm(Motor::pinPwm, (0)); // 1023
//digitalWrite(LED_BUILTIN , 0 );
pinMode(pinPwm , OUTPUT);
digitalWrite(pinPwm , 1);
}
@ -36,56 +34,28 @@ void Motor::memberSetup(){
}
void Motor::memberLoop(){
if(richtung){
if(test == 32767)
richtung = !richtung;
else
test ++;
void Motor::setMotorAktion(int8_t richtung){
if(richtung > 0){
digitalWrite( pinA , 1);
digitalWrite( pinB , 0);
}else if(richtung < 0){
digitalWrite( pinA , 0);
digitalWrite( pinB , 1);
}else{
if(test == -32767)
richtung = !richtung;
else
test --;
digitalWrite( pinA , 1);
digitalWrite( pinB , 0);
}
setSollSpeed( test / 128);
//setSollSpeed(100);
}
void Motor::setSollSpeed(int16_t speed){
uint16_t pwm;
if(speed >255)
speed = 255;
if(speed < -255)
speed = -255;
if(speed > 0)
{
pwm = 512 + speed * 2;
digitalWrite(pinA , 0);
digitalWrite(pinB , 1);
}else if (speed < 0){
pwm = 512 - speed * 2;
digitalWrite(pinA , 1);
digitalWrite(pinB , 0);
}else{
pwm = 1023;
digitalWrite(pinA , 0);
digitalWrite(pinB , 0);
}
Timer1.pwm(Motor::pinPwm, pwm);
void Motor::setMotorAktion(int8_t richtung , int id ){
Motor *zeiger;
zeiger = (Motor*) searchIdElement(id);
if(zeiger)
zeiger->setMotorAktion(richtung);
}

View File

@ -16,8 +16,10 @@ public:
void setMotorPins(uint8_t pinA , uint8_t pinB);
static void setMotorPwmPin(uint8_t pinPwm);
void setMotorAktion(int8_t richtung);
static void setMotorAktion(int8_t richtung , int id);
void setSollSpeed(int16_t speed);
protected:
@ -26,7 +28,7 @@ protected:
void memberSetup();
void memberLoop();
//static void interruptEinsprung();
//void memberInterruptEinsprung();

View File

@ -25,3 +25,17 @@ void MyList::SetId(int id){
this->id = id;
}
MyList *MyList::searchIdElement(int id){
MyList *zeiger;
zeiger = getErstesElement();
while(zeiger){
if (zeiger->id == id)
return zeiger;
zeiger = zeiger->getNachfolgerElement();
}
return 0;
}

View File

@ -6,9 +6,10 @@ public:
MyList();
virtual ~MyList();
static MyList* getErstesElement();
static MyList* getIdElement();
//static MyList* getIdElement();
MyList* getNachfolgerElement();
void SetId(int id);
static MyList* searchIdElement(int id);

View File

@ -3,6 +3,13 @@
typedef enum statusKlappenenum{
NICHTS,
OK,
OFFEN,
GESCHLOSSEN,
ERROR,
ERROR_BUSY,
ERROR_ID
}statusKlappen;