public void SaveResult(string pathDir) { string path = pathDir; DirUtils.CreateDir(path); //this.FileName = this.FileName.Replace(':', '_'); path = path + "\\" + DateTime.Now.ToString("yyyyMMdd HHmmss"); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(this.Barcode + "\r\n"); stringBuilder.Append(FluidProgram.CurrentOrDefault().RuntimeSettings.CustomParam.RTVParam.Depart + "\r\n"); stringBuilder.Append(FluidProgram.CurrentOrDefault().RuntimeSettings.CustomParam.RTVParam.ComputerInfo + "\r\n"); stringBuilder.Append(FluidProgram.CurrentOrDefault().RuntimeSettings.CustomParam.RTVParam.MachineInfo + "\r\n"); stringBuilder.Append(this.GetBarcodePart(this.Barcode) + "\r\n"); stringBuilder.Append(FluidProgram.CurrentOrDefault().RuntimeSettings.CustomParam.RTVParam.ProductLineInfo + "\r\n"); stringBuilder.Append(FluidProgram.CurrentOrDefault().RuntimeSettings.CustomParam.RTVParam.OwkInfo + "\r\n"); stringBuilder.Append(FluidProgram.CurrentOrDefault().RuntimeSettings.CustomParam.RTVParam.UserInfo + "\r\n"); stringBuilder.Append(this.GetProgramRunTime() + "\r\n"); stringBuilder.Append(this.GetProgramEndTime() + "\r\n"); stringBuilder.Append("No Width MaxValue MinValue Height MaxValue MinValue" + "\r\n"); for (int i = 0; i < this.Results.Count; i++) { string s = ""; s += (1 + i).ToString() + " "; s += this.Results[i][0] + " "; s += this.Results[i][1] + " "; s += this.Results[i][2] + " "; s += this.Results[i][3] + " "; s += this.Results[i][4] + " "; s += this.Results[i][5]; stringBuilder.Append(s + "\r\n"); } CsvUtil.WriteLine(path, stringBuilder.ToString()); }
private void recdPatternWeight() { string strheadline = "时间,型号,实际重量(mg),重量范围(mg),状态,NG原因"; string line = String.Empty; //记录拼版重量CSV if (!File.Exists(PatternWeightSettings.FilePathMatrixWeight)) { //时间 型号 实际重量(mg) 重量范围(mg) 状态 NG原因 CsvUtil.WriteLine(PatternWeightSettings.FilePathMatrixWeight, strheadline); } else { line = String.Format("{0},{1},{2},{3},{4}", DateTime.Now.ToString(), FluidProgram.Current.Name, this.Valve.weightPrm.DifferWeight, String.Format("{0}-{1}", (getPatWgt(this.shotNums) * (1 - this.Valve.weightPrm.WeightOffset / 100.0d)), (getPatWgt(this.shotNums) * (1 + this.Valve.weightPrm.WeightOffset / 100.0d))), this.CaliPatWgtResult()); CsvUtil.WriteLine(PatternWeightSettings.FilePathMatrixWeight, line); } if (!String.IsNullOrEmpty(PatternWeightSettings.FilePathMatrixWeightUser)) { if (!File.Exists(PatternWeightSettings.FilePathMatrixWeightUser)) { CsvUtil.WriteLine(PatternWeightSettings.FilePathMatrixWeightUser, strheadline); } else { CsvUtil.WriteLine(PatternWeightSettings.FilePathMatrixWeightUser, line); } } }
//记录单点重量CSV private void recDotWeight() { //Time NozzalNumber DotWeight string strheadline = "Time,NozzalNumber,DotWeight"; string line = String.Empty; if (!File.Exists(PatternWeightSettings.FilePathDotWeight)) { //时间 型号 实际重量(mg) 重量范围(mg) 状态 NG原因 CsvUtil.WriteLine(PatternWeightSettings.FilePathDotWeight, strheadline); } else { line = String.Format("{0},{1},{2}", DateTime.Now.ToString(), ((ValueType)this.Valve.Key).ToString(), this.Valve.weightPrm.SingleDotWeight); CsvUtil.WriteLine(PatternWeightSettings.FilePathDotWeight, line); } if (!String.IsNullOrEmpty(PatternWeightSettings.FilePathDotWeightUser)) { if (!File.Exists(PatternWeightSettings.FilePathDotWeightUser)) { CsvUtil.WriteLine(PatternWeightSettings.FilePathDotWeightUser, strheadline); } else { CsvUtil.WriteLine(PatternWeightSettings.FilePathDotWeightUser, line); } } }
/// <summary> /// 螺杆阀Inspect模式下的运行逻辑 /// </summary> /// <returns></returns> private Result SvValveInspectLogic(Line line) { Result ret = Result.OK; List <PointD> points = this.CaculateSvValvePoints(line); if (line.LineCmd.lineCmdLine == null || points == null) { return(ret); } if (line.LineCmd.lineCmdLine.LineMethod != LineMethod.Single) { return(ret); } for (int i = 0; i < points.Count; i++) { //为了去到线段的起点,会跳过list的奇数部分(终点) if (i % 2 == 1) { continue; } else { ret = Machine.Instance.Robot.MovePosXYAndReply(points[i], FluidProgram.Current.MotionSettings.VelXY, FluidProgram.Current.MotionSettings.AccXY); if (!ret.IsOk) { return(ret); } LineCmdLine lineCmdline = line.LineCmd.lineCmdLine; InspectionLine inspectionLine = InspectionMgr.Instance.FindBy((int)lineCmdline.inspectionKey) as InspectionLine; if (inspectionLine != null) { Thread.Sleep(inspectionLine.SettlingTime); double width1, width2; Machine.Instance.CaptureAndInspect(inspectionLine); width1 = inspectionLine.PhyWidth1; width2 = inspectionLine.PhyWidth2; Log.Dprint(inspectionLine.CurrResultStr); string resline = string.Format("{0},{1},{2},{3}", Math.Round(points[i].X, 3), Math.Round(points[i].Y, 3), Math.Round(width1, 3), Math.Round(width2, 3)); CsvUtil.WriteLine(line.Program.RuntimeSettings.FilePathInspectRect, resline); Thread.Sleep(inspectionLine.DwellTime); } } } return(ret); }
/// <summary> /// InspectDot模式下的逻辑 /// </summary> /// <param name="dot"></param> /// <returns></returns> protected Result InspectDotLogic(Dot dot) { Log.Dprint("begin to execute Dot-InspectDot"); Result ret = Result.OK; //抬起到安全高度 ret = Machine.Instance.Robot.MoveSafeZAndReply(); if (!ret.IsOk) { return(ret); } // 移动到指定位置 Log.Dprint("move to position XY : " + dot.Position); //ret = Machine.Instance.Robot.MovePosXYAndReply(dot.Position); ret = Machine.Instance.Robot.MovePosXYAndReply(dot.Position, FluidProgram.Current.MotionSettings.VelXY, FluidProgram.Current.MotionSettings.AccXY); if (!ret.IsOk) { return(ret); } InspectionDot inspectionDot = InspectionMgr.Instance.FindBy((int)InspectionKey.Dot1) as InspectionDot; if (inspectionDot != null) { Thread.Sleep(inspectionDot.SettlingTime); double dx, dy; Machine.Instance.CaptureAndInspect(inspectionDot); dx = inspectionDot.PhyResultX; dy = inspectionDot.PhyResultY; string line = string.Format("{0},{1},{2},{3}", Math.Round(dot.Position.X, 3), Math.Round(dot.Position.Y, 3), Math.Round(dx, 3), Math.Round(dy, 3)); CsvUtil.WriteLine(dot.Program.RuntimeSettings.FilePathInspectDot, line); Thread.Sleep(inspectionDot.DwellTime); } // 等待一段时间 Settling Time Log.Dprint("wait Settling Time(s) : " + dot.Param.SettlingTime); Thread.Sleep(TimeSpan.FromSeconds(dot.Param.SettlingTime)); return(ret); }
public void recordWeight() { string line; //记录拼版重量CSV if (File.Exists(MesSettings.FilePathDotWeight)) { //时间 型号 实际重量(mg) 重量范围(mg) 状态 NG原因 line = "时间,型号,实际重量(mg),重量范围(mg),状态NG原因"; CsvUtil.WriteLine(MesSettings.FilePathDotWeight, line); } else { line = String.Format("{0},{1},{2},{3},{4}", DateTime.Now.ToString(), "", this); CsvUtil.WriteLine(MesSettings.FilePathDotWeight, this.WeightPattern.ToString()); } //记录单点重量CSV }
/// <summary> /// CV模式和点检测模式的运行逻辑 /// </summary> /// <returns></returns> private Result CvAndInspectLogic(PointD pos) { Result ret = Result.OK; ret = Machine.Instance.Robot.MoveSafeZAndReply(); if (!ret.IsOk) { return(ret); } // 移动到指定位置 Log.Dprint("move to position XY : " + pos); ret = Machine.Instance.Robot.MovePosXYAndReply(pos, this.Program.MotionSettings.VelXY, this.Program.MotionSettings.AccXY); if (!ret.IsOk) { return(ret); } if (Machine.Instance.Valve1.RunMode == Drive.ValveSystem.ValveRunMode.InspectDot) { InspectionDot inspectionDot = InspectionMgr.Instance.FindBy((int)InspectionKey.Dot1) as InspectionDot; if (inspectionDot != null) { Thread.Sleep(inspectionDot.SettlingTime); double dx, dy; Machine.Instance.CaptureAndInspect(inspectionDot); dx = inspectionDot.PhyResultX; dy = inspectionDot.PhyResultY; string line = string.Format("{0},{1},{2},{3}", Math.Round(pos.X, 3), Math.Round(pos.Y, 3), Math.Round(dx, 3), Math.Round(dy, 3)); CsvUtil.WriteLine(Program.RuntimeSettings.FilePathInspectDot, line); Thread.Sleep(inspectionDot.DwellTime); } } return(ret); }
public bool SaveComponent() { try { if (File.Exists(this.csvpath)) { File.Delete(this.csvpath); } string resline = string.Format("{0},{1},{2},{3},{4},{5}", HeadName.Design.ToString(), HeadName.Comp, HeadName.X.ToString(), HeadName.Y.ToString(), HeadName.Rot.ToString(), HeadName.LayOut.ToString()); CsvUtil.WriteLine(this.csvpath, resline); foreach (CompProperty p in this.CompList) { resline = string.Format("{0},{1},{2},{3},{4},{5}", p.Desig, p.Comp, Math.Round(p.Mid.X, 3), Math.Round(p.Mid.Y, 3), Math.Round(p.Rotation, 2), p.LayOut); CsvUtil.WriteLine(this.csvpath, resline); } return(true); } catch (Exception) { return(false); } }
private DialogResult saveCSV(List <MapPoint> list) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "*.csv|*.*"; DialogResult dr = sfd.ShowDialog(); if (dr == DialogResult.OK) { string fileName = sfd.FileName + ".csv"; string head = "index_x,index_y,robot_x,robot_y,real_x,real_y,delta_x,delta_y"; CsvUtil.WriteLine(fileName, head); foreach (var item in list) { StringBuilder builder = new StringBuilder(); string line = string.Format("{0},{1},{2},{3},{4},{5},{6},{7}", item.IndexX, item.IndexY, item.RobotX, Math.Round(item.RobotY, 3), Math.Round(item.RealX, 3), Math.Round(item.RealY, 3), Math.Round(item.RealX - item.RobotX, 3), Math.Round(item.RealY - item.RobotY, 3)); CsvUtil.WriteLine(fileName, line); } } return(dr); }
/// <summary> /// 执行单条线段命令,连续插补模式,将每条线压入插补队列 /// </summary> /// <param name="line"></param> /// <param name="accStart">加速区间距离</param> /// <param name="decelEnd">减速区间距离</param> /// <param name="speed">线段区间的运动速度</param> /// <param name="points">每一滴胶水的点胶位置</param> /// <param name="intervalSec">每一滴胶水的打胶时间,单位秒</param> /// <returns></returns> private Result executeSingleLine(Line directiveLine, LineCoordinate line, PointD accStart, PointD decelEnd, double speed, PointD[] points, double intervalSec) { double lineOffset = line.Param.Offset; // 偏移调整 if (Machine.Instance.Valve1.RunMode == ValveRunMode.Dry || Machine.Instance.Valve1.RunMode == ValveRunMode.Wet || Machine.Instance.Valve1.RunMode == ValveRunMode.AdjustLine) { if (directiveLine.LineCmd.RunnableModule.CommandsModule.IsReversePattern) { lineOffset += line.LookOffsetRevs; } else { lineOffset += line.LookOffset; } } VectorD v = (line.End - line.Start).Normalize() * lineOffset; //相机位置 PointD cameraLineStart = line.Start + v; PointD cameraLineEnd = line.End + v; PointD cameraAccStart = accStart + v; PointD cameraDecEnd = decelEnd + v; PointD[] cameraPoints = new PointD[points.Length]; PointD[] cameraPoints2 = new PointD[points.Length];//副阀的点位 for (int i = 0; i < points.Length; i++) { cameraPoints[i] = points[i] + v; } //胶枪点胶起点 PointD valveAccStart = cameraAccStart.ToNeedle(directiveLine.Valve, directiveLine.Tilt); //副阀点胶起点位置(默认值为设定间距) PointD simulStart = new PointD(directiveLine.Program.RuntimeSettings.SimulDistence, 0) /*-胶阀原点间距?*/; ///生成副阀相关参数(起点、插补点位) if (directiveLine.RunnableModule.Mode == ModuleMode.MainMode) { //副阀插补坐标绝对值(X方向实际坐标取负值) = 主阀机械坐标-副阀机械坐标-双阀原点间距(理论情况-不考虑坐标系不平行) VectorD SimulModuleOffset = Machine.Instance.Robot.CalibPrm.NeedleCamera2 - Machine.Instance.Robot.CalibPrm.NeedleCamera1; for (int i = 0; i < points.Length; i++) { cameraPoints2[i] = cameraPoints[i] - directiveLine.RunnableModule.SimulTransformer.Transform(cameraPoints[i]).ToVector() - SimulModuleOffset; //乘以系数得到AB轴的移动位移 cameraPoints2[i].X = -Math.Abs(cameraPoints2[i].X) / Machine.Instance.Robot.CalibPrm.HorizontalRatio; cameraPoints2[i].Y = -cameraPoints2[i].Y / Machine.Instance.Robot.CalibPrm.VerticalRatio; } //副阀在加速段直接使用实际点胶起始位置 simulStart = cameraPoints2[0]; } Result ret = Result.OK; double targZ = 0; if (Machine.Instance.Laser.Laserable.Vendor == Drive.Sensors.HeightMeasure.Laser.Vendor.Disable) { targZ = directiveLine.Program.RuntimeSettings.BoardZValue + line.Param.DispenseGap; } else { targZ = Converter.NeedleBoard2Z(line.Param.DispenseGap, directiveLine.CurMeasureHeightValue, directiveLine.Tilt); } if (Machine.Instance.Valve1.RunMode == Drive.ValveSystem.ValveRunMode.Look || Machine.Instance.Valve1.RunMode == Drive.ValveSystem.ValveRunMode.AdjustLine || Machine.Instance.Valve1.RunMode == Drive.ValveSystem.ValveRunMode.InspectRect) { ret = Machine.Instance.Robot.BufMoveSafeZ(); if (!ret.IsOk) { return(ret); } if (Machine.Instance.Valve1.RunMode == Drive.ValveSystem.ValveRunMode.Look) { ret = Machine.Instance.Robot.BufMoveLnXY(cameraLineStart, FluidProgram.Current.MotionSettings.VelXY, FluidProgram.Current.MotionSettings.AccXY); if (!ret.IsOk) { return(ret); } ret = Machine.Instance.Robot.BufMoveLnXY(cameraLineEnd, line.Param.Speed, FluidProgram.Current.MotionSettings.AccXY); if (!ret.IsOk) { return(ret); } Log.Print("current position in LookMode: " + cameraAccStart.ToString() + " || the LookOffset:" + line.LookOffset); } else if (Machine.Instance.Valve1.RunMode == Drive.ValveSystem.ValveRunMode.AdjustLine) { ret = Machine.Instance.Robot.MovePosXYAndReply(cameraLineStart, FluidProgram.Current.MotionSettings.VelXY, FluidProgram.Current.MotionSettings.AccXY); if (!ret.IsOk) { return(ret); } LineCmdLine lineCmdline = directiveLine.LineCmd.lineCmdLine; if (lineCmdline == null || line == null) { return(ret); } Machine.Instance.IsProducting = false; Line.WaitMsg.Reset(); switch (lineCmdline.LineMethod) { case LineMethod.Single: MsgCenter.Broadcast(MsgType.MSG_LINEEDITLOOK_SHOW, directiveLine, lineCmdline); break; case LineMethod.Multi: case LineMethod.Poly: MsgCenter.Broadcast(MsgType.MSG_LINEEDITLOOK_SHOW, directiveLine, lineCmdline, directiveLine.LineCoordinates.IndexOf(line)); break; default: break; } Line.WaitMsg.WaitOne(); Machine.Instance.IsProducting = true; } else if (Machine.Instance.Valve1.RunMode == Drive.ValveSystem.ValveRunMode.InspectRect) { ret = Machine.Instance.Robot.MovePosXYAndReply(cameraLineStart, FluidProgram.Current.MotionSettings.VelXY, FluidProgram.Current.MotionSettings.AccXY); if (!ret.IsOk) { return(ret); } LineCmdLine lineCmdline = directiveLine.LineCmd.lineCmdLine; if (lineCmdline == null || line == null) { return(ret); } if (lineCmdline.LineMethod != LineMethod.Single) { return(ret); } InspectionLine inspectionLine = InspectionMgr.Instance.FindBy((int)lineCmdline.inspectionKey) as InspectionLine; if (inspectionLine != null) { Thread.Sleep(inspectionLine.SettlingTime); double width1, width2; Machine.Instance.CaptureAndInspect(inspectionLine); width1 = inspectionLine.PhyWidth1; width2 = inspectionLine.PhyWidth2; Log.Dprint(inspectionLine.CurrResultStr); string resline = string.Format("{0},{1},{2},{3}", Math.Round(cameraLineStart.X, 3), Math.Round(cameraLineStart.Y, 3), Math.Round(width1, 3), Math.Round(width2, 3)); CsvUtil.WriteLine(directiveLine.Program.RuntimeSettings.FilePathInspectRect, resline); Thread.Sleep(inspectionLine.DwellTime); } } return(ret); } // 倾斜到位 Log.Dprint("change tilt status : " + directiveLine.Tilt.ToString()); ret = Machine.Instance.Valve1.BufChangeValveTiltStatus(directiveLine.Tilt, FluidProgram.Current.MotionSettings.VelU, FluidProgram.Current.MotionSettings.AccU); if (!ret.IsOk) { return(ret); } double currZ = Machine.Instance.Robot.PosZ; //到起点,Z轴到点胶位置 if (currZ > targZ) { // 移动到加速区间起始位置 Log.Dprint("move to position XY : " + valveAccStart); if (directiveLine.RunnableModule.Mode == ModuleMode.MainMode) { ret = Machine.Instance.Robot.MovePosXYABAndReply(valveAccStart, simulStart, FluidProgram.Current.MotionSettings.VelXYAB, FluidProgram.Current.MotionSettings.AccXYAB, (int)Machine.Instance.Setting.CardSelect); } else { ret = Machine.Instance.Robot.BufMoveLnXY(valveAccStart, FluidProgram.Current.MotionSettings.VelXY, FluidProgram.Current.MotionSettings.AccXY); } if (!ret.IsOk) { return(ret); } Log.Dprint("move down to Z : " + targZ.ToString("0.000000") + ", DispenseGap=" + line.Param.DispenseGap.ToString("0.000000")); ret = Machine.Instance.Robot.BufMovePosZ(targZ, line.Param.DownSpeed, line.Param.DownAccel); if (!ret.IsOk) { return(ret); } } else { Log.Dprint("move up to Z : " + targZ.ToString("0.000000") + ", DispenseGap=" + line.Param.DispenseGap.ToString("0.000000")); ret = Machine.Instance.Robot.BufMovePosZ(targZ, line.Param.DownSpeed, line.Param.DownAccel); if (!ret.IsOk) { return(ret); } // 移动到加速区间起始位置 Log.Dprint("move to position XY : " + valveAccStart); if (directiveLine.RunnableModule.Mode == ModuleMode.MainMode) { ret = Machine.Instance.Robot.MovePosXYABAndReply(valveAccStart, simulStart, FluidProgram.Current.MotionSettings.VelXYAB, FluidProgram.Current.MotionSettings.AccXYAB, (int)Machine.Instance.Setting.CardSelect); } else { ret = Machine.Instance.Robot.BufMoveLnXY(valveAccStart, FluidProgram.Current.MotionSettings.VelXY, FluidProgram.Current.MotionSettings.AccXY); } if (!ret.IsOk) { return(ret); } } // 移动: 加速区间--线段区间--减速区间 Log.Dprint("fluid line, accStart=" + cameraAccStart + " start=" + cameraLineStart + ", end=" + cameraLineEnd + ", decelEnd=" + cameraDecEnd + ", spped=" + speed); //printPoints(newPoints); if (directiveLine.RunnableModule.Mode == ModuleMode.MainMode) { ret = Machine.Instance.DualValve.FluidLine(cameraAccStart, cameraLineStart, cameraLineEnd, cameraDecEnd, speed, cameraPoints, intervalSec, simulStart, cameraPoints2, FluidProgram.Current.MotionSettings.WeightAcc); GlueManagerMgr.Instance.UpdateGlueRemainWeight(0, points.Length * directiveLine.Program.RuntimeSettings.SingleDropWeight); GlueManagerMgr.Instance.UpdateGlueRemainWeight(1, points.Length * directiveLine.Program.RuntimeSettings.SingleDropWeight); } else if (directiveLine.RunnableModule.Mode == ModuleMode.DualFallow) { ret = Machine.Instance.DualValve.FluidLine(cameraAccStart, cameraLineStart, cameraLineEnd, cameraDecEnd, speed, cameraPoints, intervalSec, FluidProgram.Current.MotionSettings.WeightAcc); GlueManagerMgr.Instance.UpdateGlueRemainWeight(0, points.Length * directiveLine.Program.RuntimeSettings.SingleDropWeight); GlueManagerMgr.Instance.UpdateGlueRemainWeight(1, points.Length * directiveLine.Program.RuntimeSettings.SingleDropWeight); } else if (directiveLine.RunnableModule.Mode == ModuleMode.AssignMode2) { ret = Machine.Instance.Valve2.FluidLine(cameraAccStart, cameraLineStart, cameraLineEnd, cameraDecEnd, speed, cameraPoints, intervalSec, FluidProgram.Current.MotionSettings.WeightAcc); GlueManagerMgr.Instance.UpdateGlueRemainWeight(1, points.Length * directiveLine.Program.RuntimeSettings.SingleDropWeight); } else { ret = Machine.Instance.Valve1.BufFluidLine(cameraAccStart, cameraLineStart, cameraLineEnd, cameraDecEnd, speed, cameraPoints, intervalSec, FluidProgram.Current.MotionSettings.WeightAcc); GlueManagerMgr.Instance.UpdateGlueRemainWeight(0, points.Length * directiveLine.Program.RuntimeSettings.SingleDropWeight); } if (!ret.IsOk) { return(ret); } if (Machine.Instance.Valve1.RunMode == Drive.ValveSystem.ValveRunMode.Wet || Machine.Instance.Valve1.RunMode == Drive.ValveSystem.ValveRunMode.Dry) { Log.Dprint("RetractDistance : " + line.Param.RetractDistance); // 减速区间运动完成后,x y 轴速度为0, 此时需要抬升一段高度 if (line.Param.RetractDistance > 0) { Log.Dprint("move up RetractDistance : " + line.Param.RetractDistance); ret = Machine.Instance.Robot.BufMoveIncZ(line.Param.RetractDistance, line.Param.RetractSpeed, line.Param.RetractAccel); if (!ret.IsOk) { return(ret); } } } return(ret); }