ZHCU083I January 2013 – October 2021 TMS320F2802-Q1 , TMS320F28026-Q1 , TMS320F28026F , TMS320F28027-Q1 , TMS320F28027F , TMS320F28027F-Q1 , TMS320F28052-Q1 , TMS320F28052F , TMS320F28052F-Q1 , TMS320F28052M , TMS320F28052M-Q1 , TMS320F28054-Q1 , TMS320F28054F , TMS320F28054F-Q1 , TMS320F28054M , TMS320F28054M-Q1 , TMS320F2806-Q1 , TMS320F28062-Q1 , TMS320F28062F , TMS320F28062F-Q1 , TMS320F28068F , TMS320F28068M , TMS320F28069-Q1 , TMS320F28069F , TMS320F28069F-Q1 , TMS320F28069M , TMS320F28069M-Q1
这应该在死循环之前的项目主函数中完成。这样会将所有的默认值加载到 SpinTAC 位置移动计划中。该步骤可通过运行函数 ST_init(已在 spintac_position.h 头文件中声明)和函数 ST_setupPosPlan(已在 main.c 中声明)来完成。如果不希望使用该函数,可使用下方的代码示例配置 SpinTAC 位置规划组件。本示例加载的是Topic Link Label14.5.6 中介绍的自动售货机系统配置。有关 SpinTAC Plan API 的详细信息,请参见图 4-19。
// Pass the configuration array pointer into SpinTAC Velocity Plan
STPOSPLAN_setCfgArray(stPosPlanHandle, &stPosPlanCfgArray[0],
sizeof(stPosPlanCfgArray), 4, 6, 6, 6, 5);
// Establish the Velocity, Acceleration, Deceleration, and Jerk Maximums
velMax = STPOSMOVE_getVelocityMaximum(stPosMoveHandle);
accMax = STPOSMOVE_getAccelerationMaximum(stPosMoveHandle);
decMax = STPOSMOVE_getDecelerationMaximum(stPosMoveHandle);
jrkMax = STPOSMOVE_getJerkMaximum(stPosMoveHandle);
// Establish the Velocity, Acceleration, Deceleration, and Jerk Limits
velLim = _IQ24(0.1 * ST_SPEED_PU_PER_KRPM);
accLim = _IQ24(0.5 * ST_SPEED_PU_PER_KRPM);
decLim = _IQ24(0.5 * ST_SPEED_PU_PER_KRPM);
jrkLim = _IQ24(1.0 * ST_SPEED_PU_PER_KRPM);
// Configure SpinTAC Velocity Plan: Sample Time, VelMax, AccMax, DecMax, JrkMax, LoopENB
STPOSPLAN_setCfg(stPosPlanHandle, _IQ24(ST_SAMPLE_TIME), velMax, accMax, decMax, jrkMax, false);
// Configure halt state: PosStepInt, PosStepFrac, VelMax, AccMax, JrkMax, Timer
STPOSPLAN_setCfgHaltState(stPosPlanHandle, 0, 0, velMax, accMax, jrkMax, 1000L);
//Example: STPOSPLAN_addCfgState(handle, PosStepInt[MRev], PosStepFrac[MRev], StateTimer[ticks]);
STPOSPLAN_addCfgState(stPosPlanHandle, 0, 0, 200L); // StateIdx0: Init
STPOSPLAN_addCfgState(stPosPlanHandle, 0, _IQ24(0.25), 200L); // StateIdx1: Item0
STPOSPLAN_addCfgState(stPosPlanHandle, 0, _IQ24(0.25), 200L); // StateIdx2: Item1
STPOSPLAN_addCfgState(stPosPlanHandle, 0, _IQ24(0.25), 200L); // StateIdx2: Item2
STPOSPLAN_addCfgState(stPosPlanHandle, 0, _IQ24(0.25), 200L); // StateIdx2: Item3
//Example: STPOSPLAN_addCfgVar(handle, VarType, InitialValue);
STPOSPLAN_addCfgVar(stPosPlanHandle, ST_VAR_INOUT, 0); // VarIdx0: FwdButton
STPOSPLAN_addCfgVar(stPosPlanHandle, ST_VAR_IN, 10); // VarIdx1: Item0Inv
STPOSPLAN_addCfgVar(stPosPlanHandle, ST_VAR_IN, 10); // VarIdx2: Item1Inv
STPOSPLAN_addCfgVar(stPosPlanHandle, ST_VAR_IN, 10); // VarIdx3: Item2Inv
STPOSPLAN_addCfgVar(stPosPlanHandle, ST_VAR_IN, 10); // VarIdx4: Item3Inv
STPOSPLAN_addCfgVar(stPosPlanHandle, ST_VAR_IN, 40); // VarIdx5: TotalInv
//Example: STPOSPLAN_addCfgCond(handle, VarIdx, Comparison, Value1, Value2)
// CondIdx0: Fwd Button Pressed
STPOSPLAN_addCfgCond(stPosPlanHandle, 0, ST_COMP_EQ, 1, 0);
// CondIdx1: Item0 Empty
STPOSPLAN_addCfgCond(stPosPlanHandle, 1, ST_COMP_ELW, 0, 0);
// CondIdx2: Item1 Empty
STPOSPLAN_addCfgCond(stPosPlanHandle, 2, ST_COMP_ELW, 0, 0);
// CondIdx3: Item2 Empty
STPOSPLAN_addCfgCond(stPosPlanHandle, 3, ST_COMP_ELW, 0, 0);
// CondIdx4: Item3 Empty
STPOSPLAN_addCfgCond(stPosPlanHandle, 4, ST_COMP_ELW, 0, 0);
// CondIdx5: TotalInv Empty
STPOSPLAN_addCfgCond(stPosPlanHandle, 5, ST_COMP_ELW, 0, 0);
//Example: STPOSPLAN_addCfgTran(handle, FromState, ToState, CondOption, CondIdx1, CondIdx2, VelLim[pups], AccLim[pups2], DecLim[pups2], JrkLim[pups3]);
// NOTE: The deceleration limit must be set between the following bounds [acceleration limit, 10*acceleration limit]
// From Init to Item1
STPOSPLAN_addCfgTran(stPosPlanHandle, 0, 2, ST_COND_OR, 0, 2, velLim, accLim, decLim, jrkLim);
// From Item3 to Init
STPOSPLAN_addCfgTran(stPosPlanHandle, 1, 0, ST_COND_FC, 5, 0, velLim, accLim, decLim, jrkLim);
// From Item0 to Item1
STPOSPLAN_addCfgTran(stPosPlanHandle, 1, 2, ST_COND_OR, 0, 1, velLim, accLim, decLim, jrkLim);
// From Item1 to Item2
STPOSPLAN_addCfgTran(stPosPlanHandle, 2, 3, ST_COND_OR, 0, 2, velLim, accLim, decLim, jrkLim);
// From Item2 to Item3
STPOSPLAN_addCfgTran(stPosPlanHandle, 3, 4, ST_COND_OR, 0, 3, velLim, accLim, decLim, jrkLim);
// From Item3 to Item0
STPOSPLAN_addCfgTran(stPosPlanHandle, 4, 1, ST_COND_OR, 0, 4, velLim, accLim, decLim, jrkLim);
//Example: STPOSPLAN_addCfgAct(handle, StateIdx, VarIdx, Operation, Value, ActionTriger);
// In Item1, clear Fwd Button
STPOSPLAN_addCfgAct(stPosPlanHandle, 1, ST_COND_NC, 0, 0, 0, ST_ACT_ENTR);
// In Item2, clear Fwd Button
STPOSPLAN_addCfgAct(stPosPlanHandle, 2, ST_COND_NC, 0, 0, 0, ST_ACT_ENTR);
// In Item3, clear Fwd Button
STPOSPLAN_addCfgAct(stPosPlanHandle, 3, ST_COND_NC, 0, 0, 0, ST_ACT_ENTR);
// In Item4, clear Fwd Button
STPOSPLAN_addCfgAct(stPosPlanHandle, 4, ST_COND_NC, 0, 0, 0, ST_ACT_ENTR);
if(STPOSPLAN_getErrorID(stPosPlanHandle) != false) {
// Configure FSM: Ts, VelMax, AccMax, DecMax, JrkMax, LoopENB
STPOSPLAN_setCfg(stPosPlanHandle, _IQ24(ST_SAMPLE_TIME), velMax, accMax, decMax, jrkMax, false);
// Configure halt state: PosStepInt[MRev], PosStepFrac[MRev], VelMax, AccMax, JrkMax, Timer
STPOSPLAN_setCfgHaltState(stPosPlanHandle, 0, 0, velMax, accMax, jrkMax, 1000L);
}