paul cox / Mbed 2 deprecated Nucleo_pmsmfoc

Dependencies:   mbed-dsp mbed Nucleo_pmsmfoc

Dependents:   Nucleo_pmsmfoc

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers rtwdemo_pmsmfoc.h Source File

rtwdemo_pmsmfoc.h

00001 /*
00002  * File: rtwdemo_pmsmfoc.h
00003  *
00004  * Code generated for Simulink model 'rtwdemo_pmsmfoc'.
00005  *
00006  * Model version                  : 1.2949
00007  * Simulink Coder version         : 8.7 (R2014b) 11-Aug-2014
00008  * C/C++ source code generated on : Sat Oct 11 00:06:05 2014
00009  *
00010  * Target selection: ert.tlc
00011  * Embedded hardware selection: Generic->32-bit Embedded Processor
00012  * Code generation objective: Execution efficiency
00013  * Validation result: Not run
00014  */
00015 
00016 #ifndef RTW_HEADER_rtwdemo_pmsmfoc_h_
00017 #define RTW_HEADER_rtwdemo_pmsmfoc_h_
00018 #include "rtwtypes.h"
00019 #include <float.h>
00020 #include <math.h>
00021 #include <string.h>
00022 #ifndef rtwdemo_pmsmfoc_COMMON_INCLUDES_
00023 # define rtwdemo_pmsmfoc_COMMON_INCLUDES_
00024 #include "rtwtypes.h"
00025 #endif                                 /* rtwdemo_pmsmfoc_COMMON_INCLUDES_ */
00026 
00027 /* Macros for accessing real-time model data structure */
00028 
00029 /* Forward declaration for rtModel */
00030 typedef struct tag_RTM RT_MODEL;
00031 
00032 #ifndef _DEFINED_TYPEDEF_FOR_EnumErrorType_
00033 #define _DEFINED_TYPEDEF_FOR_EnumErrorType_
00034 
00035 typedef enum {
00036   NoError = 0,                         /* Default value */
00037   MeasuredVelocityError
00038 } EnumErrorType;
00039 
00040 #endif
00041 
00042 #ifndef _DEFINED_TYPEDEF_FOR_EnumCommandType_
00043 #define _DEFINED_TYPEDEF_FOR_EnumCommandType_
00044 
00045 typedef enum {
00046   Torque = 0,                          /* Default value */
00047   Velocity,
00048   Position
00049 } EnumCommandType;
00050 
00051 #endif
00052 
00053 #ifndef _DEFINED_TYPEDEF_FOR_EnumControllerMode_
00054 #define _DEFINED_TYPEDEF_FOR_EnumControllerMode_
00055 
00056 typedef enum {
00057   StandBy = 0,                         /* Default value */
00058   Startup,
00059   TorqueControl,
00060   VelocityControl,
00061   PositionControl
00062 } EnumControllerMode;
00063 
00064 #endif
00065 
00066 #ifndef _DEFINED_TYPEDEF_FOR_SENSORS_STRUCT_
00067 #define _DEFINED_TYPEDEF_FOR_SENSORS_STRUCT_
00068 
00069 typedef struct {
00070   uint16_T adc_phase_currents[2];
00071   uint16_T encoder_valid;
00072   uint16_T encoder_counter;
00073 } SENSORS_STRUCT;
00074 
00075 #endif
00076 
00077 #ifndef _DEFINED_TYPEDEF_FOR_CTRLPARAMS_STRUCT_
00078 #define _DEFINED_TYPEDEF_FOR_CTRLPARAMS_STRUCT_
00079 
00080 typedef struct {
00081   real32_T Current_P;
00082   real32_T Current_I;
00083   real32_T Velocity_P;
00084   real32_T Velocity_I;
00085   real32_T Position_P;
00086   real32_T Position_I;
00087   real32_T StartupAcceleration;
00088   real32_T StartupCurrent;
00089   real32_T RampToStopVelocity;
00090   real32_T AdcZeroOffsetDriverUnits;
00091   real32_T AdcDriverUnitsToAmps;
00092   real32_T EncoderToMechanicalZeroOffsetRads;
00093   real32_T PmsmPolePairs;
00094 } CTRLPARAMS_STRUCT;
00095 
00096 #endif
00097 
00098 /* Block signals and states (auto storage) for system '<Root>' */
00099 typedef struct {
00100   real32_T Merge;                      /* '<S5>/Merge' */
00101   real32_T position;                   /* '<S63>/Integrate_To_Position' */
00102   real32_T velocity_command;           /* '<S1>/Controller_Mode_Scheduler' */
00103   real32_T position_command;           /* '<S1>/Controller_Mode_Scheduler' */
00104   real32_T torque_command;             /* '<S1>/Controller_Mode_Scheduler' */
00105   real32_T Integrator_DSTATE;          /* '<S17>/Integrator' */
00106   real32_T Integrator_DSTATE_l;        /* '<S18>/Integrator' */
00107   real32_T Velocity_Delay_DSTATE;      /* '<S58>/Velocity_Delay' */
00108   real32_T Integrate_To_Position_DSTATE;/* '<S63>/Integrate_To_Position' */
00109   real32_T Integrate_To_Velocity_DSTATE;/* '<S63>/Integrate_To_Velocity' */
00110   real32_T Integrator_DSTATE_lc;       /* '<S42>/Integrator' */
00111   real32_T Integrator_DSTATE_f;        /* '<S45>/Integrator' */
00112   int32_T Position_Delay_DSTATE;       /* '<S55>/Position_Delay' */
00113   EnumErrorType error_l;               /* '<Root>/Data Store Memory' */
00114   int16_T DelayInput1_DSTATE;          /* '<S13>/Delay Input1' */
00115   uint16_T Position_Valid;             /* '<S49>/Wait_For_Valid_Position' */
00116   int8_T Integrator_PrevResetState;    /* '<S17>/Integrator' */
00117   int8_T SwitchCase_ActiveSubsystem;   /* '<S5>/Switch Case' */
00118   int8_T Integrator_PrevResetState_c;  /* '<S18>/Integrator' */
00119   uint8_T is_active_c2_rtwdemo_pmsmfoc;/* '<S49>/Wait_For_Valid_Position' */
00120   uint8_T is_c2_rtwdemo_pmsmfoc;       /* '<S49>/Wait_For_Valid_Position' */
00121   uint8_T temporalCounter_i1;          /* '<S49>/Wait_For_Valid_Position' */
00122   uint8_T is_c1_rtwdemo_pmsmfoc;       /* '<S1>/Controller_Mode_Scheduler' */
00123   uint8_T is_Motor_On;                 /* '<S1>/Controller_Mode_Scheduler' */
00124   uint8_T is_Motor_Control;            /* '<S1>/Controller_Mode_Scheduler' */
00125   boolean_T RelationalOperator_a;      /* '<S51>/Relational Operator' */
00126   boolean_T Lo_to_Hi_Rate_Transition3_Buffe;/* '<S6>/Lo_to_Hi_Rate_Transition3' */
00127   boolean_T OpenLoopPosition_MODE;     /* '<S51>/Open Loop Position' */
00128 } D_Work;
00129 
00130 /* Constant parameters (auto storage) */
00131 typedef struct {
00132   /* Computed Parameter: Lookup_Table_table
00133    * Referenced by: '<S28>/Lookup_Table'
00134    */
00135   uint16_T Lookup_Table_table[7];
00136 } ConstParam;
00137 
00138 /* Real-time Model Data Structure */
00139 struct tag_RTM {
00140   /*
00141    * Timing:
00142    * The following substructure contains information regarding
00143    * the timing information for the model.
00144    */
00145   struct {
00146     struct {
00147       uint8_T TID[2];
00148     } TaskCounters;
00149   } Timing;
00150 };
00151 
00152 /* Block signals and states (auto storage) */
00153 extern D_Work DWork;
00154 
00155 /* Constant parameters (auto storage) */
00156 extern const ConstParam ConstP;
00157 
00158 /*
00159  * Exported Global Signals
00160  *
00161  * Note: Exported global signals are block signals with an exported global
00162  * storage class designation.  Code generation will declare the memory for
00163  * these signals and export their symbols.
00164  *
00165  */
00166 extern real32_T phase_currents[2];     /* '<S48>/Product' */
00167 extern real32_T rotor_position;        /* '<S49>/Add' */
00168 extern real32_T velocity_measured;     /* '<S55>/Scale_Output' */
00169 extern real32_T d_current_error;       /* '<S12>/Sum2' */
00170 extern real32_T q_current_command;     /* '<S5>/Lo_to_Hi_Rate_Transition1' */
00171 extern real32_T q_current_measured;    /* '<S22>/Add' */
00172 extern real32_T q_current_error;       /* '<S12>/Sum' */
00173 extern real32_T phase_voltages[3];     /* '<S27>/Select_Sector' */
00174 extern real32_T velocity_error;        /* '<S11>/Sum2' */
00175 extern EnumControllerMode controller_mode;/* '<S1>/Controller_Mode_Scheduler' */
00176 
00177 /*
00178  * Exported Global Parameters
00179  *
00180  * Note: Exported global parameters are tunable parameters with an exported
00181  * global storage class designation.  Code generation will declare the memory for
00182  * these parameters and exports their symbols.
00183  *
00184  */
00185 extern CTRLPARAMS_STRUCT ctrlParams;   /* Variable: ctrlParams
00186                                         * Referenced by:
00187                                         *   '<S1>/Controller_Mode_Scheduler'
00188                                         *   '<S48>/ADC_Driver_Units_To_Amps'
00189                                         *   '<S48>/ADC_Zero_Offset'
00190                                         *   '<S49>/Offset_Between_Encoder_Zero_And_Mechanical_Zero'
00191                                         *   '<S14>/number_of_pole_pairs'
00192                                         *   '<S42>/Integral Gain'
00193                                         *   '<S42>/Proportional Gain'
00194                                         *   '<S45>/Integral Gain'
00195                                         *   '<S45>/Proportional Gain'
00196                                         *   '<S63>/Startup_Acceleration_Constant'
00197                                         *   '<S17>/Integral Gain'
00198                                         *   '<S17>/Proportional Gain'
00199                                         *   '<S18>/Integral Gain'
00200                                         *   '<S18>/Proportional Gain'
00201                                         */
00202 
00203 /* Model entry point functions */
00204 extern "C"  void Controller_Init(void);
00205 
00206 /* Customized model step function */
00207 extern "C"  EnumErrorType Controller(uint16_T motor_on, EnumCommandType command_type,
00208   real32_T current_request, SENSORS_STRUCT *sensors, uint16_T pwm_compare[3]);
00209 
00210 /* Real-time Model object */
00211 extern RT_MODEL *const M;
00212 
00213 /*-
00214  * The generated code includes comments that allow you to trace directly
00215  * back to the appropriate location in the model.  The basic format
00216  * is <system>/block_name, where system is the system number (uniquely
00217  * assigned by Simulink) and block_name is the name of the block.
00218  *
00219  * Use the MATLAB hilite_system command to trace the generated code back
00220  * to the model.  For example,
00221  *
00222  * hilite_system('<S3>')    - opens system 3
00223  * hilite_system('<S3>/Kp') - opens and selects block Kp which resides in S3
00224  *
00225  * Here is the system hierarchy for this model
00226  *
00227  * '<Root>' : 'rtwdemo_pmsmfoc'
00228  * '<S1>'   : 'rtwdemo_pmsmfoc/Mode_Scheduler'
00229  * '<S2>'   : 'rtwdemo_pmsmfoc/Model Info'
00230  * '<S3>'   : 'rtwdemo_pmsmfoc/Motor_Control'
00231  * '<S4>'   : 'rtwdemo_pmsmfoc/Mode_Scheduler/Controller_Mode_Scheduler'
00232  * '<S5>'   : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller'
00233  * '<S6>'   : 'rtwdemo_pmsmfoc/Motor_Control/Phase_Voltages_to_PWM_Compare_Values'
00234  * '<S7>'   : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units'
00235  * '<S8>'   : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control'
00236  * '<S9>'   : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Position_Control'
00237  * '<S10>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Torque_Control'
00238  * '<S11>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Velocity_Control'
00239  * '<S12>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Current_Controllers'
00240  * '<S13>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Detect_Change'
00241  * '<S14>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Rotation_Coefficients_Sin_Cos'
00242  * '<S15>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_ABC_to_dq'
00243  * '<S16>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC'
00244  * '<S17>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Current_Controllers/Direct_Current_Control'
00245  * '<S18>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Current_Controllers/Quadrature_Current_Control'
00246  * '<S19>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Current_Controllers/Direct_Current_Control/Clamping circuit'
00247  * '<S20>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Current_Controllers/Quadrature_Current_Control/Clamping circuit'
00248  * '<S21>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_ABC_to_dq/Clarke_Transform'
00249  * '<S22>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_ABC_to_dq/Park_Transform'
00250  * '<S23>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC'
00251  * '<S24>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Inverse_Park_Transform'
00252  * '<S25>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Inverse_Clarke_Transform'
00253  * '<S26>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation'
00254  * '<S27>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Calculate_Phase_Voltages'
00255  * '<S28>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Determine_Sector'
00256  * '<S29>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Phase_Advanced_Inverse_Clarke'
00257  * '<S30>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Calculate_Phase_Voltages/Va_Sectors_1_and_4'
00258  * '<S31>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Calculate_Phase_Voltages/Va_Sectors_2_and_5'
00259  * '<S32>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Calculate_Phase_Voltages/Va_Sectors_3_and_6'
00260  * '<S33>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Calculate_Phase_Voltages/Vb_Sectors_1_and_4'
00261  * '<S34>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Calculate_Phase_Voltages/Vb_Sectors_2_and_5'
00262  * '<S35>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Calculate_Phase_Voltages/Vb_Sectors_3_and_6'
00263  * '<S36>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Calculate_Phase_Voltages/Vc_Sectors_1_and_4'
00264  * '<S37>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Calculate_Phase_Voltages/Vc_Sectors_2_and_5'
00265  * '<S38>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Calculate_Phase_Voltages/Vc_Sectors_3_and_6'
00266  * '<S39>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Determine_Sector/Compare_VA_To_Zero'
00267  * '<S40>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Determine_Sector/Compare_VB_To_Zero'
00268  * '<S41>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Current_Control/Transform_Coordinates_dq_to_ABC/Alpha_Beta_to_ABC/Space_Vector_Modulation/Determine_Sector/Compare_VC_To_Zero'
00269  * '<S42>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Position_Control/Position_Control'
00270  * '<S43>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Position_Control/Wrap_Error_pi'
00271  * '<S44>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Position_Control/Position_Control/Clamping circuit'
00272  * '<S45>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Velocity_Control/Rotor_Speed_Control'
00273  * '<S46>'  : 'rtwdemo_pmsmfoc/Motor_Control/Field_Oriented_Controller/Velocity_Control/Rotor_Speed_Control/Clamping circuit'
00274  * '<S47>'  : 'rtwdemo_pmsmfoc/Motor_Control/Phase_Voltages_to_PWM_Compare_Values/Enumerated_Constant'
00275  * '<S48>'  : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/ADC_Level_to_Phase_Current'
00276  * '<S49>'  : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Encoder_To_Position'
00277  * '<S50>'  : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Position_To_Velocity'
00278  * '<S51>'  : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Startup_Open_Loop_Control'
00279  * '<S52>'  : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Encoder_To_Position/Wait_For_Valid_Position'
00280  * '<S53>'  : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Position_To_Velocity/Explicit_Angle_Wrap'
00281  * '<S54>'  : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Position_To_Velocity/Explicit_Angle_Wrap_With_Error'
00282  * '<S55>'  : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Position_To_Velocity/Implicit_Integer_Wrap_With_Error'
00283  * '<S56>'  : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Position_To_Velocity/Explicit_Angle_Wrap_With_Error/Detect_Velocity_Error'
00284  * '<S57>'  : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Position_To_Velocity/Explicit_Angle_Wrap_With_Error/Detect_Velocity_Error/Generate_Error'
00285  * '<S58>'  : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Position_To_Velocity/Implicit_Integer_Wrap_With_Error/Detect_Velocity_Error'
00286  * '<S59>'  : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Position_To_Velocity/Implicit_Integer_Wrap_With_Error/Detect_Velocity_Error/Enumerated_Constant'
00287  * '<S60>'  : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Position_To_Velocity/Implicit_Integer_Wrap_With_Error/Detect_Velocity_Error/Generate_Error'
00288  * '<S61>'  : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Position_To_Velocity/Implicit_Integer_Wrap_With_Error/Detect_Velocity_Error/Generate_Error/Enumerated_Constant'
00289  * '<S62>'  : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Startup_Open_Loop_Control/Enumerated Constant'
00290  * '<S63>'  : 'rtwdemo_pmsmfoc/Motor_Control/Sensors_To_Engineering_Units/Startup_Open_Loop_Control/Open Loop Position'
00291  */
00292 
00293 /*-
00294  * Requirements for '<Root>': rtwdemo_pmsmfoc
00295  */
00296 #endif                                 /* RTW_HEADER_rtwdemo_pmsmfoc_h_ */
00297 
00298 /*
00299  * File trailer for generated code.
00300  *
00301  * [EOF]
00302  */