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 Position Plan
if(gPosPlanRunFlag == ST_PLAN_STOP
&& gMotorVars.SpinTAC.PosPlanRun == ST_PLAN_START) {
if(STPOSMOVE_getDone(stPosMoveHandle) == true) {
if(STPOSPLAN_getErrorID(stPosPlanHandle) != false) {
STPOSPLAN_setEnable(stPosPlanHandle, false);
STPOSPLAN_setReset(stPosPlanHandle, true);
gMotorVars.SpinTAC.PosPlanRun = gPosPlanRunFlag;
}
else {
STPOSPLAN_setEnable(stPosPlanHandle, true);
STPOSPLAN_setReset(stPosPlanHandle, false);
gPosPlanRunFlag = gMotorVars.SpinTAC.PosPlanRun;
}
}
}
if(gMotorVars.SpinTAC.PosPlanRun == ST_PLAN_STOP) {
STPOSPLAN_setReset(stPosPlanHandle, true);
gPosPlanRunFlag = gMotorVars.SpinTAC.PosPlanRun;
}
if(gPosPlanRunFlag == ST_PLAN_START
&& gMotorVars.SpinTAC.PosPlanRun == ST_PLAN_PAUSE) {
STPOSPLAN_setEnable(stPosPlanHandle, false);
gPosPlanRunFlag = gMotorVars.SpinTAC.PosPlanRun;
}
if(gPosPlanRunFlag == ST_PLAN_PAUSE
&& gMotorVars.SpinTAC.PosPlanRun == ST_PLAN_START) {
STPOSPLAN_setEnable(stPosPlanHandle, true);
gPosPlanRunFlag = gMotorVars.SpinTAC.PosPlanRun;
}
// if we have selected an item from the machine
if(gVendSelectButton == 1) {
if(STPOSPLAN_getStatus(stPosPlanHandle) != ST_PLAN_IDLE) {
// decrease our inventory
gVendInventory[gVendAvailableItem - 1]--;
}
// toggle the select button off
gVendSelectButton = 0;
}
// Update variables passed into Plan
STPOSPLAN_setVar(stPosPlanHandle, VEND_Fwd, gVendFwdButton);
STPOSPLAN_setVar(stPosPlanHandle, VEND_Item0Inv, gVendInventory[VEND_ITEM0 - 1]);
STPOSPLAN_setVar(stPosPlanHandle, VEND_Item1Inv, gVendInventory[VEND_ITEM1 - 1]);
STPOSPLAN_setVar(stPosPlanHandle, VEND_Item2Inv, gVendInventory[VEND_ITEM2 - 1]);
STPOSPLAN_setVar(stPosPlanHandle, VEND_Item3Inv, gVendInventory[VEND_ITEM3 - 1]);
STPOSPLAN_setVar(stPosPlanHandle, VEND_TotalInv,
gVendInventory[0] + gVendInventory[1] + gVendInventory[2] + gVendInventory[3]);
// Run SpinTAC Position Plan
STPOSPLAN_run(stPosPlanHandle);
// display the selected item
if(STPOSPLAN_getCurrentState(stPosPlanHandle) > 0) {
gVendAvailableItem = (VEND_State_e)STPOSPLAN_getCurrentState(stPosPlanHandle);
}
else {
gVendAvailableItem = VEND_ITEM0;
}
// Update variables passed out of Plan
if(STPOSPLAN_getFsmState(stPosPlanHandle) == ST_FSM_STATE_STAY) {
STPOSPLAN_getVar(stPosPlanHandle, VEND_Fwd, &gVendFwdButton);
}
if(STPOSPLAN_getStatus(stPosPlanHandle) != ST_PLAN_IDLE) {
// Send the profile configuration to SpinTAC Position Profile Generator
STPOSPLAN_getPositionStep_mrev(stPosPlanHandle,
(_iq24 *)&gMotorVars.PosStepInt_MRev, (_iq24 *)&gMotorVars.PosStepFrac_MRev);
gMotorVars.MaxVel_krpm = _IQmpy(STPOSPLAN_getVelocityLimit(stPosPlanHandle),
_IQ24(ST_SPEED_KRPM_PER_PU));
gMotorVars.MaxAccel_krpmps =_IQmpy(STPOSPLAN_getAccelerationLimit(stPosPlanHandle),
_IQ24(ST_SPEED_KRPM_PER_PU));
gMotorVars.MaxDecel_krpmps =_IQmpy(STPOSPLAN_getDecelerationLimit(stPosPlanHandle),
_IQ24(ST_SPEED_KRPM_PER_PU));
gMotorVars.MaxJrk_krpmps2 = _IQ20mpy(STPOSPLAN_getJerkLimit(stPosPlanHandle),
_IQ20(ST_SPEED_KRPM_PER_PU));
}
else {
if(gPosPlanRunFlag == ST_PLAN_START
&& gMotorVars.SpinTAC.PosPlanRun == ST_PLAN_START)
{
gMotorVars.SpinTAC.PosPlanRun = ST_PLAN_STOP;
gPosPlanRunFlag = gMotorVars.SpinTAC.PosPlanRun;
}
}