20230411Change

This commit is contained in:
17860779768 2023-04-11 13:56:50 +08:00
parent 8a92dd3eea
commit 9b6bd5321a
4 changed files with 181 additions and 113 deletions

View File

@ -81,7 +81,7 @@ namespace BRS.Common.Model
[Category("机械臂配置项")]
[Description("拧紧轴推进距离")]
[DisplayName("拧紧轴推进距离")]
public float NIJ_DisD { get; set; } = -99;
public float NIJ_DisD { get; set; }
public string GetDisplayText()
{

View File

@ -20,7 +20,7 @@ namespace BRS.Process.A020
{
public partial class A020Process
{
private bool IsTesting { get; set; } = true;
private bool IsTesting { get; set; } = false;
public bool IsSingleStepOperating { get; set; } = false;
public bool IsArrive { get; set; } = false;//判断机械臂携带拧紧轴是否到位
@ -29,11 +29,12 @@ namespace BRS.Process.A020
private bool IsTough { get; set; } = false;//是否拧紧
int ShiJiaoVecCountFlag1 = 0;// 相机的示教点索引
float Distance_DisD = 0;//拧紧轴推进距离100
//float NJZ_T = (float)102.548;
DeviceModel AModeTypeRun = new DeviceModel();//相机机械臂全局配置(务必要有)
private void StopMachineClosing(PLCBase MelsecPlc, TCPSeverBase TcpSeverBase1)
{
if (MelsecPlc != null && MelsecPlc.InitialConfig.IsEnabled)
@ -55,6 +56,7 @@ namespace BRS.Process.A020
/* 设备对象 */
private ThridLibray.IDevice m_dev;
Mat Mat_CamA = new Mat();
Bitmap Bit_Image = null;
// private ThridLibray.IDevice m_dev1;
// private ThridLibray.IDevice m_dev2;
@ -139,7 +141,7 @@ namespace BRS.Process.A020
Catcher.Show(exception);
}
}
bool CamA = false;
bool CamA = true;
private void OnImageGrabbed(Object sender, GrabbedEventArgs e)
{
Mat_CamA = null;
@ -245,12 +247,40 @@ namespace BRS.Process.A020
public static void Contour_Get(Mat mat, List<OpenCvSharp.Point[]> Lastcontours)
{
//高斯模糊
Mat dst = new Mat();
//Mat dst = new Mat();
//OpenCvSharp.Size ksize = new OpenCvSharp.Size(3, 3);
//Cv2.GaussianBlur(mat, dst, ksize, 0);
//Mat gray = new Mat();
//Cv2.CvtColor(dst, gray, ColorConversionCodes.BGR2GRAY);
Mat binary = mat.Clone();
Cv2.Threshold(mat, binary, 0, 255, ThresholdTypes.BinaryInv | ThresholdTypes.Otsu);
//查找轮廓
//List<List<Point>> contours = new List<List<Point>>();
OpenCvSharp.Point[][] contours = null;
HierarchyIndex[] hierarchly;
Cv2.FindContours(binary, out contours, out hierarchly, RetrievalModes.Tree, ContourApproximationModes.ApproxSimple, new OpenCvSharp.Point(0, 0));
for (int i = 0; i < contours.Length; i++)
{
double length = Cv2.ArcLength(contours[i], true);
if (length > 300 && length < 550)
{
Lastcontours.Add(contours[i]);
Console.WriteLine(length);
}
}
}
public static void Contour3_Get(Mat mat, List<OpenCvSharp.Point[]> Lastcontours)
{
//高斯模糊
//Mat Image = Cv2.ImRead(@"C:\徐敏育\项目\螺丝机研发\P1\1.png");
Mat dst = mat.Clone();
OpenCvSharp.Size ksize = new OpenCvSharp.Size(3, 3);
Cv2.GaussianBlur(mat, dst, ksize, 0);
Mat gray = new Mat();
// Cv2.GaussianBlur(mat, dst, ksize, 0);
Mat gray = mat.Clone();
Cv2.CvtColor(dst, gray, ColorConversionCodes.BGR2GRAY);
Mat binary = new Mat();
Mat binary = gray.Clone();
Cv2.Threshold(gray, binary, 0, 255, ThresholdTypes.BinaryInv | ThresholdTypes.Otsu);
//查找轮廓
//List<List<Point>> contours = new List<List<Point>>();
@ -261,8 +291,13 @@ namespace BRS.Process.A020
for (int i = 0; i < contours.Length; i++)
{
double length = Cv2.ArcLength(contours[i], true);
if (length > 300 && length < 400)
//Console.ReadKey();
if (length > 500 && length < 600)
{
Console.WriteLine(length);
Lastcontours.Add(contours[i]);
}
@ -278,7 +313,7 @@ namespace BRS.Process.A020
{
Mat SrcImage = image.Clone();
// 固定路径的模板图像
Mat Image = Cv2.ImRead(@"D:\MelsecPLCReadWrite\Bk\20230330\1.png");
Mat Image = Cv2.ImRead(@"D:\testData\Model_P\1.jpg");
Mat TempleteImage = Image.Clone();
// Point[][] contours1 = new Point[][] { };
@ -286,9 +321,10 @@ namespace BRS.Process.A020
List<OpenCvSharp.Point[]> contours1 = new List<OpenCvSharp.Point[]>();
List<OpenCvSharp.Point[]> contours2 = new List<OpenCvSharp.Point[]>();
Contour3_Get(TempleteImage, contours2);
Contour_Get(SrcImage, contours1);
Contour_Get(TempleteImage, contours2);
Cv2.ImWrite(@"D:\MelsecPLCReadWrite\Bk\20230330\TempleteImage.jpg", SrcImage);
Cv2.ImWrite(@"D:\MelsecPLCReadWrite\Bk\20230330\SrcImage.jpg", TempleteImage);
// Hu矩计算
//Moments mm2 = Cv2.Moments(contours2[0]); // 先计算几何矩
//Mat hu2 = new Mat();
@ -340,119 +376,138 @@ namespace BRS.Process.A020
VP.Clear();
VR.Clear();
/*************生成像素数据*********************/
for (int i = 0; i < VPList.Count; i++)
{
MyPoint tp;
tp.dX = VPList[0].X;//2054;
tp.dY = VPList[0].Y;// 1831;
VP.Add(tp);
tp.dX = VPList[1].X;// 2033;
tp.dY = VPList[1].Y; //986;
VP.Add(tp);
tp.dX = VPList[2].X;//2013;
tp.dY = VPList[2].Y;//168;
VP.Add(tp);
tp.dX = VPList[3].X;// 1369;
tp.dY = VPList[3].Y; //235;
tp.dX = VPList[i].X;//2054;
tp.dY = VPList[i].Y;// 1831;
VP.Add(tp);
}
////5-8
tp.dX = VPList[4].X;// 1369;
tp.dY = VPList[4].Y; //235;
// tp.dX = 1403;
//tp.dY = 985;
VP.Add(tp);
//MyPoint tp;
//tp.dX = VPList[0].X;//2054;
//tp.dY = VPList[0].Y;// 1831;
//VP.Add(tp);
tp.dX = VPList[5].X;// 1327;
tp.dY = VPList[5].Y;// 1756;
VP.Add(tp);
//tp.dX = VPList[1].X;// 2033;
//tp.dY = VPList[1].Y; //986;
//VP.Add(tp);
tp.dX = VPList[6].X;// 717;
tp.dY = VPList[6].Y;// 1701;
VP.Add(tp);
//tp.dX = VPList[2].X;//2013;
//tp.dY = VPList[2].Y;//168;
//VP.Add(tp);
tp.dX = VPList[7].X;// 879;
tp.dY = VPList[7].Y;// 947;
VP.Add(tp);
////
//tp.dX = VPList[3].X;// 1369;
//tp.dY = VPList[3].Y; //235;
//VP.Add(tp);
tp.dX = VPList[8].X;// 774;
tp.dY = VPList[8].Y;// 236;
VP.Add(tp);
tp.dX = VPList[9].X;// 257;
tp.dY = VPList[9].Y;// ;
VP.Add(tp);
//////5-8
//tp.dX = VPList[4].X;// 1369;
//tp.dY = VPList[4].Y; //235;
// // tp.dX = 1403;
// //tp.dY = 985;
//VP.Add(tp);
tp.dX = VPList[10].X;// 307;
tp.dY = VPList[10].Y;// 994;
VP.Add(tp);
//tp.dX = VPList[5].X;// 1327;
//tp.dY = VPList[5].Y;// 1756;
//VP.Add(tp);
tp.dX = VPList[11].X;// 303;
tp.dY = VPList[11].Y;// 1727;
VP.Add(tp);
//tp.dX = VPList[6].X;// 717;
//tp.dY = VPList[6].Y;// 1701;
//VP.Add(tp);
//tp.dX = VPList[7].X;// 879;
//tp.dY = VPList[7].Y;// 947;
//VP.Add(tp);
//////
//tp.dX = VPList[8].X;// 774;
//tp.dY = VPList[8].Y;// 236;
//VP.Add(tp);
//tp.dX = VPList[9].X;// 257;
//tp.dY = VPList[9].Y;// ;
//VP.Add(tp);
//tp.dX = VPList[10].X;// 307;
//tp.dY = VPList[10].Y;// 994;
//VP.Add(tp);
//tp.dX = VPList[11].X;// 303;
//tp.dY = VPList[11].Y;// 1727;
//VP.Add(tp);
/*************生成三维数据*********************/
for (int i = 0; i < VRList.Count; i++)
{
MyPoint tr;
tr.dX = VRList[0].X + PYliangx;
tr.dY = VRList[0].Y + PYliangy;
tr.dX = VRList[i].X + PYliangx;
tr.dY = VRList[i].Y + PYliangy;
VR.Add(tr);
}
//MyPoint tr;
//tr.dX = VRList[0].X + PYliangx;
//tr.dY = VRList[0].Y + PYliangy;
//VR.Add(tr);
tr.dX = VRList[1].X + PYliangx;
tr.dY = VRList[1].Y + PYliangy;
VR.Add(tr);
//tr.dX = VRList[1].X + PYliangx;
//tr.dY = VRList[1].Y + PYliangy;
//VR.Add(tr);
tr.dX = VRList[2].X + PYliangx;
tr.dY = VRList[2].Y + PYliangy;
VR.Add(tr);
//tr.dX = VRList[2].X + PYliangx;
//tr.dY = VRList[2].Y + PYliangy;
//VR.Add(tr);
//////////////
////////////////
tr.dX = VRList[3].X + PYliangx;
tr.dY = VRList[3].Y + PYliangy;
VR.Add(tr);
//tr.dX = VRList[3].X + PYliangx;
//tr.dY = VRList[3].Y + PYliangy;
//VR.Add(tr);
tr.dX = VRList[4].X + PYliangx;
tr.dY = VRList[4].Y + PYliangy;
VR.Add(tr);
//tr.dX = VRList[4].X + PYliangx;
//tr.dY = VRList[4].Y + PYliangy;
//VR.Add(tr);
tr.dX = VRList[5].X + PYliangx;
tr.dY = VRList[5].Y + PYliangy;
VR.Add(tr);
//tr.dX = VRList[5].X + PYliangx;
//tr.dY = VRList[5].Y + PYliangy;
//VR.Add(tr);
//////////////7
tr.dX = VRList[6].X + PYliangx;
tr.dY = VRList[6].Y + PYliangy;
VR.Add(tr);
////////////////7
//tr.dX = VRList[6].X + PYliangx;
//tr.dY = VRList[6].Y + PYliangy;
//VR.Add(tr);
tr.dX = VRList[7].X + PYliangx;
tr.dY = VRList[7].Y + PYliangy;
VR.Add(tr);
//tr.dX = VRList[7].X + PYliangx;
//tr.dY = VRList[7].Y + PYliangy;
//VR.Add(tr);
tr.dX = VRList[8].X + PYliangx;
tr.dY = VRList[8].Y + PYliangy;
VR.Add(tr);
//tr.dX = VRList[8].X + PYliangx;
//tr.dY = VRList[8].Y + PYliangy;
//VR.Add(tr);
//////////////
////////////////
tr.dX = VRList[9].X + PYliangx;
tr.dY = VRList[9].Y + PYliangy;
VR.Add(tr);
//tr.dX = VRList[9].X + PYliangx;
//tr.dY = VRList[9].Y + PYliangy;
//VR.Add(tr);
tr.dX = VRList[10].X + PYliangx;
tr.dY = VRList[10].Y + PYliangy;
VR.Add(tr);
//tr.dX = VRList[10].X + PYliangx;
//tr.dY = VRList[10].Y + PYliangy;
//VR.Add(tr);
tr.dX = VRList[11].X + PYliangx;
tr.dY = VRList[11].Y + PYliangy;
VR.Add(tr);
//tr.dX = VRList[11].X + PYliangx;
//tr.dY = VRList[11].Y + PYliangy;
//VR.Add(tr);
}
catch (Exception e)
{
@ -473,14 +528,16 @@ namespace BRS.Process.A020
Console.WriteLine(DateTime.Now + "==========配置=================" + stopWatch2.ElapsedMilliseconds + "===========================");
//MyPoint ssw = new MyPoint();
Mat Image = Cv2.ImRead(@"D:\MelsecPLCReadWrite\Bk\Image\1.png");
//Mat Image = Cv2.ImRead(@"D:\MelsecPLCReadWrite\Bk\Image\1.png");
List<MyPoint> resultPoint = new List<MyPoint>();
#if false
Mat _mat = dd.Clone();
string ss = "D:\\QT\\" + DateTime.Now.ToString("HHmmssfff") + ".jpg";
Cv2.ImWrite(ss, _mat);
#endif
Mat _mat = dd.Clone();
GetScrew(Image, resultPoint);
GetScrew(_mat, resultPoint);
MyPoint ssw3 = resultPoint[0];
@ -534,6 +591,9 @@ namespace BRS.Process.A020
var MelsecPLC = DeviceCollection.FirstOrDefault(u => u is PLCBase) as PLCBase;
var KawasakiRobot = DeviceCollection.Find(d => d is KawasakiTCPSeverRobotDriver) as KawasakiTCPSeverRobotDriver;
float NJZt = AModeTypeRun.NIJ_DisD;
StrRobotPoint strPointInitA;//示教点位
strPointInitA.X = 847.462F;
strPointInitA.Y = 891.623F;
@ -543,7 +603,7 @@ namespace BRS.Process.A020
strPointInitA.C = 90F;
RobotPoint robotInitPoint = KawasakiRobot.IIConfig.RobotInitPosition;//机械臂初始点位
StrRobotPoint initPoint = ClassChangeStruct(robotInitPoint);
#region
if (KawasakiRobot != null)
{
@ -559,8 +619,9 @@ namespace BRS.Process.A020
MachineState = MachineState.Running;
ProcessStatus = ProcessStatus.Init;
RobotsStatus = RobotsStatus.Release;
KawasakiRobotInit(KawasakiRobot);//机械臂移动到初始位置
OpenCam1();
KawasakiRobotMove(KawasakiRobot, initPoint);
//KawasakiRobotInit(KawasakiRobot);//机械臂移动到初始位置
//OpenCam1();
Task.Run(() =>
{
@ -621,13 +682,13 @@ namespace BRS.Process.A020
KawasakiRobot.SendMessage(PointInitMove);
LogAsync(DateTime.Now, LogLevel.Assist, $"机械臂A移动到示教点");
RobotsStatus = RobotsStatus.Runing;
DownCirce = DownCirce.DownCirce;//标志机械臂的运动状态
//DownCirce = DownCirce.DownCirce;//标志机械臂的运动状态
while (true)
{
if (DownCirce == DownCirce.DownCirceRuning)
break;
else
Thread.Sleep(10);
Thread.Sleep(20);
}
ProcessStatus = ProcessStatus.OpenLight;
//KawasakiRobotInit(KawasakiRobot);
@ -644,18 +705,20 @@ namespace BRS.Process.A020
//JYDAMDriver1.WriteStrs(SerialOpenLight);
#region
SoftTrigger1();
//SoftTrigger1();
Thread.Sleep(200);
while (CamA == true)
{
//拍照视觉定位
OnBitmapChanged?.Invoke(1, Bit_Image);
//OnBitmapChanged?.Invoke(1, Bit_Image);
Mat img = Cv2.ImRead(@"D:\testData\ShaftP\173648283.jpg");
Mat Mat_CamA = img.Clone();
OnCameraImageOutput(ref sswF, ref Mat_CamA, 1);
stopWatch.Stop();
Console.WriteLine(DateTime.Now + "=========拍照==================" + stopWatch.ElapsedMilliseconds + "===========================");
CamA = false;
}
ProcessStatus = ProcessStatus.CVLocation;
#endregion
}
break;
@ -692,7 +755,7 @@ namespace BRS.Process.A020
strPointInitA1 = strPointInitA;
StrRobotPoint strPointInitA2 = new StrRobotPoint();
strPointInitA2 = strPointInitA;
strPointInitA2.Z += Distance_DisD;//XYZ是毫米
strPointInitA2.Z += NJZt;//XYZ是毫米
_strRobotPointAs.Add(strPointInitA1);
_strRobotPointAs.Add(strPointInitA2);
//KawasakiRobotMoves(KawasakiRobot, _strRobotPointAs, false);
@ -904,7 +967,7 @@ namespace BRS.Process.A020
case ProcessStatus.UpShaft:
{
RobotPoint robotInitPoint1 = KawasakiRobot.IIConfig.RobotInitPosition;//机器人初始点
StrRobotPoint initPoint = ClassChangeStruct(robotInitPoint);
StrRobotPoint initPoint1 = ClassChangeStruct(robotInitPoint);
List<StrRobotPoint> _strRobotPointAup = new List<StrRobotPoint>();
StrRobotPoint strPointInitA3 = new StrRobotPoint();
@ -912,8 +975,8 @@ namespace BRS.Process.A020
StrRobotPoint strPointInitA4 = new StrRobotPoint();
strPointInitA4 = strPointInitA;
StrRobotPoint strPointInitA5 = new StrRobotPoint();
strPointInitA5 = initPoint;
strPointInitA4.Z -= Distance_DisD;//XYZ是毫米
strPointInitA5 = initPoint1;
strPointInitA4.Z -= NJZt;//XYZ是毫米
_strRobotPointAup.Add(strPointInitA4);
_strRobotPointAup.Add(strPointInitA3);
_strRobotPointAup.Add(strPointInitA5);
@ -1479,6 +1542,7 @@ namespace BRS.Process.A020
KawasakiRobotStatus = KawasakiRobotStatus.Runing;
while (true)
{
KawasakiRobotStatus = KawasakiRobotStatus.Stoped;
if (KawasakiRobotStatus == KawasakiRobotStatus.Stoped)
break;
else

View File

@ -368,11 +368,11 @@ namespace BRS.Process.A020
}
#endregion
#region
if (ProcessStatus == ProcessStatus.Measure && RobotsStatus == RobotsStatus.Runing && msg == "wanbi")
if (ProcessStatus == ProcessStatus.OpenLight && RobotsStatus == RobotsStatus)
{
msg = string.Empty;
DownCirce = DownCirce.DownCirceRuning;
ProcessStatus = ProcessStatus.OpenLight;
RobotsStatus = RobotsStatus.Release;
}
#endregion

View File

@ -65,7 +65,7 @@ namespace BRS.Process.A020.UI
//ProcessA020.OnBitmapChanged -= BitMapTest;
//ProcessA020.OnBitmapChanged += BitMapTest;
pLCBase = ProcessA020.DeviceCollection.FirstOrDefault(u => u is PLCBase) as PLCBase;
TcpListerWrapBase1 = ProcessA020.DeviceCollection.Find(d => d is TCPSeverBase && d.InitialConfig.Name == "123") as TCPSeverBase;
TcpListerWrapBase1 = ProcessA020.DeviceCollection.Find(d => d is TCPSeverBase && d.InitialConfig.Name == "KawasakiRobot") as TCPSeverBase;
if (TcpListerWrapBase1 != null)
{
TcpListerWrapBase1.OnTcpDataReceived -= NbtRobotDriver_OnDataReceived;
@ -87,7 +87,10 @@ namespace BRS.Process.A020.UI
private void NbtRobotDriver_OnDataReceived(byte[] obj)
{
string msg = string.Empty;
RobotAStatus.BackColor = Color.Green;
msg = Encoding.Default.GetString(obj);
Message1 = msg;
//}
//else if (rbHexData.Checked)
@ -579,6 +582,7 @@ namespace BRS.Process.A020.UI
if (isStart)
{
ProcessOperation(true);
//RobotAStatus.BackColor = Color.Green;
//ProcessOperation(true);
}
}