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

case FSMTreppe_IN_inaktiv: case FSMTreppe_IN_inaktiv:
// Outport: '<Root>/status' // Outport: '<Root>/status'
FSMTreppe_Y.status = 0U; FSMTreppe_Y.status = 0U;
if (FSMTreppe_U.ldr_schwelle == 1.0) {
if (FSMTreppe_U.ldr_schwelle) {
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_ruhezustand; FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_ruhezustand;


// Outport: '<Root>/status' // Outport: '<Root>/status'


// Outport: '<Root>/status' // Outport: '<Root>/status'
FSMTreppe_Y.status = 5U; 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; FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_inaktiv;


// Outport: '<Root>/status' // Outport: '<Root>/status'

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

bool sensor_unten; // '<Root>/sensor_unten' bool sensor_unten; // '<Root>/sensor_unten'
bool sensor_oben; // '<Root>/sensor_oben' bool sensor_oben; // '<Root>/sensor_oben'
bool anim_beendet; // '<Root>/anim_beendet' 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) // External outputs (root outports fed by signals with default storage)

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

current_pwm += differenz_pwm_pro_tick; current_pwm += differenz_pwm_pro_tick;
else else
current_pwm -= differenz_pwm_pro_tick; 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)); pwmController.setChannelPWM(stufe, static_cast<uint16_t>(current_pwm));


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


{ {
if (!dimm_stufe(stufe)) 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 (fsm_outputs.laufrichtung == LR_HOCH)
{ {
if (stufe >= stufen - 1) if (stufe >= stufen - 1)
fsm_inputs.anim_beendet != last_in.anim_beendet || fsm_inputs.anim_beendet != last_in.anim_beendet ||
fsm_inputs.sensor_oben != last_in.sensor_oben || fsm_inputs.sensor_oben != last_in.sensor_oben ||
fsm_inputs.sensor_unten != last_in.sensor_unten || fsm_inputs.sensor_unten != last_in.sensor_unten ||
fsm_inputs.ldr_schwelle != last_in.ldr_schwelle ||
fsm_outputs.dimmrichtung != last_out.dimmrichtung || fsm_outputs.dimmrichtung != last_out.dimmrichtung ||
fsm_outputs.laufrichtung != last_out.laufrichtung || fsm_outputs.laufrichtung != last_out.laufrichtung ||
fsm_outputs.status != last_out.status) fsm_outputs.status != last_out.status)
last_in.anim_beendet = fsm_inputs.anim_beendet; last_in.anim_beendet = fsm_inputs.anim_beendet;
last_in.sensor_oben = fsm_inputs.sensor_oben; last_in.sensor_oben = fsm_inputs.sensor_oben;
last_in.sensor_unten = fsm_inputs.sensor_unten; last_in.sensor_unten = fsm_inputs.sensor_unten;
last_in.ldr_schwelle = fsm_inputs.ldr_schwelle;
last_out.dimmrichtung = fsm_outputs.dimmrichtung; last_out.dimmrichtung = fsm_outputs.dimmrichtung;
last_out.laufrichtung = fsm_outputs.laufrichtung; last_out.laufrichtung = fsm_outputs.laufrichtung;
last_out.status = fsm_outputs.status; 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", Serial.printf("OUT: LR: %d DR: %d ST: %d\n",
fsm_outputs.laufrichtung, fsm_outputs.dimmrichtung, fsm_outputs.status); fsm_outputs.laufrichtung, fsm_outputs.dimmrichtung, fsm_outputs.status);
} }
return active; return active;
} }


int i = 0;

void Treppe::task() 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.setExternalInputs(&fsm_inputs);
FSMTreppe_Obj.step(); FSMTreppe_Obj.step();
fsm_outputs = FSMTreppe_Obj.getExternalOutputs(); fsm_outputs = FSMTreppe_Obj.getExternalOutputs();
print_state_on_change(); 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(); start_animation();
}
if (!anim_beendet)
else
anim_tick(); anim_tick();
} }
} }
ticks_pro_stufe = time_per_stair / INT_TIME; // [ms] ticks_pro_stufe = time_per_stair / INT_TIME; // [ms]
differenz_pwm_pro_tick = (float)(active_pwm - idle_pwm_internal) differenz_pwm_pro_tick = (float)(active_pwm - idle_pwm_internal)
/ (float)ticks_pro_stufe; / (float)ticks_pro_stufe;

} }


void Treppe::setup() void Treppe::setup()

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

#include "PCA9685.h" #include "PCA9685.h"


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

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


#define SENSOR_OBEN 16 #define SENSOR_OBEN 16
FSMTreppeModelClass::ExtU_FSMTreppe_T fsm_inputs; FSMTreppeModelClass::ExtU_FSMTreppe_T fsm_inputs;
FSMTreppeModelClass::ExtY_FSMTreppe_T fsm_outputs; FSMTreppeModelClass::ExtY_FSMTreppe_T fsm_outputs;
enum fsm_status_t { enum fsm_status_t {
// 2.0
ST_INAKTIV_LDR =0, ST_INAKTIV_LDR =0,
ST_RUHEZUSTAND =1, ST_RUHEZUSTAND =1,
ST_AUFDIMMEN_HOCH =2, ST_AUFDIMMEN_HOCH =2,
ST_AUFDIMMEN_RUNTER =5, ST_AUFDIMMEN_RUNTER =5,
ST_WARTEN_RUNTER =6, ST_WARTEN_RUNTER =6,
ST_ABDIMMEN_RUNTER =7 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 { enum fsm_laufrichtung_t {
LR_RUNTER=0, LR_RUNTER=0,

Loading…
Cancel
Save