Browse Source

corrected double in FSM2, debug in treppe.cpp !

tags/v1.0.0
Simon Schmidt 3 years ago
parent
commit
f677f18681

+ 2
- 2
lib/treppe/FSMTreppe2/FSMTreppe2.cpp View File

@@ -122,7 +122,7 @@ void FSMTreppeModelClass::step()
case FSMTreppe_IN_inaktiv:
// Outport: '<Root>/status'
FSMTreppe_Y.status = 0U;
if (FSMTreppe_U.ldr_schwelle == 1.0) {
if (FSMTreppe_U.ldr_schwelle) {
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_ruhezustand;

// Outport: '<Root>/status'
@@ -157,7 +157,7 @@ void FSMTreppeModelClass::step()

// Outport: '<Root>/status'
FSMTreppe_Y.status = 5U;
} else if (FSMTreppe_U.ldr_schwelle == 0.0) {
} else if (!FSMTreppe_U.ldr_schwelle) {
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_inaktiv;

// Outport: '<Root>/status'

+ 1
- 1
lib/treppe/FSMTreppe2/FSMTreppe2.h View File

@@ -37,7 +37,7 @@ class FSMTreppeModelClass {
bool sensor_unten; // '<Root>/sensor_unten'
bool sensor_oben; // '<Root>/sensor_oben'
bool anim_beendet; // '<Root>/anim_beendet'
double ldr_schwelle; // '<Root>/ldr_schwelle'
bool ldr_schwelle; // '<Root>/ldr_schwelle'
};

// External outputs (root outports fed by signals with default storage)

+ 30
- 23
lib/treppe/treppe.cpp View File

@@ -12,12 +12,15 @@ bool Treppe::dimm_stufe(uint8_t stufe)
current_pwm += differenz_pwm_pro_tick;
else
current_pwm -= differenz_pwm_pro_tick;
Serial.printf("dimm_stufe %d %f\n", stufe, current_pwm);
Serial.printf("%3.0f", current_pwm);
pwmController.setChannelPWM(stufe, static_cast<uint16_t>(current_pwm));

current_tick++;
if (current_tick >= ticks_pro_stufe)
if (current_tick >= ticks_pro_stufe) {
Serial.println("");
return false;
}
Serial.print(" - ");
return true;
}

@@ -43,9 +46,8 @@ void Treppe::anim_tick()
{
if (!dimm_stufe(stufe))
{
Serial.printf("anim_tick(): stufe: %d, start: %d, ziel: %d, current %f\n",
stufe, start_pwm, ziel_pwm, current_pwm);

// Serial.printf("anim_tick(): stufe: %d, start: %d, ziel: %d, current %f\n",
// stufe, start_pwm, ziel_pwm, current_pwm);
if (fsm_outputs.laufrichtung == LR_HOCH)
{
if (stufe >= stufen - 1)
@@ -102,6 +104,7 @@ void Treppe::print_state_on_change()
fsm_inputs.anim_beendet != last_in.anim_beendet ||
fsm_inputs.sensor_oben != last_in.sensor_oben ||
fsm_inputs.sensor_unten != last_in.sensor_unten ||
fsm_inputs.ldr_schwelle != last_in.ldr_schwelle ||
fsm_outputs.dimmrichtung != last_out.dimmrichtung ||
fsm_outputs.laufrichtung != last_out.laufrichtung ||
fsm_outputs.status != last_out.status)
@@ -109,13 +112,14 @@ void Treppe::print_state_on_change()
last_in.anim_beendet = fsm_inputs.anim_beendet;
last_in.sensor_oben = fsm_inputs.sensor_oben;
last_in.sensor_unten = fsm_inputs.sensor_unten;
last_in.ldr_schwelle = fsm_inputs.ldr_schwelle;
last_out.dimmrichtung = fsm_outputs.dimmrichtung;
last_out.laufrichtung = fsm_outputs.laufrichtung;
last_out.status = fsm_outputs.status;

Serial.printf("FSM IN: s_u: %d, s_o: %d, beendet: %d =>",
fsm_inputs.sensor_oben, fsm_inputs.sensor_unten, fsm_inputs.anim_beendet);
Serial.print(" step => ");
Serial.printf("FSM IN: s_u: %d, s_o: %d, a_b: %d, l_s: %d => ",
fsm_inputs.sensor_oben, fsm_inputs.sensor_unten,
fsm_inputs.anim_beendet, fsm_inputs.ldr_schwelle);
Serial.printf("OUT: LR: %d DR: %d ST: %d\n",
fsm_outputs.laufrichtung, fsm_outputs.dimmrichtung, fsm_outputs.status);
}
@@ -210,31 +214,35 @@ bool Treppe::check_ldr()
return active;
}

int i = 0;

void Treppe::task()
{
fsm_inputs.ldr_schwelle = check_ldr();
i = !i;
fsm_inputs.ldr_schwelle = i;

fsm_inputs.sensor_oben = 0UL;
fsm_inputs.sensor_unten = 0UL;
fsm_inputs.anim_beendet = 1UL;

fsm_inputs.sensor_oben = read_sensor(SENSOR_OBEN);
fsm_inputs.sensor_unten = read_sensor(SENSOR_UNTEN);
fsm_inputs.anim_beendet = static_cast<bool>(anim_beendet);
// fsm_inputs.ldr_schwelle = check_ldr();
// fsm_inputs.sensor_oben = read_sensor(SENSOR_OBEN);
// fsm_inputs.sensor_unten = read_sensor(SENSOR_UNTEN);
// fsm_inputs.anim_beendet = static_cast<bool>(anim_beendet);

FSMTreppe_Obj.setExternalInputs(&fsm_inputs);
FSMTreppe_Obj.step();
fsm_outputs = FSMTreppe_Obj.getExternalOutputs();
print_state_on_change();

if (fsm_outputs.status > ST_RUHEZUSTAND)
if( fsm_outputs.status == ST_AUFDIMMEN_HOCH ||
fsm_outputs.status == ST_ABDIMMEN_HOCH ||
fsm_outputs.status == ST_AUFDIMMEN_RUNTER ||
fsm_outputs.status == ST_ABDIMMEN_RUNTER )
{
if (anim_beendet == true &&
(fsm_outputs.status == ST_AUFDIMMEN_HOCH ||
fsm_outputs.status == ST_ABDIMMEN_HOCH ||
fsm_outputs.status == ST_AUFDIMMEN_RUNTER ||
fsm_outputs.status == ST_ABDIMMEN_RUNTER)
)
{
if(anim_beendet)
start_animation();
}
if (!anim_beendet)
else
anim_tick();
}
}
@@ -244,7 +252,6 @@ void Treppe::berechne_dimmer()
ticks_pro_stufe = time_per_stair / INT_TIME; // [ms]
differenz_pwm_pro_tick = (float)(active_pwm - idle_pwm_internal)
/ (float)ticks_pro_stufe;

}

