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.
138 lines
5.1 KiB
C#
138 lines
5.1 KiB
C#
using HalconDotNet;
|
|
using Rs.Controls;
|
|
using Rs.Framework;
|
|
using Rs.MotionPlat.Commom;
|
|
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.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Rs.MotionPlat.SysConfig
|
|
{
|
|
public partial class NozzleDistance : BaseForm
|
|
{
|
|
public NozzleDistance()
|
|
{
|
|
InitializeComponent();
|
|
cameraTemplate1.ItemName = "吸嘴间距标定";
|
|
cameraTemplate1.SetFindShapeMode(EFindShapeMode.SelfDefine);
|
|
cameraTemplate1.FindShapeEvent += CameraTemplate1_FindShapeEvent;
|
|
//cameraTemplate1.ManualGrab += CameraTemplate1_ManualGrab;
|
|
}
|
|
|
|
private void CameraTemplate1_ManualGrab()
|
|
{
|
|
AxisControl.LoadX.ComparePulse(1);
|
|
}
|
|
|
|
private void CameraTemplate1_FindShapeEvent(ChoiceTech.Halcon.Control.HWindow_Final arg1, HalconDotNet.HObject arg2)
|
|
{
|
|
HOperatorSet.Threshold(arg2, out HObject Region, new HTuple(0), new HTuple(100));
|
|
HOperatorSet.Connection(Region, out HObject connectedRegion);
|
|
if(connectedRegion.IsInitialized()&&connectedRegion.CountObj()>0)
|
|
{
|
|
HOperatorSet.SelectShape(connectedRegion, out HObject selectedRegion, "area","and", new HTuple(2000), new HTuple(3000));
|
|
if(selectedRegion.IsInitialized()&&selectedRegion.CountObj()>0)
|
|
{
|
|
HOperatorSet.SelectShape(selectedRegion, out HObject lastRegion, "circularity", "and", new HTuple(0.8), new HTuple(1));
|
|
if(lastRegion.IsInitialized()&&lastRegion.CountObj()>0)
|
|
{
|
|
HOperatorSet.SmallestCircle(lastRegion, out HTuple row, out HTuple column, out HTuple radius);
|
|
HOperatorSet.GenCrossContourXld(out HObject cross, row, column, new HTuple(20), new HTuple(0));
|
|
arg1.DispObj(cross, "green");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void NozzleDistance_Load(object sender, EventArgs e)
|
|
{
|
|
foreach (var item in groupBox1.Controls)
|
|
{
|
|
if(item is TextBox)
|
|
{
|
|
TextBox txt=(TextBox)item;
|
|
txt.Text = SysConfigParam.GetValue<double>(txt.Name.Replace("txt", "")).ToString("0.000");
|
|
}
|
|
}
|
|
}
|
|
|
|
private void NozzleDistance_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
cameraTemplate1.RemoveGrabEvent();
|
|
}
|
|
|
|
protected void Fetch_Position(object sender, EventArgs e)
|
|
{
|
|
AxisControl.LoadX.GetEncoderPosition(out double curX);
|
|
AxisControl.LoadY.GetEncoderPosition(out double curY);
|
|
Button btn=(Button)sender;
|
|
string txtCenterX=$"txt{btn.Name.Replace("btnFetchPostion","")}CenterX";
|
|
string txtCenterY = $"txt{btn.Name.Replace("btnFetchPostion", "")}CenterY";
|
|
foreach (var item in groupBox1.Controls)
|
|
{
|
|
if (item is TextBox)
|
|
{
|
|
TextBox txt = (TextBox)item;
|
|
if(txt.Name==txtCenterX)
|
|
{
|
|
txt.Text = curX.ToString("0.000");
|
|
}
|
|
if(txt.Name== txtCenterY)
|
|
{
|
|
txt.Text = curY.ToString("0.000");
|
|
}
|
|
}
|
|
}
|
|
SysConfigParam.Update(txtCenterX.Replace("txt", ""), curX.ToString());
|
|
SysConfigParam.Update(txtCenterY.Replace("txt", ""), curY.ToString());
|
|
}
|
|
|
|
protected void GotoThis(object sender, EventArgs e)
|
|
{
|
|
if (Ops.IsHomed("LoadX", "LoadY"))
|
|
{
|
|
double targetX = 0.0; double targetY = 0.0;
|
|
Button btn = (Button)sender;
|
|
string txtCenterX = $"txt{btn.Name.Replace("btnGoto", "")}CenterX";
|
|
string txtCenterY = $"txt{btn.Name.Replace("btnGoto", "")}CenterY";
|
|
Control[] ctls = groupBox1.Controls.Find(txtCenterX, true);
|
|
if(ctls!=null&&ctls.Length>0)
|
|
{
|
|
targetX = double.Parse(ctls[0].Text);
|
|
}
|
|
else
|
|
{
|
|
Msg.ShowError("未找到运动目的地");
|
|
return;
|
|
}
|
|
ctls = groupBox1.Controls.Find(txtCenterY, true);
|
|
if (ctls != null && ctls.Length > 0)
|
|
{
|
|
targetY = double.Parse(ctls[0].Text);
|
|
}
|
|
else
|
|
{
|
|
Msg.ShowError("未找到运动目的地");
|
|
return;
|
|
}
|
|
AxisControl.LoadX.MovePos(targetX, 10);
|
|
AxisControl.LoadY.MovePos(targetY, 10);
|
|
}
|
|
else
|
|
{
|
|
Msg.ShowInfo("轴未回原,请回原后再运动");
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
}
|