Browse Source

new FSM

tags/FSM2.0
Dominik Bartsch 2 years ago
parent
commit
eeac10c66f

+ 1
- 1
lib/PCA9685-Arduino

Subproject commit a70be39257e317d35e9118b385006a1e030e6452
Subproject commit 23e06c06a6026801a856141f64a6de54dd493b47

+ 12
- 11
lib/treppe/FSMTreppe2/FSMTreppe2.cpp View File

// Code generation objectives: Unspecified // Code generation objectives: Unspecified
// Validation result: Not run // Validation result: Not run
// //
#include "FSMTreppe.h"
#include "FSMTreppe_private.h"
#include "FSMTreppe2.h"
// #include "FSMTreppe_private.h"
#include <stdint.h>


// Named constants for Chart: '<Root>/FSMTreppe' // Named constants for Chart: '<Root>/FSMTreppe'
const uint8_T FSMTreppe_IN_abdimmen_hoch = 1U;
const uint8_T FSMTreppe_IN_abdimmen_runter = 2U;
const uint8_T FSMTreppe_IN_aufdimmen_hoch = 3U;
const uint8_T FSMTreppe_IN_aufdimmen_runter = 4U;
const uint8_T FSMTreppe_IN_inaktiv = 5U;
const uint8_T FSMTreppe_IN_ruhezustand = 6U;
const uint8_T FSMTreppe_IN_warten_hoch = 7U;
const uint8_T FSMTreppe_IN_warten_runter = 8U;
const uint8_t FSMTreppe_IN_abdimmen_hoch = 1U;
const uint8_t FSMTreppe_IN_abdimmen_runter = 2U;
const uint8_t FSMTreppe_IN_aufdimmen_hoch = 3U;
const uint8_t FSMTreppe_IN_aufdimmen_runter = 4U;
const uint8_t FSMTreppe_IN_inaktiv = 5U;
const uint8_t FSMTreppe_IN_ruhezustand = 6U;
const uint8_t FSMTreppe_IN_warten_hoch = 7U;
const uint8_t FSMTreppe_IN_warten_runter = 8U;


// Model step function // Model step function
void FSMTreppeModelClass::step() void FSMTreppeModelClass::step()
// Inport: '<Root>/sensor_unten' // Inport: '<Root>/sensor_unten'


if (FSMTreppe_DW.temporalCounter_i1 < 511U) { if (FSMTreppe_DW.temporalCounter_i1 < 511U) {
FSMTreppe_DW.temporalCounter_i1 = static_cast<uint16_T>
FSMTreppe_DW.temporalCounter_i1 = static_cast<uint16_t>
(FSMTreppe_DW.temporalCounter_i1 + 1U); (FSMTreppe_DW.temporalCounter_i1 + 1U);
} }



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

// //
#ifndef RTW_HEADER_FSMTreppe_h_ #ifndef RTW_HEADER_FSMTreppe_h_
#define RTW_HEADER_FSMTreppe_h_ #define RTW_HEADER_FSMTreppe_h_
#include "rtwtypes.h"
#include "FSMTreppe_types.h"
#include <stdint.h>


// Macros for accessing real-time model data structure // Macros for accessing real-time model data structure
#ifndef rtmGetErrorStatus #ifndef rtmGetErrorStatus
public: public:
// Block states (default storage) for system '<Root>' // Block states (default storage) for system '<Root>'
struct DW_FSMTreppe_T { struct DW_FSMTreppe_T {
uint16_T temporalCounter_i1; // '<Root>/FSMTreppe'
uint8_T is_active_c3_FSMTreppe; // '<Root>/FSMTreppe'
uint8_T is_c3_FSMTreppe; // '<Root>/FSMTreppe'
uint16_t temporalCounter_i1; // '<Root>/FSMTreppe'
uint8_t is_active_c3_FSMTreppe; // '<Root>/FSMTreppe'
uint8_t is_c3_FSMTreppe; // '<Root>/FSMTreppe'
}; };


