SPRUHJ1I 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
This should be done in the main function of the project ahead of the forever loop. This will load all of the default values into SpinTAC Velocity Plan. This step can be completed by running the function ST_init that is declared in the spintac_velocity.h header file and the function ST_setupVelPlan that is declared in the main.c. If you do not wish to use these two functions, the code example below can be used to configure the SpinTAC Velocity Plan component. This example loads the washing machine profile that is discussed in Section 14.4.5. For more information about the SpinTAC Plan API, see Section 4.6.3.1.
// init the ST VelPlan object
stVelPlanHandle = STVELPLAN_init(&stVelPlan, sizeof(ST_VelPlan_t));
// Pass the configuration array pointer into SpinTAC Velocity Plan
// Parameters: handle, pointer to array, size of array, number of actions, number of
conditions, number of variables, number of transitions, number of states
STVELPLAN_setCfgArray(stVelPlanHandle, &stVelPlanCfgArray[0], sizeof(stVelPlanCfgArray), 6, 4, 5, 7, 6);
// Establish the Velocity, Acceleration, and Jerk Maximums
_iq velMax = STVELMOVE_getVelocityMaximum(stVelMoveHandle);
_iq accMax = STVELMOVE_getAccelerationMaximum(stVelMoveHandle);
_iq jrkMax = STVELMOVE_getJerkMaximum(stVelMoveHandle);
// Configure SpinTAC Velocity Plan: Sample Time, VelMax, AccMax, DecMax, JrkMax, LoopENB
STVELPLAN_setCfg(stVelPlanHandle, _IQ24(ST_SPEED_SAMPLE_TIME),
velMax, accMax, jrkMax, FALSE);
// Configure halt state: VelEnd, AccMax, JrkMax, Timer
STVELPLAN_setCfgHaltState(stVelPlanHandle, 0, accMax, jrkMax, 1000L);
//Example: STVELPLAN_addCfgState(handle, VelSetpoint[pups], StateTimer[ticks]);
//StateIdx0: Idle
STVELPLAN_addCfgState(stVelPlanHandle, 0, 2000L);
// StateIdx1: Fill
STVELPLAN_addCfgState(stVelPlanHandle, 0, 2000L);
// StateIdx2: AgiCW
STVELPLAN_addCfgState(stVelPlanHandle, _IQ24(0.25 * ST_SPEED_PU_PER_KRPM), 200L);
// StateIdx3: AgiCCW
STVELPLAN_addCfgState(stVelPlanHandle, _IQ24(-0.25 * ST_SPEED_PU_PER_KRPM), 200L);
// StateIdx4: Drain
STVELPLAN_addCfgState(stVelPlanHandle, 0, 2000L);
// StateIdx5: Dry
STVELPLAN_addCfgState(stVelPlanHandle, _IQ24(2 * ST_SPEED_PU_PER_KRPM), 2000L);
//Example: STVELPLAN_addCfgVar(handle, VarType, InitialValue);
// VarIdx0: FillSensor {0: not filled; 1: filled}
STVELPLAN_addCfgVar(stVelPlanHandle, ST_VAR_IN, 0);
// VarIdx1: DrainSensor {0: not drained; 1: drained}
STVELPLAN_addCfgVar(stVelPlanHandle, ST_VAR_IN, 0);
// VarIdx2: CycleCounter
STVELPLAN_addCfgVar(stVelPlanHandle, ST_VAR_INOUT, 0);
// VarIdx3: FillValve {0: valve closed; 1: valve open}
STVELPLAN_addCfgVar(stVelPlanHandle, ST_VAR_OUT, 0);
// VarIdx4: DrainValve {0: valve closed; 1: valve open}
STVELPLAN_addCfgVar(stVelPlanHandle, ST_VAR_OUT, 0);
//Example: STVELPLAN_addCfgCond(handle, VarIdx, Comparison, Value1, Value2)
// CondIdx0: WaterFull Water is filled
STVELPLAN_addCfgCond(stVelPlanHandle, 0, ST_COMP_EQ, 1, 0);
// CondIdx0: AgiNotDone SgitCycleCounter is greater than 0 (not done)
STVELPLAN_addCfgCond(stVelPlanHandle, 2, ST_COMP_GT, 0, 0);
// CondIdx1: AgiDone SgitCycleCounter is equal or less than 0 (done)
STVELPLAN_addCfgCond(stVelPlanHandle, 2, ST_COMP_ELW, 0, 0);
// CondIdx0: WaterEmpty Water is drained
STVELPLAN_addCfgCond(stVelPlanHandle, 1, ST_COMP_EQ, 1, 0);
// Note: Set Value2 to 0 if Comparison is for only one value.
//Example: STVELPLAN_addCfgTran(handle, FromState, ToState, CondOption, CondIdx1,
CondiIdx2, AccLim[pups2], JrkLim[pups3]);
// From IdleState to FillState
STVELPLAN_addCfgTran(stVelPlanHandle, 0, 1, ST_COND_NC, 0, 0, _IQ24(0.1), _IQ20(1));
// From FillState to AgiState1
STVELPLAN_addCfgTran(stVelPlanHandle, 1, 2, ST_COND_FC, 0, 0, _IQ24(0.1), _IQ20(1));
// From AgiState1 to AgiState2
STVELPLAN_addCfgTran(stVelPlanHandle, 2, 3, ST_COND_NC, 0, 0, _IQ24(1), _IQ20(1));
// From AgiState2 to AgiState1
STVELPLAN_addCfgTran(stVelPlanHandle, 3, 2, ST_COND_FC, 1, 0, _IQ24(1), _IQ20(1));
// From AgiState2 to DrainState
STVELPLAN_addCfgTran(stVelPlanHandle, 3, 4, ST_COND_FC, 2, 0, _IQ24(0.1), _IQ20(1));
// From DrainState to DryState
STVELPLAN_addCfgTran(stVelPlanHandle, 4, 5, ST_COND_FC, 3, 0, _IQ24(0.2), _IQ20(1));
// From DryState to IdleState
STVELPLAN_addCfgTran(stVelPlanHandle, 5, 0, ST_COND_NC, 0, 0, _IQ24(0.1), _IQ20(1));
// Note: set CondIdx1 to 0 if CondOption is ST_COND_NC; set CondIdx2 to 0 if CondOption is ST_COND_NC or ST_COND_FC
//Example: STVELPLAN_addCfgAct(handle, StateIdx, VarIdx, Operation, Value, ActionTriger);
// In IdleState, preset AgiCycleCounter to 20
STVELPLAN_addCfgAct(stVelPlanHandle, 0, ST_COND_NC, 0, 0, 2, ST_ACT_EQ, 20, ST_ACT_EXIT);
// Decrease AgiCycleCounter by 1 every time enters AgiState1
STVELPLAN_addCfgAct(stVelPlanHandle, 2, ST_COND_NC, 0, 0, 2, ST_ACT_ADD, -1, ST_ACT_ENTR);
// In FillState, set VarIdx3 to 1 to open FillValve
STVELPLAN_addCfgAct(stVelPlanHandle, 1, ST_COND_NC, 0, 0, 3, ST_ACT_EQ, 1, ST_ACT_ENTR);
// In FillState, set VarIdx3 to 0 to close FillValve when FillSensor = 1
STVELPLAN_addCfgAct(stVelPlanHandle, 1, ST_COND_NC, 0, 0, 3, ST_ACT_EQ, 0, ST_ACT_EXIT);
// In DrainState, set VarIdx4 to 1 to open DrainValve
STVELPLAN_addCfgAct(stVelPlanHandle, 4, ST_COND_NC, 0, 0, 4, ST_ACT_EQ, 1, ST_ACT_ENTR);
// In DrainState, set VarIdx4 to 0 to close DrainValve when DrainSensor = 1
STVELPLAN_addCfgAct(stVelPlanHandle, 4, ST_COND_NC, 0, 0, 4, ST_ACT_EQ, 0, ST_ACT_EXIT);
// If there was an error during the configuration, force Plan into the Halt State
if(STVELPLAN_getErrorID(stVelPlanHandle) != FALSE) {
// Configure FSM: Ts, VelMax, AccMax, DecMax, JrkMax, LoopENB
STVELPLAN_setCfg(stVelPlanHandle, _IQ24(ST_SPEED_SAMPLE_TIME),
velMax, accMax, jrkMax, FALSE);
// Configure halt state: VelEnd, AccMax, JrkMax, Timer
STVELPLAN_setCfgHaltState(stVelPlanHandle, 0, accMax, jrkMax, 1000L);}