中间件界面 新增 位置刷新; 屏蔽EF3后,调整 回家到位的判断
This commit is contained in:
+83
-95
@@ -21,6 +21,8 @@ namespace HexcalMC
|
||||
private readonly Api _acs;
|
||||
private readonly int _motionTimeout = 50000; //延时时间
|
||||
|
||||
private readonly MainFrom mainFrom;
|
||||
|
||||
|
||||
private readonly Axis[] UseAxis = MainFrom.UseAxis; //获取激活的轴
|
||||
private MotionStates _currentMotionState = MotionStates.None; //运动状态
|
||||
@@ -29,6 +31,10 @@ namespace HexcalMC
|
||||
|
||||
private bool _mBConnected;
|
||||
private Button[] _mBtnOutput;
|
||||
|
||||
|
||||
//定义Jog运动 速度
|
||||
private double _mJogVel = 10.0f;
|
||||
private Label[] _mLblInput;
|
||||
|
||||
|
||||
@@ -46,8 +52,6 @@ namespace HexcalMC
|
||||
private int _mNValues, _mNOutputState;
|
||||
private object _mObjReadVar;
|
||||
|
||||
private readonly MainFrom mainFrom;
|
||||
|
||||
public Motion(MainFrom mainFrom)
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -247,21 +251,15 @@ namespace HexcalMC
|
||||
|
||||
_mBConnected = _acs.IsConnected;
|
||||
// Get Total number of axes
|
||||
// Using Transaction function : return string text from controller, we need to convert to integer value
|
||||
strTemp = _acs.Transaction("?SYSINFO(13)");
|
||||
_mNTotalAxis = Convert.ToInt32(strTemp.Trim());
|
||||
|
||||
// Using Sysinfo function
|
||||
//_ACS.GetSysInfo(_ACS.ACSC_SYS_NAXES_KEY, out lfTemp);
|
||||
|
||||
// When we are using multi axes command (ex) ToPointM, HaltM, ...), we need to allocate the array size more 1.
|
||||
// Because of the last delimeter (-1)
|
||||
_mArrAxisList = new Axis[_mNTotalAxis + 1];
|
||||
//for (i = 0; i < _mNTotalAxis; i++)
|
||||
//{
|
||||
// cboAxisNo.Items.Add(i.ToString());
|
||||
// _mArrAxisList[i] = (Axis)i;
|
||||
//}
|
||||
for (i = 0; i < _mNTotalAxis; i++)
|
||||
{
|
||||
cboAxisNo.Items.Add(i.ToString());
|
||||
_mArrAxisList[i] = (Axis)i;
|
||||
}
|
||||
|
||||
// Insert '-1' at the last
|
||||
_mArrAxisList[_mNTotalAxis] = Axis.ACSC_NONE;
|
||||
@@ -332,11 +330,6 @@ namespace HexcalMC
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Terminate connections from SPiiPlus User Mode Driver
|
||||
/// 终止来自 SPiiPlus 用户模式驱动程序的连接
|
||||
/// - Maximum connections up to 10 in UMD
|
||||
/// </summary>
|
||||
private void TernminateUMD_Connection()
|
||||
{
|
||||
try
|
||||
@@ -462,6 +455,9 @@ namespace HexcalMC
|
||||
|
||||
_mNOutputState = _acs.GetOutputPort(0); // _ACS.ReadVariableAsVector("OUT", -1, 0, 0, -1, -1);
|
||||
UpdateIoState(_mNOutputState, false);
|
||||
|
||||
//刷新平台位置
|
||||
UpdatePostion();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -471,8 +467,8 @@ namespace HexcalMC
|
||||
}
|
||||
}
|
||||
|
||||
// Update limit state
|
||||
private void UpdateLimitState(int axisNo, int fault)
|
||||
|
||||
private void UpdateLimitState(int axisNo, int fault) //刷新限位状态
|
||||
{
|
||||
if (axisNo < MaxUiLimitCnt)
|
||||
{
|
||||
@@ -485,8 +481,8 @@ namespace HexcalMC
|
||||
}
|
||||
}
|
||||
|
||||
// Update general I/O stae
|
||||
private void UpdateIoState(int value, bool isInput)
|
||||
|
||||
private void UpdateIoState(int value, bool isInput) //刷新IO状态
|
||||
{
|
||||
int bitUpCnt = 0x01;
|
||||
|
||||
@@ -518,6 +514,24 @@ namespace HexcalMC
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdatePostion()
|
||||
{
|
||||
Point3D _mPoint3D = mainFrom._mPoint3D;
|
||||
|
||||
//更新实时位置
|
||||
if (_mPoint3D != null)
|
||||
{
|
||||
lbl_X_current.Text = _mPoint3D.X.ToString("F3");
|
||||
lbl_Y_current.Text = _mPoint3D.Y.ToString("F3");
|
||||
lbl_z_current.Text = _mPoint3D.Z.ToString("F3");
|
||||
}
|
||||
|
||||
//设置目标位置
|
||||
lbl_X_target.Text = textBox_x.Text;
|
||||
lbl_Y_target.Text = textBox_y.Text;
|
||||
lbl_Z_target.Text = textBox_z.Text;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 电机使能
|
||||
@@ -618,7 +632,7 @@ namespace HexcalMC
|
||||
{
|
||||
try
|
||||
{
|
||||
Axis[] m_arrAxisList = new Axis[] { Axis.ACSC_AXIS_0, Axis.ACSC_AXIS_1, Axis.ACSC_AXIS_8, Axis.ACSC_NONE };
|
||||
Axis[] m_arrAxisList = { Axis.ACSC_AXIS_0, Axis.ACSC_AXIS_1, Axis.ACSC_AXIS_8, Axis.ACSC_NONE };
|
||||
|
||||
if (_mArrAxisList != null) _acs.HaltM(m_arrAxisList);
|
||||
}
|
||||
@@ -995,7 +1009,7 @@ namespace HexcalMC
|
||||
|
||||
#region 按钮
|
||||
|
||||
private void btn_movepose_Click(object sender, EventArgs e)
|
||||
private void Btn_MovePose_Click(object sender, EventArgs e)
|
||||
{
|
||||
//判断是否为textBox_x空
|
||||
if (string.IsNullOrWhiteSpace(textBox_x.Text) || string.IsNullOrEmpty(textBox_y.Text) ||
|
||||
@@ -1020,17 +1034,23 @@ namespace HexcalMC
|
||||
_point3D.Y,
|
||||
_point3D.Z
|
||||
};
|
||||
|
||||
//判断电机状态
|
||||
if (!mainFrom.totalAxisEnabled)
|
||||
{
|
||||
DebugDfn.AddLogText("存在电机未使能");
|
||||
|
||||
_acs.EnableM(UseAxis);
|
||||
for (int i = 0; i < UseAxis.Length; i++)
|
||||
{
|
||||
_acs.WaitMotorEnabled(UseAxis[i], 1, _motionTimeout); //等待电机使能
|
||||
}
|
||||
|
||||
DebugDfn.AddLogText("电机已启用");
|
||||
}
|
||||
|
||||
//执行运动指令
|
||||
_acs.ToPointM(MotionFlags.ACSC_NONE, UseAxis, pointsArray); //多轴运动到指定位置
|
||||
|
||||
////等待运动完成
|
||||
//for (int i = 0; i < USE_AXIS.Length; i++)
|
||||
//{
|
||||
// _acs.WaitMotionEnd(USE_AXIS[i], _motionTimeout); //等待回家完成
|
||||
//}
|
||||
|
||||
//_currentMotionState = MotionStates.InPos;
|
||||
//DebugDfn.AddLogText("运动到位");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1050,7 +1070,7 @@ namespace HexcalMC
|
||||
};
|
||||
|
||||
//判断电机状态
|
||||
if (!this.mainFrom.totalAxisEnabled)
|
||||
if (!mainFrom.totalAxisEnabled)
|
||||
{
|
||||
DebugDfn.AddLogText("存在电机未使能");
|
||||
|
||||
@@ -1078,18 +1098,18 @@ namespace HexcalMC
|
||||
|
||||
private void btn_X_left_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
double lfVelocity = 0.0f;
|
||||
try
|
||||
{
|
||||
if (chkUseVel.Checked)
|
||||
{
|
||||
lfVelocity = Convert.ToDouble(txtJogVel.Text.Trim());
|
||||
if (lfVelocity > 0) lfVelocity = lfVelocity * -1; // Negative direction : Using - (minus) velocity
|
||||
_mJogVel = Convert.ToDouble(txtJogVel.Text.Trim());
|
||||
if (_mJogVel > 0) _mJogVel = _mJogVel * -1; // Negative direction : Using - (minus) velocity
|
||||
DebugDfn.AddLogText("X左移速度: " + _mJogVel);
|
||||
|
||||
_acs.Jog(
|
||||
MotionFlags.ACSC_AMF_VELOCITY, // Velocity flag 速度标志
|
||||
Axis.ACSC_AXIS_1, // Axis number
|
||||
lfVelocity // Velocity
|
||||
_mJogVel // Velocity
|
||||
);
|
||||
}
|
||||
else
|
||||
@@ -1105,19 +1125,20 @@ namespace HexcalMC
|
||||
|
||||
private void btn_X_right_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
double lfVelocity = 0.0f;
|
||||
try
|
||||
{
|
||||
if (chkUseVel.Checked)
|
||||
{
|
||||
lfVelocity = Convert.ToDouble(txtJogVel.Text.Trim());
|
||||
if (lfVelocity > 0) lfVelocity = lfVelocity * -1; // Negative direction : Using - (minus) velocity
|
||||
_mJogVel = Convert.ToDouble(txtJogVel.Text.Trim());
|
||||
|
||||
|
||||
_acs.Jog(
|
||||
MotionFlags.ACSC_AMF_VELOCITY, // Velocity flag 速度标志
|
||||
Axis.ACSC_AXIS_1, // Axis number
|
||||
lfVelocity // Velocity
|
||||
_mJogVel // Velocity
|
||||
);
|
||||
|
||||
DebugDfn.AddLogText("X右移速度: " + _mJogVel);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1132,19 +1153,19 @@ namespace HexcalMC
|
||||
|
||||
private void btn_Y_Forward_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
double lfVelocity = 0.0f;
|
||||
try
|
||||
{
|
||||
if (chkUseVel.Checked)
|
||||
{
|
||||
lfVelocity = Convert.ToDouble(txtJogVel.Text.Trim());
|
||||
if (lfVelocity > 0) lfVelocity = lfVelocity * -1; // Negative direction : Using - (minus) velocity
|
||||
_mJogVel = Convert.ToDouble(txtJogVel.Text.Trim());
|
||||
if (_mJogVel > 0) _mJogVel = _mJogVel * -1; // Negative direction : Using - (minus) velocity
|
||||
|
||||
_acs.Jog(
|
||||
MotionFlags.ACSC_AMF_VELOCITY, // Velocity flag 速度标志
|
||||
Axis.ACSC_AXIS_0, // Axis number
|
||||
lfVelocity // Velocity
|
||||
_mJogVel // Velocity
|
||||
);
|
||||
DebugDfn.AddLogText("Y前移速度: " + _mJogVel);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1160,19 +1181,20 @@ namespace HexcalMC
|
||||
|
||||
private void btn_Y_Back_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
double lfVelocity = 0.0f;
|
||||
try
|
||||
{
|
||||
if (chkUseVel.Checked)
|
||||
{
|
||||
lfVelocity = Convert.ToDouble(txtJogVel.Text.Trim());
|
||||
if (lfVelocity > 0) lfVelocity = lfVelocity * -1; // Negative direction : Using - (minus) velocity
|
||||
_mJogVel = Convert.ToDouble(txtJogVel.Text.Trim());
|
||||
|
||||
|
||||
_acs.Jog(
|
||||
MotionFlags.ACSC_AMF_VELOCITY, // Velocity flag 速度标志
|
||||
Axis.ACSC_AXIS_0, // Axis number
|
||||
lfVelocity // Velocity
|
||||
_mJogVel // Velocity
|
||||
);
|
||||
|
||||
DebugDfn.AddLogText("Y后移速度: " + _mJogVel);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1187,19 +1209,20 @@ namespace HexcalMC
|
||||
|
||||
private void btn_Z_Down_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
double lfVelocity = 0.0f;
|
||||
try
|
||||
{
|
||||
if (chkUseVel.Checked)
|
||||
{
|
||||
lfVelocity = Convert.ToDouble(txtJogVel.Text.Trim());
|
||||
if (lfVelocity > 0) lfVelocity = lfVelocity * -1; // Negative direction : Using - (minus) velocity
|
||||
_mJogVel = Convert.ToDouble(txtJogVel.Text.Trim());
|
||||
if (_mJogVel > 0) _mJogVel = _mJogVel * -1; // Negative direction : Using - (minus) velocity
|
||||
|
||||
_acs.Jog(
|
||||
MotionFlags.ACSC_AMF_VELOCITY, // Velocity flag 速度标志
|
||||
Axis.ACSC_AXIS_8, // Axis number
|
||||
lfVelocity // Velocity
|
||||
_mJogVel // Velocity
|
||||
);
|
||||
|
||||
DebugDfn.AddLogText("Z向下速度: " + _mJogVel);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1214,19 +1237,20 @@ namespace HexcalMC
|
||||
|
||||
private void btn_Z_Up_MouseDown(object sender, MouseEventArgs e)
|
||||
{
|
||||
double lfVelocity = 0.0f;
|
||||
try
|
||||
{
|
||||
if (chkUseVel.Checked)
|
||||
{
|
||||
lfVelocity = Convert.ToDouble(txtJogVel.Text.Trim());
|
||||
if (lfVelocity > 0) lfVelocity = lfVelocity * -1; // Negative direction : Using - (minus) velocity
|
||||
_mJogVel = Convert.ToDouble(txtJogVel.Text.Trim());
|
||||
|
||||
|
||||
_acs.Jog(
|
||||
MotionFlags.ACSC_AMF_VELOCITY, // Velocity flag 速度标志
|
||||
Axis.ACSC_AXIS_8, // Axis number
|
||||
lfVelocity // Velocity
|
||||
_mJogVel // Velocity
|
||||
);
|
||||
|
||||
DebugDfn.AddLogText("Z向上速度: " + _mJogVel);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1240,43 +1264,7 @@ namespace HexcalMC
|
||||
}
|
||||
|
||||
|
||||
private void btn_run_Click(object sender, EventArgs e)
|
||||
{
|
||||
//运动次数
|
||||
if (string.IsNullOrEmpty(textBox_cycleTimes.Text))
|
||||
{
|
||||
MessageBox.Show("循环次数不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
return;
|
||||
}
|
||||
|
||||
int times = Convert.ToInt32(textBox_cycleTimes.Text);
|
||||
DebugDfn.AddLogText("循环次数: " + times);
|
||||
|
||||
do
|
||||
{
|
||||
//X轴
|
||||
if (checkBox_X.Checked)
|
||||
{
|
||||
}
|
||||
|
||||
if (checkBox_y.Checked)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
if (checkBox_Z.Checked)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//开始运动
|
||||
|
||||
times = times - 1;
|
||||
DebugDfn.AddLogText($"当前为第{times}循环");
|
||||
} while (times > 0);
|
||||
|
||||
DebugDfn.AddLogText("循环结束");
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user