18 #include "sw/modules/cal/src/float/cal.h"
19 #include "sw/modules/ipark/src/float/ipark.h"
20 #include "sw/modules/park/src/float/park.h"
22 #include "sw/modules/svgen/src/float/svgen.h"
188 uint_least8_t ctrlNumber = 0;
189 uint_least8_t estNumber = 0;
197 USER_setParams_priv(&gUserParams);
201 halHandle =
HAL_init(&hal,
sizeof(hal));
209 angleHandle =
ANGLE_init(&angle,
sizeof(angle));
217 calHandle =
CAL_init(&cal,
sizeof(cal));
225 clarkeHandle_I =
CLARKE_init(&clarke_I,
sizeof(clarke_I));
226 clarkeHandle_V =
CLARKE_init(&clarke_V,
sizeof(clarke_V));
235 ctrlHandle =
CTRL_init(&(ctrl[ctrlNumber]),
sizeof(ctrl[ctrlNumber]));
261 if(gUserParams.
motor_type == MOTOR_Type_Induction)
269 iparkHandle =
IPARK_init(&ipark,
sizeof(ipark));
273 parkHandle =
PARK_init(&park,
sizeof(park));
277 queueHandle =
QUEUE_init(&queue,
sizeof(queue));
281 svgenHandle =
SVGEN_init(&svgen,
sizeof(svgen));
338 if(gUserParams.
motor_type == MOTOR_Type_Induction)
352 if(gUserParams.
motor_type == MOTOR_Type_Induction)
449 if(flag_calStateChanged)
453 if(calState == CAL_State_Done)
481 if(flag_trajStateChanged)
486 (state == EST_Traj_State_OnLine))
516 if(flag_estStateChanged)
544 if(gUserParams.
motor_type == MOTOR_Type_Induction)
601 float_t RoverLd_rps = Rs_Ohm / Ls_d_H;
602 float_t RoverLq_rps = Rs_Ohm / Ls_q_H;
606 float_t Kp_Id = Ls_d_H * BWc_rps;
607 float_t Ki_Id = RoverLd_rps * currentCtrlPeriod_sec;
609 float_t Kp_Iq = Ls_q_H * BWc_rps;
610 float_t Ki_Iq = RoverLq_rps * currentCtrlPeriod_sec;
681 if(count_traj >= numIsrTicksPerTrajTick)
706 if(count_est >= numIsrTicksPerEstTick)
728 argList.
arg[3] = NULL;
736 &gEstOutputData[gBufferIndex_est]);
784 if(count_ctrl >= numIsrTicksPerCtrlTick)
788 bool flag_useZeroIq_ref =
false;
821 PARK_run(parkHandle,&Iab_in_A,&Idq_A);
834 Vdq_offset_V.
value[0] = 0.0;
835 Vdq_offset_V.
value[1] = 0.0;
871 IPARK_run(iparkHandle,&Vdq_out_V,&Vab_out_V);
923 if(numCurrentSensors == 3)
928 else if(numCurrentSensors == 2)
953 if(numVoltageSensors == 3)
#define USER_SYSTEM_FREQ_MHz
CLOCKS & TIMERS.
bool EST_isError(EST_Handle handle)
float_t EST_getRsOnLine_Ohm(EST_Handle handle)
void EST_enableTraj(EST_Handle handle)
void ANGLE_setup(ANGLE_Handle handle, const int_least32_t timeStamp, const float_t angle_rad, const float_t speed_rps, const float_t accel_rps2)
EST_State_e gEstState
Global variable for the estimator state.
float_t angleDelayed_sf_sec
void EST_setFlag_enableForceAngle(EST_Handle handle, const bool state)
ANGLE_Obj angle
the angle object
static void CAL_enable(CAL_Handle handle)
IPARK_Handle IPARK_init(void *pMemory, const size_t numBytes)
void EST_resetTrajCounter_isr(EST_Handle handle)
void CTRL_incrCounter_isr(CTRL_Handle handle)
void HAL_enableGlobalInts(HAL_Handle handle)
void HAL_enableAdcInts(HAL_Handle handle)
bool EST_getFlag_estComplete(EST_Handle handle)
float_t EST_getFlux_Wb(EST_Handle handle)
static float_t CTRL_getCurrentCtrlPeriod_sec(CTRL_Handle handle)
void EST_incrTrajCounter_isr(EST_Handle handle)
void EST_setRsOnLineId_mag_A(EST_Handle handle, const float_t Id_mag_A)
void CTRL_run(CTRL_Handle handle, HAL_Handle halHandle, const HAL_AdcData_t *pAdcData, HAL_PwmData_t *pPwmData)
volatile bool gFlag_enableRsRecalc
void calcGains(CTRL_Handle handle, EST_Handle estHandle)
Calculates controller gains.
float_t EST_getRr_q_Ohm(EST_Handle handle)
static void CAL_run(CAL_Handle handle, const HAL_AdcData_t *pAdcData)
CLARKE_Handle clarkeHandle_V
the handle for the voltage Clarke transform
float_t EST_getOneOverDcBus_invV(EST_Handle handle)
float_t gLs_d_H
Global variable for the stator inductance in the direct coordinate direction, Henry.
EST_InputData_t gEstInputData[NUM_EST_DATA_BUFFERS]
static void PARK_setPhasor(PARK_Handle handle, const MATH_vec2 *pPhasor)
QUEUE_Handle QUEUE_init(void *pMemory, const size_t numBytes)
float_t gRs_b_Ohm
Global variable for the stator resistance in the beta coordinate direction, Ohm.
IPARK_Handle iparkHandle
the handle for the inverse Park transform
float_t EST_getRoverL_rps(EST_Handle handle)
float_t gIdRated_A
Global variable for the rated Id current current, A.
volatile bool gFlag_runIdentAndOnLine
void ANGLE_run(ANGLE_Handle handle, const int_least32_t timeStamp)
float_t gRoverL_rps
Global variable for the R/L value used for the current controller.
float_t EST_getIntValue_Iq_A(EST_Handle handle)
#define USER_EST_FREQ_Hz
Defines the estimator frequency, Hz.
int_least16_t EST_getCount_isr(EST_Handle handle)
static void HAL_writePwmData(HAL_Handle handle, HAL_PwmData_t *pPwmData)
void EST_setMinValue_spd_Hz(EST_Handle handle, const float_t minValue_Hz)
bool EST_isOnLine(EST_Handle handle)
static float_t CTRL_getBWc_rps(CTRL_Handle handle)
struct _EST_Obj_ * EST_Handle
void HAL_writeDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
bool CTRL_isError(CTRL_Handle handle)
CTRL_Obj ctrl[CTRL_NUM_CONTROLLERS]
the controller object
uint_least16_t CTRL_getNumIsrTicksPerCtrlTick(CTRL_Handle handle)
void EST_incrCounter_isr(EST_Handle handle)
PARK_Handle parkHandle
the handle for the Park object
float_t gRs_d_Ohm
Global variable for the stator resistance in the direct coordinate direction, Ohm.
static void HAL_acqAdcInt(HAL_Handle handle, const ADC_IntNumber_e intNumber)
float_t EST_getRr_d_Ohm(EST_Handle handle)
void * arg[EVENT_MAX_NUM_ARGS]
volatile float_t gSpeed_Kp
static void CAL_setFlag_enableAdcOffset(CAL_Handle handle, const bool value)
uint_least8_t numCurrentSensors
bool EST_isEnabled(EST_Handle handle)
volatile bool gFlag_bypassLockRotor
void EST_setupTraj(EST_Handle handle, CTRL_Handle ctrlHandle, const float_t targetValue_spd_Hz, const float_t targetValue_Id_A)
void EST_setMaxDelta_spd_Hz(EST_Handle handle, const float_t maxDelta_Hz)
void CAL_setParams(CAL_Handle handle, const USER_Params *pUserParams)
void EST_setParams(EST_Handle handle, USER_Params *pUserParams)
static void SVGEN_run(SVGEN_Handle handle, const MATH_vec2 *pVab, MATH_vec3 *pT)
volatile float_t gSpeed_Ki
static uint32_t CPU_USAGE_getAvgDeltaCntObserved(CPU_USAGE_Handle handle)
static MATH_vec2 * CTRL_getIdq_ref_A_addr(CTRL_Handle handle)
static status QUEUE_postEventLast(QUEUE_Handle handle, const EVENT_Fxn eventFxn, const EVENT_ArgList *pArgList, const uint_least8_t numArgs)
void EST_configureTraj(EST_Handle handle)
#define MATH_ONE_OVER_THREE
QUEUE_Handle queueHandle
the handle for the queue
volatile bool gFlag_runCal
void USER_setParams(USER_Params *pUserParams)
Sets the user parameter values.
uint_least16_t CTRL_getCount_isr(CTRL_Handle handle)
void setupClarke_V(CLARKE_Handle handle, const uint_least8_t numVoltageSensors)
Sets the number of voltage sensors.
void EST_setFlag_updateRs(EST_Handle handle, const bool state)
float_t EST_computeTorque_Nm(EST_Handle handle)
bool EST_isTrajEnabled(EST_Handle handle)
void CTRL_setGains(CTRL_Handle handle, const CTRL_Type_e ctrlType, const _iq Kp, const _iq Ki, const _iq Kd)
float_t EST_getIntValue_Id_A(EST_Handle handle)
static void CLARKE_setScaleFactors(CLARKE_Handle handle, const _iq alpha_sf, const _iq beta_sf)
float_t EST_getFm_lp_Hz(EST_Handle handle)
PARK_Obj park
the Park transform object
void EST_enable(EST_Handle handle)
CTRL_Handle CTRL_init(void *pMemory, const size_t numBytes)
static void incrCount_isr(void)
Increments the ISR counter.
void HAL_setupFaults(HAL_Handle handle)
float_t EST_getLs_d_H(EST_Handle handle)
void EST_setFlag_enableRsRecalc(EST_Handle handle, const bool state)
volatile bool gFlag_enableRsOnLine
USER_Params gUserParams
The user parameters.
void updateCPUusage(CTRL_Handle handle)
Updates CPU usage.
static void incrBufferIndex_est(void)
Increments the estimation buffer index.
static void HAL_enablePwm(HAL_Handle handle)
void EST_configureCtrl(EST_Handle handle, CTRL_Handle ctrlHandle)
CTRL_Version gVersion
Global variable for the controller version.
void CTRL_setParams(CTRL_Handle handle, USER_Params *pUserParams)
void EST_setFlag_enablePowerWarp(EST_Handle handle, const bool state)
EST_OutputData_t gEstOutputData[NUM_EST_DATA_BUFFERS]
CLARKE_Obj clarke_I
the current Clarke transform object
int_least32_t gCounter_isr
A counter that is incremented by each call to the mainISR() function.
void HAL_enableDrv(HAL_Handle handle)
void CTRL_resetCounter_isr(CTRL_Handle handle)
bool EST_doSpeedCtrl(EST_Handle handle)
volatile bool gFlag_enablePowerWarp
EST_Handle EST_initEst(const uint_least8_t estNumber)
IPARK_Obj ipark
the inverse Park transform object
float_t gCpuUsagePercentageMax
ANGLE_Handle ANGLE_init(void *pMemory, const size_t numBytes)
uint_least32_t trajFreq_Hz
float_t EST_getIdRated_A(EST_Handle handle)
void HAL_setupDrvSpi(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
uint_least8_t numVoltageSensors
float_t EST_getLs_q_H(EST_Handle handle)
void HAL_enableDebugInt(HAL_Handle handle)
CLARKE_Handle CLARKE_init(void *pMemory, const size_t numBytes)
int_least32_t gCounter_main
A counter that is incremented by each iteration of the main() function.
void EST_disableTraj(EST_Handle handle)
CTRL_State_e CTRL_getState(CTRL_Handle handle)
uint_least16_t gBufferIndex_setup
A counter that to denote the buffer index for the setup.
static void IPARK_run(IPARK_Handle handle, const MATH_vec2 *pInVec, MATH_vec2 *pOutVec)
float_t EST_getRs_b_Ohm(EST_Handle handle)
EST_State_e EST_getState(EST_Handle handle)
static void CAL_disable(CAL_Handle handle)
void setupClarke_I(CLARKE_Handle handle, const uint_least8_t numCurrentSensors)
Sets the number of current sensors.
volatile bool gFlag_enableForceAngle
void EST_updateId_ref_A(EST_Handle handle, float_t *pId_ref_A)
void CTRL_setup(CTRL_Handle handle)
void EST_setFlag_estComplete(EST_Handle handle, const bool state)
CLARKE_Obj clarke_V
the voltage Clarke transform object
HAL_DacData_t gDacData
Defines the DAC data.
float_t gLs_q_H
Global variable for the stator inductance in the quadrature coordinate direction, Henry...
float_t gRs_a_Ohm
Global variable for the stator resistance in the alpha coordinate direction, Ohm. ...
float_t EST_getRs_a_Ohm(EST_Handle handle)
static bool CTRL_isEnabled(CTRL_Handle handle)
void EST_setFlag_enableRsOnLine(EST_Handle handle, const bool state)
interrupt void mainISR(void)
The main interrupt service (ISR) routine.
int_least16_t EST_getNumIsrTicksPerEstTick(EST_Handle handle)
static OFFSET_Handle * CAL_getOffsetHandleAddr_I(CAL_Handle handle)
static uint32_t HAL_readTimerCnt(HAL_Handle handle, const uint_least8_t timerNumber)
void EST_setIdq_ref_A(EST_Handle handle, const MATH_vec2 *pIdq_ref_A)
static void CLARKE_setNumSensors(CLARKE_Handle handle, const uint_least8_t numSensors)
float_t EST_getRs_Ohm(EST_Handle handle)
float_t EST_computeLmag_H(EST_Handle handle, const float_t current_A)
float_t gRr_d_Ohm
Global variable for the rotor resistance in the direct coordinate direction, Ohm. ...
void EST_setMaxValue_spd_Hz(EST_Handle handle, const float_t maxValue_Hz)
CPU_USAGE_Handle cpu_usageHandle
bool EST_doCurrentCtrl(EST_Handle handle)
float_t EST_getRs_q_Ohm(EST_Handle handle)
void updateGlobalVariables_motor(CTRL_Handle ctrlHandle, EST_Handle estHandle)
Updates the global motor variables.
void ANGLE_setParams(ANGLE_Handle handle, const float_t timeStampPeriod_sec, const float_t angleDelayed_sf_sec)
void CPU_USAGE_setParams(CPU_USAGE_Handle handle, const uint32_t timerPeriod_cnts, const uint32_t numDeltaCntsAvg)
void EST_runTraj(EST_Handle handle)
static bool CAL_isError(CAL_Handle handle)
#define USER_ISR_FREQ_Hz
Defines the Interrupt Service Routine (ISR) frequency, Hz.
static void IPARK_setPhasor(IPARK_Handle handle, const MATH_vec2 *pPhasor)
CPU_USAGE_Handle CPU_USAGE_init(void *pMemory, const size_t numBytes)
float_t gRs_q_Ohm
Global variable for the stator resistance in the quadrature coordinate direction, Ohm...
static void HAL_disablePwm(HAL_Handle handle)
void EST_setRsOnLineAngleDelta_rad(EST_Handle handle, const float_t angleDelta_rad)
float_t gCpuUsagePercentageAvg
bool EST_isMotorIdentified(EST_Handle handle)
CAL_Handle calHandle
the handle for the calibrator
CLARKE_Handle clarkeHandle_I
the handle for the current Clarke transform
float_t EST_getRs_d_Ohm(EST_Handle handle)
HAL_Handle HAL_init(void *pMemory, const size_t numBytes)
bool EST_isLockRotor(EST_Handle handle)
static void CLARKE_run(CLARKE_Handle handle, const MATH_vec3 *pInVec, MATH_vec2 *pOutVec)
static uint32_t CPU_USAGE_getMaxDeltaCntObserved(CPU_USAGE_Handle handle)
HAL_Handle halHandle
the handle for the hardware abstraction layer
void EST_setRsOnLine_beta_rad(EST_Handle handle, const float_t beta_rad)
static void PARK_run(PARK_Handle handle, const MATH_vec2 *pInVec, MATH_vec2 *pOutVec)
volatile float_t gRsOnLineFreq_Hz
static CAL_State_e CAL_getState(CAL_Handle handle)
HAL_Obj hal
the hardware abstraction layer object
float_t gFlux_Wb
Global variable for the rotor flux estimate, Wb.
#define NUM_EST_DATA_BUFFERS
Defines the number of estimator data buffers NOTE: Must be a multiple of two.
volatile bool gFlag_updateRs
SVGEN_Handle svgenHandle
the handle for the space vector generator
static void HAL_readAdcData(HAL_Handle handle, HAL_AdcData_t *pAdcData)
CAL_Handle CAL_init(void *pMemory, const size_t numBytes)
#define USER_TRAJ_FREQ_Hz
Defines the trajectory frequency, Hz.
void SVGEN_setup(SVGEN_Handle svgenHandle)
uint_least16_t gBufferIndex_est
A counter that to denote the buffer index for the estimation.
CTRL_Handle ctrlHandle
the handle for the controller
bool EST_isIdle(EST_Handle handle)
static void CPU_USAGE_updateCnts(CPU_USAGE_Handle handle, const uint32_t cnt)
volatile bool gFlag_enableSys
Global flag to enable/disable the system.
ANGLE_Handle angleHandle
the handle for the angle generator
SVGEN_Obj svgen
the space vector generator object
static uint32_t CPU_USAGE_getMinDeltaCntObserved(CPU_USAGE_Handle handle)
#define MATH_ONE_OVER_SQRT_THREE
bool EST_isTrajError(EST_Handle handle)
EST_Handle estHandle
the handle for the estimator
EST_Traj_State_e gTrajState
EST_Traj_State_e EST_getTrajState(EST_Handle handle)
float_t gLmag_H
Global variable for the magnetizing inductance, Henry.
static void HAL_initIntVectorTable(HAL_Handle handle)
static float_t ANGLE_getAngleWithDelay_rad(ANGLE_Handle handle)
volatile float_t gRsOnLinePole_Hz
static void QUEUE_executeEvent(QUEUE_Handle handle)
static void HAL_updateAdcBias(HAL_Handle handle)
PARK_Handle PARK_init(void *pMemory, const size_t numBytes)
float_t EST_getIdRated_indEst_A(EST_Handle handle)
void CTRL_getVersion(CTRL_Handle handle, CTRL_Version *pVersion)
volatile float_t gRsOnLineId_mag_A
static uint16_t HAL_readPwmPeriod(HAL_Handle handle, const PWM_Number_e pwmNumber)
HAL_PwmData_t gPwmData
Defines the PWM data.
static bool QUEUE_isEvent(QUEUE_Handle handle)
static void CTRL_enable(CTRL_Handle handle)
bool EST_updateState(EST_Handle handle, const _iq Id_target_pu)
static void CTRL_disable(CTRL_Handle handle)
void CTRL_computePhasor(const _iq angle_pu, MATH_vec2 *pPhasor)
#define CTRL_NUM_CONTROLLERS
void EST_disable(EST_Handle handle)
void HAL_setParams(HAL_Handle handle, const USER_Params *pUserParams)
static void CPU_USAGE_run(CPU_USAGE_Handle handle)
bool CAL_updateState(CAL_Handle handle)
HAL_AdcData_t gAdcData
Defines the ADC data.
CTRL_State_e gCtrlState
Global variable for the controller state.
float_t EST_getFe_Hz(EST_Handle handle)
CAL_Obj cal
the calibrator object
void HAL_readDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
static bool CAL_isEnabled(CAL_Handle handle)
static float_t ANGLE_getAngle_rad(ANGLE_Handle handle)
float_t gTorque_Nm
Global variable for the estimated torque, N*m.
static void incrBufferIndex_setup(void)
Increments the setup buffer index.
float_t EST_getIntValue_spd_Hz(EST_Handle handle)
static void HAL_writeDacData(HAL_Handle handle, HAL_DacData_t *pDacData)
void EST_resetCounter_isr(EST_Handle handle)
SVGEN_Handle SVGEN_init(void *pMemory, const size_t numBytes)
bool EST_updateTrajState(EST_Handle handle)
int_least32_t gCounter_enableSys
A counter that is incremented while waiting for the enable system flag to be set. ...
void EST_setFlag_bypassLockRotor(EST_Handle handle, const bool state)
static OFFSET_Handle * CAL_getOffsetHandleAddr_V(CAL_Handle handle)
int_least16_t EST_getNumIsrTicksPerTrajTick(EST_Handle handle)
float_t gCpuUsagePercentageMin
void EST_run(EST_Handle handle, const MATH_vec2 *pIab_pu, const MATH_vec2 *pVab_pu, const _iq dcBus_pu, const _iq speed_ref_pu)
#define USER_NUM_PWM_TICKS_PER_ISR_TICK
DECIMATION.
int_least16_t EST_getTrajCount_isr(EST_Handle handle)
QUEUE_Obj queue
the queue object