新增Hexcal中间件设置运动速度参数

This commit is contained in:
zhengxuan.zhang
2024-03-04 17:00:32 +08:00
parent 5a0a52629b
commit bab42c1ff8
11 changed files with 146 additions and 110 deletions
+1 -1
View File
@@ -469,7 +469,7 @@ HSI_STATUS HSI_Motion::Startup(HWND _hWnd, bool _bOfflineOnly)
handleACS = acsc_OpenCommSimulator();
#else
// 10.0.0.100 - default IP address of the controller
handleACS = acsc_OpenCommEthernet("10.0.0.100", ACSC_SOCKET_DGRAM_PORT);
handleACS = acsc_OpenCommEthernet("100.0.0.100", ACSC_SOCKET_DGRAM_PORT);
// for the connection to the controller via local network or Internet
// hComm = acsc_OpenCommEthernet("10.0.0.100", ACSC_SOCKET_STREAM_PORT);
+2 -2
View File
@@ -12,5 +12,5 @@
#define HSI_VERSION_REVNUM
#define HSI_VERSION_BUILD_DATE _T(__DATE__ )
#define HSI_VERSION_BUILD_TIME _T(__TIME__ )
#define HSI_FILE_DESCRIPTION "2024.02.28 / 14:55 "
#define HSI_FILE_CSDESCRIPTION _T("2024.02.28 / 14:55 ")
#define HSI_FILE_DESCRIPTION "2024.02.28 / 15:15 "
#define HSI_FILE_CSDESCRIPTION _T("2024.02.28 / 15:15 ")
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -1139,7 +1139,7 @@
this.txtIP.Name = "txtIP";
this.txtIP.Size = new System.Drawing.Size(91, 21);
this.txtIP.TabIndex = 22;
this.txtIP.Text = "10.0.0.100";
this.txtIP.Text = "100.0.0.100";
//
// btn_ACSStop
//
+125 -105
View File
@@ -32,8 +32,7 @@ namespace HexcalMC
public partial class MainFrom : RadRibbonForm
{
private List<Point3D> _pointCloud = new List<Point3D>(); //运动中点集合
private readonly List<Point3D> _pointCloud = new List<Point3D>(); //运动中点集合
public MainFrom()
@@ -41,7 +40,7 @@ namespace HexcalMC
InitializeComponent();
#region 3D
#region 3D
//var sharpGlViewportControl = new SharpGLViewportControl
//{
@@ -69,8 +68,6 @@ namespace HexcalMC
tabControl1.TabPages.RemoveAt(1);
#endregion
}
private void MainFrom_Load(object sender, EventArgs e)
@@ -83,9 +80,12 @@ namespace HexcalMC
//加载配置文件
LoadConfig();
_acs = new Api(); //初始化 ACS运动控制类
//启动界面刷新
timer_RefreshUI.Start();
this.TopMost = true;
}
private void MainFrom_Shown(object sender, EventArgs e) //窗体显示准备好接受用户输入时发生
@@ -93,7 +93,8 @@ namespace HexcalMC
//启动服务端,用于接收hexcal传来的指令
StartServer();
Btn_ACSStart_Click(null, null);
//Plot3D();
}
@@ -131,6 +132,7 @@ namespace HexcalMC
return;
}
MOTION_SPEED = FileIni.ReadDouble(StrConfigFile, "MOTOR", "MOTION_SPEED"); //运动定位速度
//正限位
X_MAXSTROKESW = FileIni.ReadDouble(StrConfigFile, "MOTOR", "X_MAXSTROKESW");
Y_MAXSTROKESW = FileIni.ReadDouble(StrConfigFile, "MOTOR", "Y_MAXSTROKESW");
@@ -147,6 +149,12 @@ namespace HexcalMC
// 清空画布
formsPlot1.Plot.Clear();
//pointCloud 是否为空
if (pointCloud.Count <= 0)
{
return;
}
List<double> dataX = new List<double>();
List<double> dataY = new List<double>();
@@ -172,8 +180,6 @@ namespace HexcalMC
}
#region
private Api _acs;
@@ -185,7 +191,7 @@ namespace HexcalMC
private int _mNTotalBuffer = 0;
private Axis[] _mArrAxisList = null;
private bool _mBConnected; //ACS通讯状态
private bool _mAcsConnected; //ACS通讯状态
// For update values
private MotorStates _mNMotorState; //运动状态
@@ -201,22 +207,23 @@ namespace HexcalMC
private HomeStates _homeStates; //回家状态
private MotionStates _currentMotionState; //当前运动状态
private readonly int _motionTimeout = 5000; //定义运动超时时间
private readonly int _motionTimeout = 50000; //定义运动超时时间
public static Axis[] USE_AXIS =
{ Axis.ACSC_AXIS_0, Axis.ACSC_AXIS_1, Axis.ACSC_AXIS_4, Axis.ACSC_NONE }; //定义启用的轴,后面运动时会使用
{ Axis.ACSC_AXIS_1, Axis.ACSC_AXIS_0, Axis.ACSC_AXIS_8, Axis.ACSC_NONE }; //定义启用的轴,后面运动时会使用
//定义 XYZ三个轴的左右行程范围
public string StrConfigFile = Application.StartupPath + "\\File\\config.ini";
public static double X_MAXSTROKESW = 100.0; //正限位
public static double Y_MAXSTROKESW = 50.0;
public static double Z_MAXSTROKESW = 10.0;
public static double MOTION_SPEED = 60;
public static double X_MAXSTROKESW = 730; //正限位
public static double Y_MAXSTROKESW = 1000;
public static double Z_MAXSTROKESW = 5;
public static double X_MINSTROKESW = -100.0; //负限位
public static double Y_MINSTROKESW = -50.0;
public static double Z_MINSTROKESW = -10.0;
public static double X_MINSTROKESW = -30; //负限位
public static double Y_MINSTROKESW = -10;
public static double Z_MINSTROKESW = -280;
#endregion
@@ -340,7 +347,7 @@ namespace HexcalMC
private void ParseHexcalMsg(string msg) //编写一个Hexcal协议解析函数
{
DebugDfn.AddLogText("正在解析" + msg);
DebugDfn.AddLogText("正在解析 " + msg);
//去除Msg中\r\n
msg = msg.Replace("\r\n", "");
//判断是否含有故障ERROR字样
@@ -439,7 +446,7 @@ namespace HexcalMC
SendMsgToHexcal(
"ACCEL 1000.000000,1000.000000,1000.000000,0.000000,0.000000,0.000000,0.000000,0.000000");
}
else if (msg.Contains("MOVPAR 300.0,300.0,300.0,0.0,0.0,0.0")) //设置速度 xyz 轴的速度
else if (msg.Contains("MOVPAR")) //设置速度 xyz 轴的速度
{
SendMsgToHexcal("%");
}
@@ -537,8 +544,16 @@ namespace HexcalMC
private void BtnEnable_Click(object sender, EventArgs e) //使能所有轴
{
//!!!! Important !! Must insert '-1' at the last
_acs.EnableM(USE_AXIS);
if (_mAcsConnected)
{
//!!!! Important !! Must insert '-1' at the last
_acs.EnableM(USE_AXIS);
}
else
{
//弹窗提醒尚未连接
MessageBox.Show("未连接到运动平台,请先点击连接");
}
}
private void BtnDisable_Click(object sender, EventArgs e) //轴取消
@@ -550,20 +565,10 @@ namespace HexcalMC
private void TmrMonitor_Tick(object sender, EventArgs e) //用于刷新状态
{
int iAxisNo = cboAxisNo.SelectedIndex;
if (_mBConnected)
if (_mAcsConnected)
{
try
{
// Instruction 1. Using library functions - acsc_GetFPosition,
// acsc_GetRPosition, .... Instruction 2. Read ACS variable - Already defined
// almost things (FPOS, RPOS, ...) Motion parameters and state is array (Max
// length is total number of axes)
//
// * Library function can read only 1 axis information, so if you want to read
// several axes, you have to call the function many times. (This may cause
// communication delay.) Recommand (if you want to read many axes) : read/write
// variable using ReadVariable, ReadVariableScalar, ReadVariableVector, ReadVariableMatrix
// Get Motor State ACSPL+ Variable : MST (integer)
_mNMotorState = _acs.GetMotorState((Axis)iAxisNo);
@@ -573,6 +578,7 @@ namespace HexcalMC
if ((_mNMotorState & MotorStates.ACSC_MST_MOVE) != 0)
{
lblMoving.Image = Resources.On;
_currentMotionState = MotionStates.Moving;
}
else
{
@@ -583,6 +589,7 @@ namespace HexcalMC
if ((_mNMotorState & MotorStates.ACSC_MST_INPOS) != 0)
{
lblInPos.Image = Resources.On;
_currentMotionState = MotionStates.InPos;
}
else
{
@@ -608,43 +615,6 @@ namespace HexcalMC
{
lblEnable.Image = Resources.Off;
}
// Reference position ACSPL+ Variable : RPOS (real)
_mLfRPos = _acs.GetRPosition((Axis)iAxisNo); // 参考位置
// Feedback position (Encoder value) ACSPL+ Variable : FPO (real)
_mLfFPos = _acs.GetFPosition((Axis)iAxisNo); //反馈位置
// PE (Position Error) There is no function in library. We need to use
// ReadVariable function
_mLfPe = (double)_acs.ReadVariable("PE", ProgramBuffer.ACSC_NONE, iAxisNo, iAxisNo); //位置误差
// Feedback Velocity
_mLfFvel = (double)_acs.ReadVariable("FVEL", ProgramBuffer.ACSC_NONE, iAxisNo, iAxisNo); //实际速度
// txtRPOS.Text = String.Format("{0:0.0000}", m_lfRPos); //参考位置
rtb_xPos.Text = string.Format("{0:0.0000}", _mLfFPos); //反馈位置
// txtPE.Text =
// String.Format("{0:0.0000}",
// m_lfPE); //实际速度
// txtFVEL.Text =
// String.Format("{0:0.0000}", m_lfFVEL);//位置误差
// Read left/right hardware limits state ACSPL+ Variable : FAULT (integer)
_mObjReadVar =
_acs.ReadVariableAsVector("FAULT", ProgramBuffer.ACSC_NONE, 0, _mNTotalAxis - 1);
if (_mObjReadVar != null)
{
_mArrReadVector = _mObjReadVar as Array;
if (_mArrReadVector != null)
{
for (int i = 0; i < _mNTotalAxis; i++)
{
UpdateLimitState(i, (int)_mArrReadVector.GetValue(i));
}
}
}
}
catch (Exception ex)
{
@@ -665,7 +635,7 @@ namespace HexcalMC
txtIP.Text, // IP Address (Default : 10.0.0.100)
Convert.ToInt32(txtPort.Text.Trim())); // TCP/IP Port nubmer (default : 701)
_mBConnected = true;
_mAcsConnected = true;
}
catch (Exception ex)
{
@@ -685,7 +655,7 @@ namespace HexcalMC
private void Btn_ACSStop_Click(object sender, EventArgs e) //断开连接
{
if (_mBConnected) _acs.CloseComm();
if (_mAcsConnected) _acs.CloseComm();
tmrMonitor.Stop();
@@ -709,7 +679,7 @@ namespace HexcalMC
private void Ishome() //读取回家状态,当未回家时执行回家指令
{
// 1、连接状态检查,如果未连接,提示
if (!_mBConnected)
if (!_mAcsConnected)
{
DebugDfn.AddLogText("[Ishome] ACS平台未连接,请先点击连接");
MessageBox.Show("ACS平台未连接,请先点击连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
@@ -717,7 +687,7 @@ namespace HexcalMC
}
// 2、回家状态检查是否已经回家
if (_mBConnected && _homeStates == HomeStates.Homed)
if (_mAcsConnected && _homeStates == HomeStates.Homed)
{
//弹窗提示
MessageBox.Show("轴已经回家", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
@@ -725,12 +695,12 @@ namespace HexcalMC
}
// 3、读取回家状态
if (_acs != null && _mBConnected)
if (_acs != null && _mAcsConnected)
{
var yawHome = _acs.ReadVariable("YAW_HOME_DONE");
if (yawHome != null && (bool)yawHome)
if (Convert.ToBoolean(yawHome))
{
//弹窗提示
MessageBox.Show("轴已经回家", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
@@ -769,7 +739,6 @@ namespace HexcalMC
}
}
private void InitMotion() //定义 运动状态初始化函数,包括内部变量,轴启用,回家判断等
{
//运动相关变量初始化
@@ -777,6 +746,18 @@ namespace HexcalMC
_currentMotionState = MotionStates.None;
_currentMotionState = MotionStates.None;
if (!_mAcsConnected)
{
MessageBox.Show("未连接运动平台,请先连接运动平台");
return;
}
if (_acs == null)
{
DebugDfn.AddLogText("运动控制对象不存在");
return;
}
//轴启用,加电
_acs.EnableM(USE_AXIS);
for (int i = 0; i < USE_AXIS.Length; i++)
@@ -788,6 +769,39 @@ namespace HexcalMC
//回家
Ishome();
SetSpeedXyz();
//注册到位事件
_acs.PHYSICALMOTIONEND += ACS_PHYSICALMOTIONEND;
_acs.EnableEvent(Interrupts.ACSC_INTR_PHYSICAL_MOTION_END);
}
private void ACS_PHYSICALMOTIONEND(AxisMasks axis)
{
int bit = 0x01;
int axisNo = 0;
// Param value is bit number
// Bit Number = Axis Number
for (int i = 0; i < 64; i++)
{
if ((int)axis == bit)
{
axisNo = i;
break;
}
bit = bit << 1;
}
// Add log to ListBox
Invoke((MethodInvoker)delegate
{
DebugDfn.AddLogText("运动到位");
_currentMotionState = MotionStates.InPos;
DebugDfn.AddLogText("运动到位");
});
}
private bool IsWithinStrokes(Point3D point) //判断点是否在行程范围内
@@ -804,7 +818,7 @@ namespace HexcalMC
private void SetPositionXyz(Point3D point3D) //运动到指定位置
{
if (!_mBConnected)
if (!_mAcsConnected)
{
DebugDfn.AddLogText("ACS平台未连接,请先点击连接");
MessageBox.Show("ACS平台未连接,请先点击连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
@@ -821,22 +835,22 @@ namespace HexcalMC
{
double[] pointsArray =
{
point3D.Y,
point3D.X,
point3D.Y,
point3D.Z
};
//执行运动指令
_acs.ToPointM(MotionFlags.ACSC_NONE, USE_AXIS, pointsArray); //多轴运动到指定位置
//等待运动完成
for (int i = 0; i < USE_AXIS.Length; i++)
{
_acs.WaitMotionEnd(USE_AXIS[i], _motionTimeout); //等待回家完成
}
////等待运动完成
//for (int i = 0; i < USE_AXIS.Length; i++)
//{
// _acs.WaitMotionEnd(USE_AXIS[i], _motionTimeout); //等待回家完成
//}
_currentMotionState = MotionStates.InPos;
DebugDfn.AddLogText("运动到位");
//_currentMotionState = MotionStates.InPos;
//DebugDfn.AddLogText("运动到位");
}
else
{
@@ -852,12 +866,11 @@ namespace HexcalMC
}
}
private Point3D GetPositionXyz(int positionMode = 1) //获取当前位置
{
double xPosition = 0, yPosition = 0, zPosition = 0;
Point3D point3D = new Point3D(xPosition, yPosition, zPosition);
if (!_mBConnected)
if (!_mAcsConnected)
{
DebugDfn.AddLogText("ACS平台未连接,请先点击连接");
MessageBox.Show("ACS平台未连接,请先点击连接", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
@@ -882,9 +895,6 @@ namespace HexcalMC
DebugDfn.AddLogText("参考位置: " + xPosition + " " + yPosition + " " + zPosition);
}
//获取位置误差
double positionError = (double)_acs.ReadVariable("PE", ProgramBuffer.ACSC_NONE, 0, 2);
DebugDfn.AddLogText("位置误差: " + positionError);
//构造point3D格式
point3D = new Point3D(xPosition, yPosition, zPosition);
@@ -892,14 +902,30 @@ namespace HexcalMC
return point3D;
}
private void GetSpeedXyz() //获取运动参数
private void SetSpeedXyz() //获取运动参数
{
//获取实际速度
double feedbackVelocity = (double)_acs.ReadVariable("FVEL", ProgramBuffer.ACSC_NONE, 0, 2);
double feedbackVelocity = (double)_acs.ReadVariable("FVEL", ProgramBuffer.ACSC_NONE, 0, 0);
DebugDfn.AddLogText("实际速度: " + feedbackVelocity);
//设置Y轴 速度参数
_acs.SetVelocity(Axis.ACSC_AXIS_0, MOTION_SPEED);
_acs.SetAcceleration(Axis.ACSC_AXIS_0,MOTION_SPEED*10);
_acs.SetDeceleration(Axis.ACSC_AXIS_0,MOTION_SPEED*10);
//设置X轴速度参数
_acs.SetVelocity(Axis.ACSC_AXIS_1, MOTION_SPEED);
_acs.SetAcceleration(Axis.ACSC_AXIS_1, MOTION_SPEED * 10);
_acs.SetDeceleration(Axis.ACSC_AXIS_1, MOTION_SPEED * 10);
//设置Z轴速度参数
_acs.SetVelocity(Axis.ACSC_AXIS_8, MOTION_SPEED);
_acs.SetAcceleration(Axis.ACSC_AXIS_8, MOTION_SPEED * 10);
_acs.SetDeceleration(Axis.ACSC_AXIS_8, MOTION_SPEED * 10);
}
private void openGLControl1_OpenGLDraw(object sender, SharpGL.RenderEventArgs args)
private void openGLControl1_OpenGLDraw(object sender, RenderEventArgs args)
{
OpenGL gl = openGLControl1.OpenGL;
@@ -908,7 +934,6 @@ namespace HexcalMC
gl.LoadIdentity();
//gl.Translate(0.0f, 0.0f, -5.0f); // 平移场景
}
private void LoadPoints(List<Point3D> points)
@@ -931,6 +956,7 @@ namespace HexcalMC
gl.PointSize(5.0f); // 大小为5个单位
gl.Vertex(point.X, point.Y, point.Z);
}
gl.End();
gl.Flush();
@@ -938,24 +964,18 @@ namespace HexcalMC
private void openGLControl1_OpenGLInitialized(object sender, EventArgs e)
{
}
private void openGLControl1_Resized(object sender, EventArgs e)
{
}
private void openGLControl1_GDIDraw(object sender, SharpGL.RenderEventArgs args)
{
}
private void SetSpeedXyz() //设置运动参数
private void openGLControl1_GDIDraw(object sender, RenderEventArgs args)
{
}
#endregion ACS平台相关
#region
@@ -976,14 +996,14 @@ namespace HexcalMC
private void Timer_RefreshUI_Tick(object sender, EventArgs e) //UI刷新
{
//状态灯刷新
lamp_acs.State = _mBConnected ? LampColor.Green : LampColor.Silver;
lamp_acs.State = _mAcsConnected ? LampColor.Green : LampColor.Silver;
lamp_hexcal.State = _mBHexcalConnected ? LampColor.Green : LampColor.Silver;
//时间栏
//获取当前时间,构造形如 精确到秒,例如 2023-10-08 16:01:23
rle_timer.Text = "当前时间: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
Plot2D(_pointCloud);//绘图
Plot2D(_pointCloud); //绘图
}
#endregion
+1 -1
View File
@@ -852,7 +852,7 @@ namespace HexcalMC
private void BtnEventMotionEnd_Click(object sender, EventArgs e)
{
//_ACS.PHYSICALMOTIONEND +=_ACS_PHYSICALMOTIONEND;
_acs.PHYSICALMOTIONEND +=ACS_PHYSICALMOTIONEND;
_acs.EnableEvent(Interrupts.ACSC_INTR_PHYSICAL_MOTION_END);
lstLog.Items.Add("PHYSICAL_MOTION_END event enabled");
}
Binary file not shown.
Binary file not shown.
@@ -14,3 +14,19 @@ E:\HexagonProjects\2022-05-直线电机平台\LM-Middleware\Motion\ACS Motion\bi
E:\HexagonProjects\2022-05-直线电机平台\LM-Middleware\Motion\ACS Motion\obj\x86\Debug\ACS_Motion.exe.licenses
E:\HexagonProjects\2022-05-直线电机平台\LM-Middleware\Motion\ACS Motion\obj\x86\Debug\ACS_Motion.exe
E:\HexagonProjects\2022-05-直线电机平台\LM-Middleware\Motion\ACS Motion\obj\x86\Debug\ACS_Motion.pdb
D:\HexagonProjects\2022-05-直线电机平台\LM-Middleware\Motion\ACS Motion\bin\Debug\ACS_Motion.exe
D:\HexagonProjects\2022-05-直线电机平台\LM-Middleware\Motion\ACS Motion\bin\Debug\ACS_Motion.pdb
D:\HexagonProjects\2022-05-直线电机平台\LM-Middleware\Motion\ACS Motion\bin\Debug\Telerik.WinControls.dll
D:\HexagonProjects\2022-05-直线电机平台\LM-Middleware\Motion\ACS Motion\bin\Debug\Telerik.WinControls.UI.dll
D:\HexagonProjects\2022-05-直线电机平台\LM-Middleware\Motion\ACS Motion\bin\Debug\TelerikCommon.dll
D:\HexagonProjects\2022-05-直线电机平台\LM-Middleware\Motion\ACS Motion\bin\Debug\Telerik.WinControls.xml
D:\HexagonProjects\2022-05-直线电机平台\LM-Middleware\Motion\ACS Motion\bin\Debug\Telerik.WinControls.UI.xml
D:\HexagonProjects\2022-05-直线电机平台\LM-Middleware\Motion\ACS Motion\obj\x86\Debug\ACS Motion.csproj.AssemblyReference.cache
D:\HexagonProjects\2022-05-直线电机平台\LM-Middleware\Motion\ACS Motion\obj\x86\Debug\ACS_DotNET_Library_Advanced_Demo.MainForm.resources
D:\HexagonProjects\2022-05-直线电机平台\LM-Middleware\Motion\ACS Motion\obj\x86\Debug\ACS_DotNET_Library_Advanced_Demo.Properties.Resources.resources
D:\HexagonProjects\2022-05-直线电机平台\LM-Middleware\Motion\ACS Motion\obj\x86\Debug\ACS Motion.csproj.GenerateResource.cache
D:\HexagonProjects\2022-05-直线电机平台\LM-Middleware\Motion\ACS Motion\obj\x86\Debug\ACS_Motion.exe.licenses
D:\HexagonProjects\2022-05-直线电机平台\LM-Middleware\Motion\ACS Motion\obj\x86\Debug\ACS Motion.csproj.CoreCompileInputs.cache
D:\HexagonProjects\2022-05-直线电机平台\LM-Middleware\Motion\ACS Motion\obj\x86\Debug\ACS Motion.csproj.CopyComplete
D:\HexagonProjects\2022-05-直线电机平台\LM-Middleware\Motion\ACS Motion\obj\x86\Debug\ACS_Motion.exe
D:\HexagonProjects\2022-05-直线电机平台\LM-Middleware\Motion\ACS Motion\obj\x86\Debug\ACS_Motion.pdb