You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
218 lines
7.4 KiB
C#
218 lines
7.4 KiB
C#
using HalconDotNet;
|
|
using Rs.Camera;
|
|
using Rs.Framework;
|
|
using Rs.Motion.Base;
|
|
using Rs.MotionPlat.Flow;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Rs.MotionPlat
|
|
{
|
|
public partial class FormMain : BaseForm
|
|
{
|
|
IAxis axis = null;
|
|
HWindow winHandle = null;
|
|
HObject hImage = null;
|
|
HObject hmodelImage = null;
|
|
HTuple h1;
|
|
HTuple modelID;
|
|
HObject final_Region = new HObject();
|
|
BindingList<MessageItem> runInfoList = new BindingList<MessageItem>();
|
|
BindingList<MessageItem> errorInfoList = new BindingList<MessageItem>();
|
|
public FormMain()
|
|
{
|
|
InitializeComponent();
|
|
//this.tabControlEx1.TabPages.RemoveAt(1);
|
|
HikCamera.Instance.GrabOkEvent += Instance_GrabOkEvent;
|
|
winHandle = hWindow_Final1.hWindowControl.HalconWindow;
|
|
h1 = hWindow_Final1.HWindowHalconID;
|
|
HOperatorSet.GenEmptyObj(out final_Region);
|
|
HOperatorSet.GenEmptyObj(out hmodelImage);
|
|
modelID = new HTuple();
|
|
HOperatorSet.ReadShapeModel("Model/model.shm", out modelID);
|
|
}
|
|
|
|
bool cameraFinished = false;
|
|
int testNum = 0;
|
|
int speed = 50;
|
|
private void Instance_GrabOkEvent(int arg1, HalconDotNet.HObject arg2)
|
|
{
|
|
hWindow_Final1.HobjectToHimage(arg2);
|
|
hImage = arg2;
|
|
HOperatorSet.FindShapeModel(hImage, modelID, -0.39, 0.79, 0.5, 1, 0.5, "least_squares", 0, 0.9, out HTuple row, out HTuple column, out HTuple angle, out HTuple score);
|
|
if (score.Length>0)
|
|
{
|
|
Invoke(new Action(() => {
|
|
textBox1.Text = score.DArr[0].ToString("0.000");
|
|
textBox2.Text = row.DArr[0].ToString("0.000");
|
|
textBox3.Text = column.DArr[0].ToString("0.000");
|
|
|
|
string msg = $"{testNum},{speed},{textBox2.Text},{textBox3.Text},{textBox1.Text}\r\n";
|
|
File.AppendAllText("log.txt", msg);
|
|
MessageQueue.Instance.Insert(msg);
|
|
}));
|
|
}
|
|
else
|
|
{
|
|
string msg = $"{testNum},{speed},丢步\r\n";
|
|
File.AppendAllText("log.txt", msg);
|
|
MessageQueue.Instance.Warn("未找到");
|
|
}
|
|
cameraFinished = true;
|
|
}
|
|
|
|
private void timer1_Tick(object sender, EventArgs e)
|
|
{
|
|
//获取运行信息
|
|
while (MessageQueue.Instance.HaveMessage())
|
|
{
|
|
MessageItem runInfo = MessageQueue.Instance.GetMessage();
|
|
if (runInfo != null)
|
|
{
|
|
while (runInfoList.Count > 500)
|
|
{
|
|
//runInfoList.Clear();
|
|
{
|
|
runInfoList.RemoveAt(runInfoList.Count - 1);
|
|
}
|
|
}
|
|
runInfoList.Insert(0, runInfo);
|
|
}
|
|
|
|
MessageItem errorInfo = MessageQueue.Instance.GetWarn();
|
|
if (errorInfo != null)
|
|
errorInfoList.Insert(0, errorInfo);
|
|
}
|
|
}
|
|
|
|
private void FormMain_Load(object sender, EventArgs e)
|
|
{
|
|
dgv_runinfo.DataSource = runInfoList;
|
|
dgv_errinfo.DataSource = errorInfoList;
|
|
timer1.Interval = 500;
|
|
timer1.Enabled = true;
|
|
HObject img = new HObject();
|
|
//HOperatorSet.CloseWindow(hWindow_Final1.HWindowHalconID);
|
|
//HOperatorSet.OpenWindow(0, 0, hWindow_Final1.Width, hWindow_Final1.Height, winHandle,"visible", "", out h1);
|
|
//HOperatorSet.openwi
|
|
string filepath = @"C:\Users\Administrator\MVS\Data\22.bmp";
|
|
if(File.Exists(filepath))
|
|
{
|
|
HOperatorSet.ReadImage(out HObject image, filepath);
|
|
hWindow_Final1.HobjectToHimage(image);
|
|
//hSmartWindowControl1.HalconWindow.SetDraw("margin");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
private void btnStart_Click(object sender, EventArgs e)
|
|
{
|
|
axis = AxisControl.VacZ7;
|
|
axis.Enable();
|
|
AxisControl.VacR7.Enable();
|
|
int workStep = 0;
|
|
Task.Run(() => {
|
|
|
|
while (true)
|
|
{
|
|
switch (workStep)
|
|
{
|
|
case 0://到起点
|
|
if(testNum>100)
|
|
{
|
|
testNum = 0;
|
|
speed += 1;
|
|
}
|
|
else
|
|
{
|
|
testNum++;
|
|
}
|
|
axis.MovePos(2, speed);
|
|
workStep++;
|
|
break;
|
|
case 1:
|
|
axis.IsStop(out bool bStop);
|
|
if (bStop)
|
|
{
|
|
workStep++;
|
|
Thread.Sleep(100);
|
|
//设置
|
|
//double targetPos = -105;
|
|
//targetPos-
|
|
//axis.SetPosCompare(1, new double[] { -20, -80 });
|
|
}
|
|
break;
|
|
case 2:
|
|
axis.MovePos(15, speed);
|
|
workStep++;
|
|
break;
|
|
case 3:
|
|
axis.IsStop(out bStop);
|
|
if (bStop)
|
|
{
|
|
workStep++;
|
|
Thread.Sleep(100);
|
|
HikCamera.Instance.Grab("MV-CA050-10GM (00C32922251)");
|
|
}
|
|
break;
|
|
case 4:
|
|
if (cameraFinished)
|
|
{
|
|
cameraFinished = false;
|
|
workStep = 0;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
|
|
private void button3_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
private void btnWholeHome_Load(object sender, EventArgs e)
|
|
{
|
|
HomeFlow.Instance.StartGoHome();
|
|
}
|
|
|
|
private void btnSpaceRun_BtnClick(object sender, EventArgs e)
|
|
{
|
|
if(MachineManage.Instance.MachineStatus== EMachineStatus.Homed)
|
|
{
|
|
SpaceFlow.Instance.Start();
|
|
}
|
|
else if( MachineManage.Instance.MachineStatus== EMachineStatus.Stop)
|
|
{
|
|
SpaceFlow.Instance.Restart();
|
|
}
|
|
}
|
|
|
|
private void btnStop_BtnClick(object sender, EventArgs e)
|
|
{
|
|
SpaceFlow.Instance.Stop();
|
|
}
|
|
}
|
|
}
|