// External inputs (root inport signals with default storage) // External inputs (root inport signals with default storage)
struct ExtU_FSMTreppe_T { struct ExtU_FSMTreppe_T {
boolean_T sensor_unten; // '<Root>/sensor_unten'
boolean_T sensor_oben; // '<Root>/sensor_oben'
boolean_T anim_beendet; // '<Root>/anim_beendet'
real_T ldr_schwelle; // '<Root>/ldr_schwelle'
bool sensor_unten; // '<Root>/sensor_unten'
bool sensor_oben; // '<Root>/sensor_oben'
bool anim_beendet; // '<Root>/anim_beendet'
double 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)
struct ExtY_FSMTreppe_T { struct ExtY_FSMTreppe_T {
uint8_T laufrichtung; // '<Root>/laufrichtung'
uint8_T status; // '<Root>/status'
uint8_T dimmrichtung; // '<Root>/dimmrichtung'
uint8_t laufrichtung; // '<Root>/laufrichtung'
uint8_t status; // '<Root>/status'
uint8_t dimmrichtung; // '<Root>/dimmrichtung'
}; };


// Real-time Model Data Structure // Real-time Model Data Structure
struct RT_MODEL_FSMTreppe_T { struct RT_MODEL_FSMTreppe_T {
const char_T * volatile errorStatus;
const char * volatile errorStatus;
}; };


// model initialize function // model initialize function

+ 9
- 8
lib/treppe/treppe.cpp View File

static FSMTreppeModelClass::ExtU_FSMTreppe_T last_in; static FSMTreppeModelClass::ExtU_FSMTreppe_T last_in;
static FSMTreppeModelClass::ExtY_FSMTreppe_T last_out; static FSMTreppeModelClass::ExtY_FSMTreppe_T last_out;
if( if(
fsm_inputs.anim_finished != last_in.anim_finished ||
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_outputs.anim_active != last_out.anim_active
fsm_inputs.sensor_unten != last_in.sensor_unten
) { ) {
last_in.anim_finished = fsm_inputs.anim_finished;
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_out.anim_active = fsm_outputs.anim_active;


Serial.printf("FSM inputs: s_u: %d, s_o: %d, an_fin: %d =>", Serial.printf("FSM inputs: s_u: %d, s_o: %d, an_fin: %d =>",
fsm_inputs.sensor_oben, fsm_inputs.sensor_unten, fsm_inputs.anim_finished);
fsm_inputs.sensor_oben, fsm_inputs.sensor_unten, fsm_inputs.anim_beendet);
Serial.print(" step => "); Serial.print(" step => ");
Serial.printf("FSM outputs: an_act: %d\n", fsm_outputs.anim_active);
Serial.printf("FSM outputs: LR: %d DR: %d ST: %d\n", fsm_outputs.laufrichtung, fsm_outputs.dimmrichtung, fsm_outputs.status);
} }
} }


fsm_inputs.sensor_oben = read_sensor(SENSOR_OBEN); fsm_inputs.sensor_oben = read_sensor(SENSOR_OBEN);
fsm_inputs.sensor_unten = read_sensor(SENSOR_UNTEN); fsm_inputs.sensor_unten = read_sensor(SENSOR_UNTEN);
fsm_inputs.anim_finished = static_cast<bool>(finish);
fsm_inputs.anim_beendet = static_cast<bool>(finish);


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();


direction = fsm_outputs.laufrichtung;
state = fsm_outputs.dimmrichtung;

// setTick(ticks_treppe); // setTick(ticks_treppe);
// setAnAus(1); // setAnAus(1);
// setDirection(0); // setDirection(0);

+ 2
- 2
lib/treppe/treppe.h View File

#pragma once #pragma once


#include "FSMTreppe/FSMTreppe.h"
#include "FSMTreppe2/FSMTreppe2.h"
#include "PCA9685.h" #include "PCA9685.h"


#define SENSOR_OBEN 2 #define SENSOR_OBEN 2
uint8_t switch_direction = 0; uint8_t switch_direction = 0;
uint8_t state = 0; uint8_t state = 0;
uint8_t switch_state = 0; uint8_t switch_state = 0;
uint8_t finish = 1;
bool finish = 1;


// alternative // alternative
uint32_t tick = 0; uint32_t tick = 0;

Loading…
Cancel
Save