#0011:轨迹记录功能

This commit is contained in:
zhengxuan.zhang
2024-08-15 10:07:20 +08:00
parent d4f1ec2cf9
commit 74272c8406
4 changed files with 176 additions and 60 deletions
+135 -46
View File
@@ -61,7 +61,8 @@ namespace ACS_DotNET_Library_Advanced_Demo
// 记录标志位
private bool record = false;
private int record_count = 0; //时间计数
private bool record_last = false; //上一次的记录标志位
public MainForm()
{
@@ -287,7 +288,7 @@ namespace ACS_DotNET_Library_Advanced_Demo
}
private bool record_action = false;
private void tmrMonitor_Tick(object sender, EventArgs e)
{
// Get selected axis number
@@ -393,35 +394,47 @@ namespace ACS_DotNET_Library_Advanced_Demo
label55.Text = point.y.ToString("0.000");
label56.Text = point.z.ToString("0.000");
if (record)
if (record_action)
{
record_count++;
pointList.Add(point);
}
if (record_count > 200)
{
record_count = 0;
record = false;
//保存数据
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Filter = "文本文件|*.txt";
saveFileDialog.Title = "保存数据";
saveFileDialog.ShowDialog();
if (saveFileDialog.FileName != "")
{
StreamWriter sw = new StreamWriter(saveFileDialog.FileName);
foreach (Point p in pointList)
{
sw.WriteLine(p.x.ToString("0.000") + " " + p.y.ToString("0.000") + " " + p.z.ToString("0.000"));
}
sw.Close();
}
}
if (!record_last && record) //从未记录到记录
{
lstLog.Items.Add("开始记录");
record_action = true;
}
//从记录到未记录
if (record_last && !record)
{
lstLog.Items.Add("停止记录");
record_action = false;
//定义文件保存位置 D:/11.txt
string path = "D:/11.txt";
{
StreamWriter sw = new StreamWriter(path);
foreach (Point p in pointList)
{
sw.WriteLine(p.x.ToString("0.000") + " " + p.y.ToString("0.000") + " " + p.z.ToString("0.000"));
}
sw.Close();
}
pointList.Clear();//清空数据
lstLog.Items.Add("保存完成");
}
//更新记录标志位
record_last = record;
}
}
@@ -970,15 +983,16 @@ namespace ACS_DotNET_Library_Advanced_Demo
// Create multi-point motion of axis 0 and 1 with default
// velocity without
// dwell in the points
_ACS.MultiPointM(MotionFlags.ACSC_NONE, axes, 0);
//_ACS.MultiPointM(MotionFlags.ACSC_NONE, axes, 0);
// Add some points
for (int index = 0; index < 5; index++)
{
points[0] = 100 * index;
points[1] = 100 * index;
_ACS.AddPointM(axes, points);
//_ACS.AddPointM(axes, points);
_ACS.ToPointM(MotionFlags.ACSC_AMF_VELOCITY,axes, points);
//将点添加到 lstLog.Items
lstLog.Items.Add("points[0]:" + points[0].ToString() + "points[1]:" + points[1].ToString());
@@ -1011,7 +1025,7 @@ namespace ACS_DotNET_Library_Advanced_Demo
// Create the arbitrary path motion to axes 0 and 1 with
// uniform interval 10 ms use a cubic interpolation
// between the specified points
_ACS.SplineM(MotionFlags.ACSC_AMF_CUBIC |MotionFlags.ACSC_AMF_WAIT, axes, 5000);
_ACS.SplineM(MotionFlags.ACSC_AMF_CUBIC, axes, 1000);
// Add some points
// 定义三维点列表
@@ -1032,13 +1046,14 @@ namespace ACS_DotNET_Library_Advanced_Demo
// 遍历列表并添加点
for (int index = 0; index < pointsArray.GetLength(0); index++)
{
double[] speed = { 100,100,100};
points[0] = pointsArray[index, 0];
points[1] = pointsArray[index, 1];
points[2] = pointsArray[index, 2];
// 使用AddPVPointM方法添加点
_ACS.AddPVPointM(axes, points, points);
_ACS.AddPVPointM(axes, points, speed);
// 将点信息添加到lstLog.Items
lstLog.Items.Add($"points[0]: {points[0]} points[1]: {points[1]} points[2]: {points[2]}");
@@ -1049,7 +1064,7 @@ namespace ACS_DotNET_Library_Advanced_Demo
// End of the multi-point motion
_ACS.EndSequenceM(axes);
_ACS.GoM(axes);
//_ACS.GoM(axes);
record = true;
@@ -1118,10 +1133,48 @@ namespace ACS_DotNET_Library_Advanced_Demo
private void button18_Click(object sender, EventArgs e)
{
lstLog.Items.Add("记录");
record = true;
}
private void button19_Click(object sender, EventArgs e)
{
lstLog.Items.Add("停止记录");
record = false;
}
private void button10_Click(object sender, EventArgs e)
{
}
private void button20_Click(object sender, EventArgs e)//MultiPointM
{
lstLog.Items.Add("MultiPointM");
int timeout = 5000;
Axis[] axes = { Axis.ACSC_AXIS_0, Axis.ACSC_AXIS_1,Axis.ACSC_NONE };
double[] points = { 0, 0 };
_ACS.EnableM(axes); // Enable axes 0 and 1
// Wait axis 0 enabled during 5 sec
_ACS.WaitMotorEnabled(Axis.ACSC_AXIS_0, 1, timeout);
// Wait axis 1 enabled during 5 sec
_ACS.WaitMotorEnabled(Axis.ACSC_AXIS_1, 1, timeout);
// Create multi-point motion with default velocity without
// dwell
_ACS.MultiPointM(MotionFlags.ACSC_AMF_VELOCITY, axes, 0);
// Add some points
for (int index = 0; index < 5; index++)
{
// Position and velocity for each point
points[0] = 100 * index;
points[1] = 100 * index;
_ACS.ExtAddPointM(axes, points, 5000);
}
// Finish the motion
// End of the multi-point motion
_ACS.EndSequenceM(axes);
}
private void button15_Click(object sender, EventArgs e) //ExtLine
{
int timeout = 5000;
@@ -1176,34 +1229,70 @@ namespace ACS_DotNET_Library_Advanced_Demo
lstLog.Items.Add("BlendedLine ");
int timeout = 5000;
Axis[] Axes = { Axis.ACSC_AXIS_0, Axis.ACSC_AXIS_1,Axis.ACSC_AXIS_8, Axis.ACSC_NONE };
double[] Point = { 1000, 1000 };
_ACS.BlendedSegmentMotionAsync(MotionFlags.ACSC_NONE, Axes,
Point,//Starting point of motion
1000, // Segment time
500, // Segment Acceleration time
200, // Segment jerk time
0);// Waiting call
Axis[] Axes = { Axis.ACSC_AXIS_0, Axis.ACSC_AXIS_1, Axis.ACSC_NONE };
_ACS.EnableM(Axes); // Enable axes 0 and 1
_ACS.WaitMotorEnabled(Axis.ACSC_AXIS_0, 1, timeout);
_ACS.WaitMotorEnabled(Axis.ACSC_AXIS_1, 1, timeout);
_ACS.WaitMotorEnabled(Axis.ACSC_AXIS_8, 1, timeout);
double[] Point = { 100, 100 };
_ACS.BlendedSegmentMotion(MotionFlags.ACSC_NONE, Axes,
Point,//Starting point of motion
1000, // Segment time
500, // Segment Acceleration time
200, // Segment jerk time
0);// Waiting call
double[] FinalPoint = { 300, 300};
_ACS.BlendedLine(MotionFlags.ACSC_NONE, Axes,FinalPoint, 10000, 200, 300, 0);
//增加第二个点(500,400
double[] FinalPoint2 = { 500, 400 };
_ACS.BlendedLine(MotionFlags.ACSC_NONE, Axes, FinalPoint2, 10000, 200, 300, 0);
//增加第三个点(600,100
double[] FinalPoint3 = { 600, 100 };
_ACS.BlendedLine(MotionFlags.ACSC_NONE, Axes, FinalPoint3, 10000, 200, 300, 0);
double[] FinalPoint = { 100, 100,-50};
_ACS.BlendedLine(MotionFlags.ACSC_NONE, Axes,
FinalPoint, 1000, 200, 300, 0);
_ACS.EndSequenceM(Axes);
record =true;
}
private void button17_Click(object sender, EventArgs e) //MoveM 方法
private void button17_Click(object sender, EventArgs e) //ExtAddPointM 方法
{
lstLog.Items.Add("ExtAddPointM ");
int timeout = 5000;
Axis[] axes = { Axis.ACSC_AXIS_0, Axis.ACSC_AXIS_1,Axis.ACSC_NONE };
double[] points = { 0, 0 };
_ACS.EnableM(axes); // Enable axes 0 and 1
// Wait axis 0 enabled during 5 sec
_ACS.WaitMotorEnabled(Axis.ACSC_AXIS_0, 1, timeout);
// Wait axis 1 enabled during 5 sec
_ACS.WaitMotorEnabled(Axis.ACSC_AXIS_1, 1, timeout);
// Create multi-point motion with default velocity without
// dwell
_ACS.MultiPointM(MotionFlags.ACSC_AMF_VELOCITY, axes, 0);
// Add some points
for (int index = 0; index < 5; index++)
{
// Position and velocity for each point
points[0] = 100 * index;
points[1] = 100 * index;
_ACS.ExtAddPointM(axes, points, 5000);
}
// Finish the motion
// End of the multi-point motion
_ACS.EndSequenceM(axes);
record = true;
}
private void button1_Click(object sender, EventArgs e)