void Treppe::setup()

+ 13
- 1
lib/treppe/treppe.h View File

@@ -5,7 +5,6 @@
#include "PCA9685.h"

// #define LDRDEBUG // comment in to override LDR measurement

#define LDR_HYS 1 // Hysteresis for switching off FSM [lux]

#define SENSOR_OBEN 16
@@ -40,6 +39,7 @@ private:
FSMTreppeModelClass::ExtU_FSMTreppe_T fsm_inputs;
FSMTreppeModelClass::ExtY_FSMTreppe_T fsm_outputs;
enum fsm_status_t {
// 2.0
ST_INAKTIV_LDR =0,
ST_RUHEZUSTAND =1,
ST_AUFDIMMEN_HOCH =2,
@@ -48,6 +48,18 @@ private:
ST_AUFDIMMEN_RUNTER =5,
ST_WARTEN_RUNTER =6,
ST_ABDIMMEN_RUNTER =7
// 3.0
// ST_INAKTIV_LDR =0,
// ST_AUFDIMMEN_LDR =1,
// ST_ABDIMMEN_LDR =2,
// ST_RUHEZUSTAND =3,
// ST_AUFDIMMEN_HOCH =4,
// ST_WARTEN_HOCH =5,
// ST_ABDIMMEN_HOCH =6,
// ST_AUFDIMMEN_RUNTER =7,
// ST_WARTEN_RUNTER =8,
// ST_ABDIMMEN_RUNTER =9
};
enum fsm_laufrichtung_t {
LR_RUNTER=0,

Loading…
Cancel
Save