モータドライバをシリアル通信で制御するためにInstaSPINの重要パラメータの確認
F28027Fのproj_lab05bのmain.hを参考にします.
gMotorVarsという構造体変数に重要なパラメータがまとめられています.
typedef struct _MOTOR_Vars_t_ { bool Flag_enableSys; bool Flag_Run_Identify; bool Flag_MotorIdentified; bool Flag_enableForceAngle; bool Flag_enableFieldWeakening; bool Flag_enableRsRecalc; bool Flag_enableUserParams; bool Flag_enableOffsetcalc; bool Flag_enablePowerWarp; bool Flag_enableSpeedCtrl; bool Flag_enableRun; bool Flag_RunState; bool Flag_enableFlyingStart; CTRL_State_e CtrlState; // Read Only EST_State_e EstState; // Read Only USER_ErrorCode_e UserErrorCode; CTRL_Version CtrlVersion; _iq IdRef_A; _iq IqRef_A; _iq SpeedRef_pu; _iq SpeedRef_krpm; _iq SpeedTraj_krpm; // Read Only _iq MaxAccel_krpmps; _iq Speed_krpm; // Read Only _iq OverModulation; _iq RsOnLineCurrent_A; _iq SvgenMaxModulation_ticks; _iq Flux_Wb; // Read Only _iq Torque_Nm; // Read Only float_t MagnCurr_A; // Read Only float_t Rr_Ohm; // Read Only float_t Rs_Ohm; // Read Only float_t RsOnLine_Ohm; float_t Lsd_H; // Read Only float_t Lsq_H; // Read Only float_t Flux_VpHz; // Read Only float_t ipd_excFreq_Hz; _iq ipd_Kspd; _iq ipd_excMag_coarse_pu; _iq ipd_excMag_fine_pu; float ipd_waitTime_coarse_sec; float ipd_waitTime_fine_sec; _iq Kp_spd; _iq Ki_spd; _iq Kp_Idq; _iq Ki_Idq; _iq Vd; _iq Vq; _iq Vs; _iq VsRef; _iq VdcBus_kV; // Read Only _iq Id_A; _iq Iq_A; _iq Is_A; MATH_vec3 I_bias; MATH_vec3 V_bias; _iq SpeedSet_krpm; _iq angle_sen_pu; _iq angle_est_pu; _iq speed_sen_pu; _iq speed_est_pu; _iq speedHigh_hall2fast_pu; _iq speedLow_hall2fast_pu; }MOTOR_Vars_t;
コメントのパラメータはループ内で更新されるので、読み込み専用。
これらのデータをシリアルでやり取りするために、それぞれの変数型のメモリサイズを調べておきます。
sizeof(bool)=1
sizeof(CTRL_State_e)=1
sizeof(EST_State_e)=1
sizeof(USER_ErrorCode_e)=1
sizeof(CTRL_Version)=4
sizeof(float_t)=2
sizeof(float)=2
sizeof(_iq)=2
sizeof(MATH_vec3)=6
_iqは標準では、24ビット目に小数点を置く.
#define _IQ24(A) (long) ((A) * 16777216.0L)
計算はこのように行われる.
#include <stdio.h> long float_to_iq24(float a, unsigned char* lower, unsigned char* upper) { long b = (long)(a * 16777216.0L) >> 8; *lower = (b%0x100)&0xff; *upper = (b/0x100)&0xff; return b; } float _iq24l_to_float(long b) { float a = (b<<8)/16777216.0; return a; } float _iq24_to_float(unsigned char lower, unsigned char upper) { long b = (upper<<8) + lower; return _iq24l_to_float(b); } int main(void){ float a = 0.1; long b = (long)(a * 16777216.0L) >> 8; printf("dec=%f, _iq=%ld, lower_byte=%d, upper_byte=%d\n", a, b, (b%0x100)&0xff, (b/0x100)&0xff); unsigned char l, u; long lo; lo = float_to_iq24(a, &l, &u); printf("float_to_iq24: %f %ld %d %d\n", a, lo, l, u); float f; f = _iq24_to_float(l, u); printf("_iq24_to_float: %f %d %d\n", f, l, u); f = _iq24l_to_float(lo); printf("_iq24_to_float: %f %ld", f, lo); }
ちょっとしたテストにはWEBサービスが便利。
Web-based online coding environment | paiza.IO
実行例
dec=0.100000, _iq=6553, lower_byte=153, upper_byte=25
ctrl_state.h
//! \brief Enumeration for the controller states //! typedef enum { CTRL_State_Error=0, //!< the controller error state CTRL_State_Idle, //!< the controller idle state CTRL_State_OffLine, //!< the controller offline state CTRL_State_OnLine, //!< the controller online state CTRL_numStates //!< the number of controller states } CTRL_State_e;
est_state.h
//! \brief Enumeration for the estimator error codes //! typedef enum { EST_ErrorCode_NoError=0, //!< no error error code EST_ErrorCode_Flux_OL_ShiftOverFlow, //!< flux open loop shift overflow error code EST_ErrorCode_FluxError, //!< flux estimator error code EST_ErrorCode_Dir_ShiftOverFlow, //!< direction shift overflow error code EST_ErrorCode_Ind_ShiftOverFlow, //!< inductance shift overflow error code EST_numErrorCodes //!< the number of estimator error codes } EST_ErrorCode_e; //! \brief Enumeration for the estimator states //! typedef enum { EST_State_Error=0, //!< error EST_State_Idle, //!< idle EST_State_RoverL, //!< R/L estimation EST_State_Rs, //!< Rs estimation state EST_State_RampUp, //!< ramp up the speed #if !defined(FAST_ROM_V1p6) && !defined(FAST_ROM_V1p7) EST_State_ConstSpeed, //!< constant speed after ramp up #endif EST_State_IdRated, //!< control Id and estimate the rated flux EST_State_RatedFlux_OL, //!< estimate the open loop rated flux EST_State_RatedFlux, //!< estimate the rated flux EST_State_RampDown, //!< ramp down the speed EST_State_LockRotor, //!< lock the rotor EST_State_Ls, //!< stator inductance estimation state EST_State_Rr, //!< rotor resistance estimation state EST_State_MotorIdentified, //!< motor identified state EST_State_OnLine, //!< online parameter estimation EST_numStates //!< the number of estimator states } EST_State_e;
//! \brief Enumeration for the user error codes //! typedef enum { USER_ErrorCode_NoError=0, //!< no error error code USER_ErrorCode_iqFullScaleCurrent_A_High=1, //!< iqFullScaleCurrent_A too high error code USER_ErrorCode_iqFullScaleCurrent_A_Low=2, //!< iqFullScaleCurrent_A too low error code USER_ErrorCode_iqFullScaleVoltage_V_High=3, //!< iqFullScaleVoltage_V too high error code USER_ErrorCode_iqFullScaleVoltage_V_Low=4, //!< iqFullScaleVoltage_V too low error code USER_ErrorCode_iqFullScaleFreq_Hz_High=5, //!< iqFullScaleFreq_Hz too high error code USER_ErrorCode_iqFullScaleFreq_Hz_Low=6, //!< iqFullScaleFreq_Hz too low error code USER_ErrorCode_numPwmTicksPerIsrTick_High=7, //!< numPwmTicksPerIsrTick too high error code USER_ErrorCode_numPwmTicksPerIsrTick_Low=8, //!< numPwmTicksPerIsrTick too low error code USER_ErrorCode_numIsrTicksPerCtrlTick_High=9, //!< numIsrTicksPerCtrlTick too high error code USER_ErrorCode_numIsrTicksPerCtrlTick_Low=10, //!< numIsrTicksPerCtrlTick too low error code USER_ErrorCode_numCtrlTicksPerCurrentTick_High=11, //!< numCtrlTicksPerCurrentTick too high error code USER_ErrorCode_numCtrlTicksPerCurrentTick_Low=12, //!< numCtrlTicksPerCurrentTick too low error code USER_ErrorCode_numCtrlTicksPerEstTick_High=13, //!< numCtrlTicksPerEstTick too high error code USER_ErrorCode_numCtrlTicksPerEstTick_Low=14, //!< numCtrlTicksPerEstTick too low error code USER_ErrorCode_numCtrlTicksPerSpeedTick_High=15, //!< numCtrlTicksPerSpeedTick too high error code USER_ErrorCode_numCtrlTicksPerSpeedTick_Low=16, //!< numCtrlTicksPerSpeedTick too low error code USER_ErrorCode_numCtrlTicksPerTrajTick_High=17, //!< numCtrlTicksPerTrajTick too high error code USER_ErrorCode_numCtrlTicksPerTrajTick_Low=18, //!< numCtrlTicksPerTrajTick too low error code USER_ErrorCode_numCurrentSensors_High=19, //!< numCurrentSensors too high error code USER_ErrorCode_numCurrentSensors_Low=20, //!< numCurrentSensors too low error code USER_ErrorCode_numVoltageSensors_High=21, //!< numVoltageSensors too high error code USER_ErrorCode_numVoltageSensors_Low=22, //!< numVoltageSensors too low error code USER_ErrorCode_offsetPole_rps_High=23, //!< offsetPole_rps too high error code USER_ErrorCode_offsetPole_rps_Low=24, //!< offsetPole_rps too low error code USER_ErrorCode_fluxPole_rps_High=25, //!< fluxPole_rps too high error code USER_ErrorCode_fluxPole_rps_Low=26, //!< fluxPole_rps too low error code USER_ErrorCode_zeroSpeedLimit_High=27, //!< zeroSpeedLimit too high error code USER_ErrorCode_zeroSpeedLimit_Low=28, //!< zeroSpeedLimit too low error code USER_ErrorCode_forceAngleFreq_Hz_High=29, //!< forceAngleFreq_Hz too high error code USER_ErrorCode_forceAngleFreq_Hz_Low=30, //!< forceAngleFreq_Hz too low error code USER_ErrorCode_maxAccel_Hzps_High=31, //!< maxAccel_Hzps too high error code USER_ErrorCode_maxAccel_Hzps_Low=32, //!< maxAccel_Hzps too low error code USER_ErrorCode_maxAccel_est_Hzps_High=33, //!< maxAccel_est_Hzps too high error code USER_ErrorCode_maxAccel_est_Hzps_Low=34, //!< maxAccel_est_Hzps too low error code USER_ErrorCode_directionPole_rps_High=35, //!< directionPole_rps too high error code USER_ErrorCode_directionPole_rps_Low=36, //!< directionPole_rps too low error code USER_ErrorCode_speedPole_rps_High=37, //!< speedPole_rps too high error code USER_ErrorCode_speedPole_rps_Low=38, //!< speedPole_rps too low error code USER_ErrorCode_dcBusPole_rps_High=39, //!< dcBusPole_rps too high error code USER_ErrorCode_dcBusPole_rps_Low=40, //!< dcBusPole_rps too low error code USER_ErrorCode_fluxFraction_High=41, //!< fluxFraction too high error code USER_ErrorCode_fluxFraction_Low=42, //!< fluxFraction too low error code USER_ErrorCode_indEst_speedMaxFraction_High=43, //!< indEst_speedMaxFraction too high error code USER_ErrorCode_indEst_speedMaxFraction_Low=44, //!< indEst_speedMaxFraction too low error code USER_ErrorCode_powerWarpGain_High=45, //!< powerWarpGain too high error code USER_ErrorCode_powerWarpGain_Low=46, //!< powerWarpGain too low error code USER_ErrorCode_systemFreq_MHz_High=47, //!< systemFreq_MHz too high error code USER_ErrorCode_systemFreq_MHz_Low=48, //!< systemFreq_MHz too low error code USER_ErrorCode_pwmFreq_kHz_High=49, //!< pwmFreq_kHz too high error code USER_ErrorCode_pwmFreq_kHz_Low=50, //!< pwmFreq_kHz too low error code USER_ErrorCode_voltage_sf_High=51, //!< voltage_sf too high error code USER_ErrorCode_voltage_sf_Low=52, //!< voltage_sf too low error code USER_ErrorCode_current_sf_High=53, //!< current_sf too high error code USER_ErrorCode_current_sf_Low=54, //!< current_sf too low error code USER_ErrorCode_voltageFilterPole_Hz_High=55, //!< voltageFilterPole_Hz too high error code USER_ErrorCode_voltageFilterPole_Hz_Low=56, //!< voltageFilterPole_Hz too low error code USER_ErrorCode_maxVsMag_pu_High=57, //!< maxVsMag_pu too high error code USER_ErrorCode_maxVsMag_pu_Low=58, //!< maxVsMag_pu too low error code USER_ErrorCode_estKappa_High=59, //!< estKappa too high error code USER_ErrorCode_estKappa_Low=60, //!< estKappa too low error code USER_ErrorCode_motor_type_Unknown=61, //!< motor type unknown error code USER_ErrorCode_motor_numPolePairs_High=62, //!< motor_numPolePairs too high error code USER_ErrorCode_motor_numPolePairs_Low=63, //!< motor_numPolePairs too low error code USER_ErrorCode_motor_ratedFlux_High=64, //!< motor_ratedFlux too high error code USER_ErrorCode_motor_ratedFlux_Low=65, //!< motor_ratedFlux too low error code USER_ErrorCode_motor_Rr_High=66, //!< motor_Rr too high error code USER_ErrorCode_motor_Rr_Low=67, //!< motor_Rr too low error code USER_ErrorCode_motor_Rs_High=68, //!< motor_Rs too high error code USER_ErrorCode_motor_Rs_Low=69, //!< motor_Rs too low error code USER_ErrorCode_motor_Ls_d_High=70, //!< motor_Ls_d too high error code USER_ErrorCode_motor_Ls_d_Low=71, //!< motor_Ls_d too low error code USER_ErrorCode_motor_Ls_q_High=72, //!< motor_Ls_q too high error code USER_ErrorCode_motor_Ls_q_Low=73, //!< motor_Ls_q too low error code USER_ErrorCode_maxCurrent_High=74, //!< maxCurrent too high error code USER_ErrorCode_maxCurrent_Low=75, //!< maxCurrent too low error code USER_ErrorCode_maxCurrent_resEst_High=76, //!< maxCurrent_resEst too high error code USER_ErrorCode_maxCurrent_resEst_Low=77, //!< maxCurrent_resEst too low error code USER_ErrorCode_maxCurrent_indEst_High=78, //!< maxCurrent_indEst too high error code USER_ErrorCode_maxCurrent_indEst_Low=79, //!< maxCurrent_indEst too low error code USER_ErrorCode_maxCurrentSlope_High=80, //!< maxCurrentSlope too high error code USER_ErrorCode_maxCurrentSlope_Low=81, //!< maxCurrentSlope too low error code USER_ErrorCode_maxCurrentSlope_powerWarp_High=82, //!< maxCurrentSlope_powerWarp too high error code USER_ErrorCode_maxCurrentSlope_powerWarp_Low=83, //!< maxCurrentSlope_powerWarp too low error code USER_ErrorCode_IdRated_High=84, //!< IdRated too high error code USER_ErrorCode_IdRated_Low=85, //!< IdRated too low error code USER_ErrorCode_IdRatedFraction_indEst_High=86, //!< IdRatedFraction_indEst too high error code USER_ErrorCode_IdRatedFraction_indEst_Low=87, //!< IdRatedFraction_indEst too low error code USER_ErrorCode_IdRatedFraction_ratedFlux_High=88, //!< IdRatedFraction_ratedFlux too high error code USER_ErrorCode_IdRatedFraction_ratedFlux_Low=89, //!< IdRatedFraction_ratedFlux too low error code USER_ErrorCode_IdRated_delta_High=90, //!< IdRated_delta too high error code USER_ErrorCode_IdRated_delta_Low=91, //!< IdRated_delta too low error code USER_ErrorCode_fluxEstFreq_Hz_High=92, //!< fluxEstFreq_Hz too high error code USER_ErrorCode_fluxEstFreq_Hz_Low=93, //!< fluxEstFreq_Hz too low error code USER_ErrorCode_ctrlFreq_Hz_High=94, //!< ctrlFreq_Hz too high error code USER_ErrorCode_ctrlFreq_Hz_Low=95, //!< ctrlFreq_Hz too low error code USER_ErrorCode_estFreq_Hz_High=96, //!< estFreq_Hz too high error code USER_ErrorCode_estFreq_Hz_Low=97, //!< estFreq_Hz too low error code USER_ErrorCode_RoverL_estFreq_Hz_High=98, //!< RoverL_estFreq_Hz too high error code USER_ErrorCode_RoverL_estFreq_Hz_Low=99, //!< RoverL_estFreq_Hz too low error code USER_ErrorCode_trajFreq_Hz_High=100, //!< trajFreq_Hz too high error code USER_ErrorCode_trajFreq_Hz_Low=101, //!< trajFreq_Hz too low error code USER_ErrorCode_ctrlPeriod_sec_High=102, //!< ctrlPeriod_sec too high error code USER_ErrorCode_ctrlPeriod_sec_Low=103, //!< ctrlPeriod_sec too low error code USER_ErrorCode_maxNegativeIdCurrent_a_High=104, //!< maxNegativeIdCurrent_a too high error code USER_ErrorCode_maxNegativeIdCurrent_a_Low=105, //!< maxNegativeIdCurrent_a too low error code USER_numErrorCodes=106 //!< the number of user error codes } USER_ErrorCode_e;
//! \brief Defines the controller (CTRL) version number //! typedef struct _CTRL_Version_ { uint16_t rsvd; //!< reserved value CTRL_TargetProc_e targetProc; //!< the target processor uint16_t major; //!< the major release number uint16_t minor; //!< the minor release number } CTRL_Version;
proj_lab05bのフローチャート
FlagCtrlStateChangedの中身
mainスレッド
void updateGlobalVariables_motor(CTRL_Handle handle)の中で、ループ中に随時パラメータの更新が行われています。したがって、これらのパラメータは基本的に読み込み専用です。
void updateGlobalVariables_motor(CTRL_Handle handle) { CTRL_Obj *obj = (CTRL_Obj *)handle; // get the speed estimate gMotorVars.Speed_krpm = EST_getSpeed_krpm(obj->estHandle); // get the real time speed reference coming out of the speed trajectory generator gMotorVars.SpeedTraj_krpm = _IQmpy(CTRL_getSpd_int_ref_pu(handle),EST_get_pu_to_krpm_sf(obj->estHandle)); // get the torque estimate gMotorVars.Torque_Nm = USER_computeTorque_Nm(handle, gTorque_Flux_Iq_pu_to_Nm_sf, gTorque_Ls_Id_Iq_pu_to_Nm_sf); // get the magnetizing current gMotorVars.MagnCurr_A = EST_getIdRated(obj->estHandle); // get the rotor resistance gMotorVars.Rr_Ohm = EST_getRr_Ohm(obj->estHandle); // get the stator resistance gMotorVars.Rs_Ohm = EST_getRs_Ohm(obj->estHandle); // get the stator inductance in the direct coordinate direction gMotorVars.Lsd_H = EST_getLs_d_H(obj->estHandle); // get the stator inductance in the quadrature coordinate direction gMotorVars.Lsq_H = EST_getLs_q_H(obj->estHandle); // get the flux in V/Hz in floating point gMotorVars.Flux_VpHz = EST_getFlux_VpHz(obj->estHandle); // get the flux in Wb in fixed point gMotorVars.Flux_Wb = USER_computeFlux(handle, gFlux_pu_to_Wb_sf); // get the controller state gMotorVars.CtrlState = CTRL_getState(handle); // get the estimator state gMotorVars.EstState = EST_getState(obj->estHandle); // Get the DC buss voltage gMotorVars.VdcBus_kV = _IQmpy(gAdcData.dcBus,_IQ(USER_IQ_FULL_SCALE_VOLTAGE_V/1000.0)); return; } // end of updateGlobalVariables_motor() function
パラメータアドレスの定義
#define Flag_enable 0x00 // bool #define Flag_Run_Identify 0x01 // bool #define Flag_MotorIdentified 0x02 // bool #define Flag_enableForceAngle 0x03 // bool #define Flag_enableFieldWeakening 0x04 // bool #define Flag_enableRsRecalc 0x05 // bool #define Flag_enableUserParam 0x06 // bool #define Flag_enableOffsetcalc 0x07 // bool #define Flag_enablePowerWarp 0x08 // bool #define Flag_enableSpeedCtrl 0x09 // bool #define Flag_enableRun 0x0A // bool #define Flag_RunState 0x0B // bool #define Flag_enableFlyingStart 0x0C // bool #define CtrlState 0x0D // CTRL_State_e #define EstState 0x0E // EST_State_e #define UserErrorCode 0x0F // USER_ErrorCode_e #define CtrlVersion 0x10 // CTRL_Version #define IdRef_A 0x14 // _iq #define IqRef_A 0x16 // _iq #define SpeedRef_pu 0x18 // _iq #define SpeedRef_krpm 0x1A // _iq #define SpeedTraj_krpm 0x1C // _iq #define MaxAccel_krpmps 0x1E // _iq #define Speed_krpm 0x20 // _iq #define OverModulation 0x22 // _iq #define RsOnLineCurrent_A 0x24 // _iq #define SvgenMaxModulation_ticks 0x26 // _iq #define Flux_Wb 0x28 // _iq #define Torque_Nm 0x2A // _iq #define MagnCurr_A 0x2C // float_t #define Rr_Ohm 0x2E // float_t #define Rs_Ohm 0x30 // float_t #define RsOnLine_Ohm 0x32 // float_t #define Lsd_H 0x34 // float_t #define Lsq_H 0x36 // float_t #define Flux_VpHz 0x38 // float_t #define ipd_excFreq_Hz 0x3A // float_t #define ipd_Kspd 0x3C // _iq #define ipd_excMag_coarse_pu 0x3E // _iq #define ipd_excMag_fine_pu 0x40 // _iq #define ipd_waitTime_coarse_set 0x42 // float #define ipd_waitTime_fine_sec 0x44 // float #define Kp_spq 0x46 // _iq #define Ki_spd 0x48 // _iq #define Kp_Idq 0x4A // _iq #define Kp_Idq 0x4C // _iq #define Vd 0x4E // _iq #define Vq 0x50 // _iq #define Vs 0x52 // _iq #define VsRef 0x54 // _iq #define VdcBufKV 0x56 // _iq #define Id_A 0x58 // _iq #define Iq_A 0x5A // _iq #define Is_A 0x5C // _iq #define I_bias 0x5E // MATH_vec3 #define V_bias 0x64 // MATH_vec3 #define SpeedSet_krpm 0x6A // _iq #define angle_sen_pu 0x6C // _iq #define angle_est_pu 0x6E // _iq #define speed_sen_pu 0x70 // _iq #define speed_est_pu 0x72 // _iq #define speedHigh_hall2fast_pu 0x74 // _iq #define speedLow_hall2fast_pu 0x76 // _iq