初始化設定
在硬體與 KINGSTAR 子系統建立 EtherCAT 連結時,我們需在連接狀態變為 Op 之前初始化一些設定,信號指示 EtherCAT 連結是否建立之旗標 OPFlag 放在 Start 之後(請見 連接鈕 > Start the KINGSTAR Subsystem),當 OPFlag 為 false,表示連結尚未建立,此時我們清除裝置清單並使用 for 迴圈初始化軸之設定。
初始化使用下列 KINGSTAR 方法:
- SetAxisMotionProfile:設定軸之運動軌跡。範例中之運動軌跡定義於 McProfileSettings 類別的實例
ProfileSettings中。 - SetAxisCountsPerUnit:將使用者自定義位置單位的轉換比例設定為軸使用的計數(脈衝)單位,在此範例中,
Numerator和Denominator為一,因此比率為 1:1,Reverse為 false,因此軸的方向未倒轉。 - EnableAxisUnitConversion:啟用軸使用真實世界單位。使用 SetAxisCountsPerUnit 設定轉換比率後,需使用此方法來啟用轉換,此比率才會生效。
- GetAxisByIndex:獲取軸資訊。
初始化設定配置完成後,將 OPFlag 設為 true。
private void t_Staus_Tick(object sender, EventArgs e)
{
.........
if (OPFlag == false)
{
lbMList.Items.Clear();
for (int i = 0; i < KSMStatus.AxesCount; i++)
{
//Sets the unit of acceleration and jerk for an axis.
motion.SetAxisMotionProfile(i, ProfileSettings);
//Sets the conversion ratio of user-defined position unit to the count (pulse) unit used by the axis.
motion.SetAxisCountsPerUnit(i, Numerator, Denominator, Reverse);
//Enables the axis to use a real-world unit.
motion.EnableAxisUnitConversion(i, true);
}
for (int i = 0; i < KSMStatus.AxesCount; i++)
{
//Gets the details information of an axis.
KSMAxisDetails[i]=KS_API.GetAxisByIndex(i);
}
.........
OPFlag = true;
.........
}