From f28aa2df8b68e05fdfc8e0cf6fe20a1f86821490 Mon Sep 17 00:00:00 2001 From: Simon Schmidt Date: Sat, 3 Jul 2021 11:31:46 +0200 Subject: [PATCH] stripped out RTM Model interface and custom types from matlab --- lib/treppe/FSMTreppe/FSMTreppe.cpp | 15 +-- lib/treppe/FSMTreppe/FSMTreppe.h | 44 ++----- lib/treppe/FSMTreppe/FSMTreppe_private.h | 28 ---- lib/treppe/FSMTreppe/ert_main.cpp | 109 --------------- lib/treppe/FSMTreppe/rtwtypes.h | 160 ----------------------- lib/treppe/treppe.cpp | 1 + lib/treppe/treppe.h | 13 +- 7 files changed, 27 insertions(+), 343 deletions(-) delete mode 100644 lib/treppe/FSMTreppe/FSMTreppe_private.h delete mode 100644 lib/treppe/FSMTreppe/ert_main.cpp delete mode 100644 lib/treppe/FSMTreppe/rtwtypes.h diff --git a/lib/treppe/FSMTreppe/FSMTreppe.cpp b/lib/treppe/FSMTreppe/FSMTreppe.cpp index c5e52a2..4329d87 100644 --- a/lib/treppe/FSMTreppe/FSMTreppe.cpp +++ b/lib/treppe/FSMTreppe/FSMTreppe.cpp @@ -17,12 +17,11 @@ // Validation result: Not run // #include "FSMTreppe.h" -#include "FSMTreppe_private.h" // Named constants for Chart: '/FSMTreppe' -const uint8_T FSMTreppe_IN_animation_down = 1U; -const uint8_T FSMTreppe_IN_animation_up = 2U; -const uint8_T FSMTreppe_IN_idle = 3U; +const uint8_t FSMTreppe_IN_animation_down = 1U; +const uint8_t FSMTreppe_IN_animation_up = 2U; +const uint8_t FSMTreppe_IN_idle = 3U; // Model step function void FSMTreppeModelClass::step() @@ -33,7 +32,7 @@ void FSMTreppeModelClass::step() // Inport: '/sensor_unten' if (FSMTreppe_DW.temporalCounter_i1 < 511U) { - FSMTreppe_DW.temporalCounter_i1 = static_cast + FSMTreppe_DW.temporalCounter_i1 = static_cast (FSMTreppe_DW.temporalCounter_i1 + 1U); } @@ -165,12 +164,6 @@ FSMTreppeModelClass::~FSMTreppeModelClass() // Currently there is no destructor body generated. } -// Real-Time Model get method -FSMTreppeModelClass::RT_MODEL_FSMTreppe_T * FSMTreppeModelClass::getRTM() -{ - return (&FSMTreppe_M); -} - // // File trailer for generated code. // diff --git a/lib/treppe/FSMTreppe/FSMTreppe.h b/lib/treppe/FSMTreppe/FSMTreppe.h index c4de56e..46d4a0f 100644 --- a/lib/treppe/FSMTreppe/FSMTreppe.h +++ b/lib/treppe/FSMTreppe/FSMTreppe.h @@ -18,17 +18,8 @@ // #ifndef RTW_HEADER_FSMTreppe_h_ #define RTW_HEADER_FSMTreppe_h_ -#include "rtwtypes.h" -#include "FSMTreppe_types.h" -// Macros for accessing real-time model data structure -#ifndef rtmGetErrorStatus -#define rtmGetErrorStatus(rtm) ((rtm)->errorStatus) -#endif - -#ifndef rtmSetErrorStatus -#define rtmSetErrorStatus(rtm, val) ((rtm)->errorStatus = (val)) -#endif +#include // Class declaration for model FSMTreppe class FSMTreppeModelClass { @@ -36,30 +27,25 @@ class FSMTreppeModelClass { public: // Block states (default storage) for system '' struct DW_FSMTreppe_T { - uint16_T temporalCounter_i1; // '/FSMTreppe' - uint8_T is_active_c3_FSMTreppe; // '/FSMTreppe' - uint8_T is_c3_FSMTreppe; // '/FSMTreppe' - uint8_T got_anim_finished; // '/FSMTreppe' - uint8_T finished_up; // '/FSMTreppe' - uint8_T finished_dn; // '/FSMTreppe' - uint8_T got_sensor; // '/FSMTreppe' + uint16_t temporalCounter_i1; // '/FSMTreppe' + uint8_t is_active_c3_FSMTreppe; // '/FSMTreppe' + uint8_t is_c3_FSMTreppe; // '/FSMTreppe' + uint8_t got_anim_finished; // '/FSMTreppe' + uint8_t finished_up; // '/FSMTreppe' + uint8_t finished_dn; // '/FSMTreppe' + uint8_t got_sensor; // '/FSMTreppe' }; // External inputs (root inport signals with default storage) struct ExtU_FSMTreppe_T { - boolean_T sensor_unten; // '/sensor_unten' - boolean_T sensor_oben; // '/sensor_oben' - boolean_T anim_finished; // '/anim_finished' + bool sensor_unten; // '/sensor_unten' + bool sensor_oben; // '/sensor_oben' + bool anim_finished; // '/anim_finished' }; // External outputs (root outports fed by signals with default storage) struct ExtY_FSMTreppe_T { - uint8_T anim_active; // '/anim_active' - }; - - // Real-time Model Data Structure - struct RT_MODEL_FSMTreppe_T { - const char_T * volatile errorStatus; + uint8_t anim_active; // '/anim_active' }; // model initialize function @@ -93,9 +79,6 @@ class FSMTreppeModelClass { return FSMTreppe_Y; } - // Real-Time Model get method - FSMTreppeModelClass::RT_MODEL_FSMTreppe_T * getRTM(); - // private data and function members private: // Block states @@ -106,9 +89,6 @@ class FSMTreppeModelClass { // External outputs ExtY_FSMTreppe_T FSMTreppe_Y; - - // Real-Time Model - RT_MODEL_FSMTreppe_T FSMTreppe_M; }; //- diff --git a/lib/treppe/FSMTreppe/FSMTreppe_private.h b/lib/treppe/FSMTreppe/FSMTreppe_private.h deleted file mode 100644 index eeaae70..0000000 --- a/lib/treppe/FSMTreppe/FSMTreppe_private.h +++ /dev/null @@ -1,28 +0,0 @@ -// -// Academic License - for use in teaching, academic research, and meeting -// course requirements at degree granting institutions only. Not for -// government, commercial, or other organizational use. -// -// File: FSMTreppe_private.h -// -// Code generated for Simulink model 'FSMTreppe'. -// -// Model version : 1.22 -// Simulink Coder version : 9.5 (R2021a) 14-Nov-2020 -// C/C++ source code generated on : Fri Jul 2 17:45:36 2021 -// -// Target selection: ert.tlc -// Embedded hardware selection: ARM Compatible->ARM Cortex-M -// Code generation objectives: Unspecified -// Validation result: Not run -// -#ifndef RTW_HEADER_FSMTreppe_private_h_ -#define RTW_HEADER_FSMTreppe_private_h_ -#include "rtwtypes.h" -#endif // RTW_HEADER_FSMTreppe_private_h_ - -// -// File trailer for generated code. -// -// [EOF] -// diff --git a/lib/treppe/FSMTreppe/ert_main.cpp b/lib/treppe/FSMTreppe/ert_main.cpp deleted file mode 100644 index 37db9c8..0000000 --- a/lib/treppe/FSMTreppe/ert_main.cpp +++ /dev/null @@ -1,109 +0,0 @@ -// -// Academic License - for use in teaching, academic research, and meeting -// course requirements at degree granting institutions only. Not for -// government, commercial, or other organizational use. -// -// File: ert_main.cpp -// -// Code generated for Simulink model 'FSMTreppe'. -// -// Model version : 1.22 -// Simulink Coder version : 9.5 (R2021a) 14-Nov-2020 -// C/C++ source code generated on : Fri Jul 2 17:45:36 2021 -// -// Target selection: ert.tlc -// Embedded hardware selection: ARM Compatible->ARM Cortex-M -// Code generation objectives: Unspecified -// Validation result: Not run -// -#include -#include // This ert_main.c example uses printf/fflush -#include "FSMTreppe.h" // Model's header file -#include "rtwtypes.h" - -static FSMTreppeModelClass FSMTreppe_Obj;// Instance of model class - -// -// Associating rt_OneStep with a real-time clock or interrupt service routine -// is what makes the generated code "real-time". The function rt_OneStep is -// always associated with the base rate of the model. Subrates are managed -// by the base rate from inside the generated code. Enabling/disabling -// interrupts and floating point context switches are target specific. This -// example code indicates where these should take place relative to executing -// the generated code step function. Overrun behavior should be tailored to -// your application needs. This example simply sets an error status in the -// real-time model and returns from rt_OneStep. -// -void rt_OneStep(void); -void rt_OneStep(void) -{ - static boolean_T OverrunFlag = false; - - // Disable interrupts here - - // Check for overrun - if (OverrunFlag) { - rtmSetErrorStatus(FSMTreppe_Obj.getRTM(), "Overrun"); - return; - } - - OverrunFlag = true; - - // Save FPU context here (if necessary) - // Re-enable timer or interrupt here - // Set model inputs here - - // Step the model - FSMTreppe_Obj.step(); - - // Get model outputs here - - // Indicate task complete - OverrunFlag = false; - - // Disable interrupts here - // Restore FPU context here (if necessary) - // Enable interrupts here -} - -// -// The example "main" function illustrates what is required by your -// application code to initialize, execute, and terminate the generated code. -// Attaching rt_OneStep to a real-time clock is target specific. This example -// illustrates how you do this relative to initializing the model. -// -int_T main(int_T argc, const char *argv[]) -{ - // Unused arguments - (void)(argc); - (void)(argv); - - // Initialize model - FSMTreppe_Obj.initialize(); - - // Attach rt_OneStep to a timer or interrupt service routine with - // period 0.01 seconds (the model's base sample time) here. The - // call syntax for rt_OneStep is - // - // rt_OneStep(); - - printf("Warning: The simulation will run forever. " - "Generated ERT main won't simulate model step behavior. " - "To change this behavior select the 'MAT-file logging' option.\n"); - fflush((NULL)); - while (rtmGetErrorStatus(FSMTreppe_Obj.getRTM()) == (NULL)) { - // Perform other application tasks here - } - - // Disable rt_OneStep() here - - // Terminate model - FSMTreppe_Obj.terminate(); - return 0; -} - -// -// File trailer for generated code. -// -// [EOF] -// diff --git a/lib/treppe/FSMTreppe/rtwtypes.h b/lib/treppe/FSMTreppe/rtwtypes.h deleted file mode 100644 index 117ab1f..0000000 --- a/lib/treppe/FSMTreppe/rtwtypes.h +++ /dev/null @@ -1,160 +0,0 @@ -// -// Academic License - for use in teaching, academic research, and meeting -// course requirements at degree granting institutions only. Not for -// government, commercial, or other organizational use. -// -// File: rtwtypes.h -// -// Code generated for Simulink model 'FSMTreppe'. -// -// Model version : 1.22 -// Simulink Coder version : 9.5 (R2021a) 14-Nov-2020 -// C/C++ source code generated on : Fri Jul 2 17:45:36 2021 -// -// Target selection: ert.tlc -// Embedded hardware selection: ARM Compatible->ARM Cortex-M -// Code generation objectives: Unspecified -// Validation result: Not run -// - -#ifndef RTWTYPES_H -#define RTWTYPES_H - -// Logical type definitions -#if (!defined(__cplusplus)) -#ifndef false -#define false (0U) -#endif - -#ifndef true -#define true (1U) -#endif -#endif - -//=======================================================================* -// Target hardware information -// Device type: ARM Compatible->ARM Cortex-M -// Number of bits: char: 8 short: 16 int: 32 -// long: 32 -// native word size: 32 -// Byte ordering: LittleEndian -// Signed integer division rounds to: Zero -// Shift right on a signed integer as arithmetic shift: on -// ======================================================================= - -//=======================================================================* -// Fixed width word size data types: * -// int8_T, int16_T, int32_T - signed 8, 16, or 32 bit integers * -// uint8_T, uint16_T, uint32_T - unsigned 8, 16, or 32 bit integers * -// real32_T, real64_T - 32 and 64 bit floating point numbers * -// ======================================================================= -typedef signed char int8_T; -typedef unsigned char uint8_T; -typedef short int16_T; -typedef unsigned short uint16_T; -typedef int int32_T; -typedef unsigned int uint32_T; -typedef float real32_T; -typedef double real64_T; - -//===========================================================================* -// Generic type definitions: boolean_T, char_T, byte_T, int_T, uint_T, * -// real_T, time_T, ulong_T. * -// =========================================================================== -typedef double real_T; -typedef double time_T; -typedef unsigned char boolean_T; -typedef int int_T; -typedef unsigned int uint_T; -typedef unsigned long ulong_T; -typedef char char_T; -typedef unsigned char uchar_T; -typedef char_T byte_T; - -//===========================================================================* -// Complex number type definitions * -// =========================================================================== -#define CREAL_T - -typedef struct { - real32_T re; - real32_T im; -} creal32_T; - -typedef struct { - real64_T re; - real64_T im; -} creal64_T; - -typedef struct { - real_T re; - real_T im; -} creal_T; - -#define CINT8_T - -typedef struct { - int8_T re; - int8_T im; -} cint8_T; - -#define CUINT8_T - -typedef struct { - uint8_T re; - uint8_T im; -} cuint8_T; - -#define CINT16_T - -typedef struct { - int16_T re; - int16_T im; -} cint16_T; - -#define CUINT16_T - -typedef struct { - uint16_T re; - uint16_T im; -} cuint16_T; - -#define CINT32_T - -typedef struct { - int32_T re; - int32_T im; -} cint32_T; - -#define CUINT32_T - -typedef struct { - uint32_T re; - uint32_T im; -} cuint32_T; - -//=======================================================================* -// Min and Max: * -// int8_T, int16_T, int32_T - signed 8, 16, or 32 bit integers * -// uint8_T, uint16_T, uint32_T - unsigned 8, 16, or 32 bit integers * -// ======================================================================= -#define MAX_int8_T ((int8_T)(127)) -#define MIN_int8_T ((int8_T)(-128)) -#define MAX_uint8_T ((uint8_T)(255U)) -#define MAX_int16_T ((int16_T)(32767)) -#define MIN_int16_T ((int16_T)(-32768)) -#define MAX_uint16_T ((uint16_T)(65535U)) -#define MAX_int32_T ((int32_T)(2147483647)) -#define MIN_int32_T ((int32_T)(-2147483647-1)) -#define MAX_uint32_T ((uint32_T)(0xFFFFFFFFU)) - -// Block D-Work pointer type -typedef void * pointer_T; - -#endif // RTWTYPES_H - -// -// File trailer for generated code. -// -// [EOF] -// diff --git a/lib/treppe/treppe.cpp b/lib/treppe/treppe.cpp index 97e0319..f9c6738 100644 --- a/lib/treppe/treppe.cpp +++ b/lib/treppe/treppe.cpp @@ -155,6 +155,7 @@ void Treppe::setup(){ } void Treppe::task(){ + FSMTreppe_Obj.step(); if(finish){ direction = switch_direction; diff --git a/lib/treppe/treppe.h b/lib/treppe/treppe.h index e8ded50..a7efcbb 100644 --- a/lib/treppe/treppe.h +++ b/lib/treppe/treppe.h @@ -1,5 +1,6 @@ #pragma once +#include "FSMTreppe/FSMTreppe.h" #include "PCA9685.h" #define SENSOR1 2 @@ -10,6 +11,10 @@ class Treppe { private: + // initialize with i2c-Address 0, use Wire Library + PCA9685 pwmController; + FSMTreppeModelClass FSMTreppe_Obj;// Instance of model class + uint8_t stairs; uint16_t time_per_stair = 300; // dimmtime per stair [ms] uint16_t idle_brightness = 100; @@ -31,21 +36,23 @@ private: float differenz_pwm_pro_tick = 0.0; // alternative - - // initialize with i2c-Address 0, use Wire Library - PCA9685 pwmController; uint8_t softstart_led(uint8_t led, uint16_t startval, uint16_t stopval); void ledsequence(); void rampe(); public: Treppe(uint8_t _stairs) : stairs(_stairs){ + FSMTreppe_Obj.initialize(); + ticks_pro_stufe = time_per_stair / 20; // [ms] ticks_treppe = ticks_pro_stufe * stairs; differenz_pwm_pro_tick = (float) (active_brightness - idle_brightness) / (float) ticks_pro_stufe; } + ~Treppe() { + FSMTreppe_Obj.terminate(); + } void setup(); void task(); // call periodically