public Level2() { Console.WriteLine("Level2"); Reset(); timebarSpace = 10.768F; this.Add(new SpriteGameObject("spr_background")); thePlayer = new Player(3, 3); door = new Door(14, 0); goal = new MainGoal(26, 3); xaxis = new Xaxis(8, "Map/spr_horizontal_art_blue"); yaxis = new Yaxis(20, "Map/spr_vertical_art_blue"); Mouse.SetPosition(GameEnvironment.Screen.X / 2, GameEnvironment.Screen.Y / 2); floors = new GameObjectList(); walls = new GameObjectList(); goals = new GameObjectList(); inputScreen = new InputScreen(GameEnvironment.Screen.X / 2 - 64 * 2, GameEnvironment.Screen.Y); inputanswer = new InputAnswer(GameEnvironment.Screen.X / 2 - 64 * 2, GameEnvironment.Screen.Y); timeGround = new SpriteGameObject("Map/time_ground"); guards = new GameObjectList(); lasers = new GameObjectList(); times = new GameObjectList(); score = new Score(12, 20, (int)time); Axis_nums = new Axis_numbers(20, 8); switchBoards = new GameObjectList(); this.Add(floors); this.Add(switchBoards); this.Add(lasers); this.Add(walls); this.Add(door); this.Add(xaxis); this.Add(yaxis); this.Add(Axis_nums); this.Add(goal); this.Add(goals); this.Add(guards); this.Add(thePlayer); this.Add(inputScreen); this.Add(timeGround); this.Add(times); this.Add(score); this.Add(inputanswer); goals.Add(new ExtraGoal(11, 9)); guards.Add(new Guard(new Vector2(3, 13), new Vector2(25, 13))); FloorSetup(); WallSetup(); TimeBarSetup(); SoundSetup(); lasers.Add(new Laser(new Vector2(11, 6), new Vector2(14, 10), Color.Red, xaxis.gridPos, yaxis.gridPos)); lasers.Add(new Laser(new Vector2(23, 10), new Vector2(28, 7), Color.Blue, xaxis.gridPos, yaxis.gridPos)); switchBoards.Add(new SwitchBoard(3, 7, Color.Blue)); switchBoards.Add(new SwitchBoard(22, 3, Color.Red)); }
private Box <IPlotProperty> _CreateLayoutProperties() { var xaxis = Scene.xaxis(Xaxis.color("red")); var yaxis = Scene.yaxis(Yaxis.color("green")); var zaxis = Scene.zaxis(Zaxis.color("blue")); var camera = Camera.up(Up.x(0), Up.y(1), Up.z(0)); var scene = Layout.scene(Scene.Aspectmode.data(), Scene.camera(camera), xaxis, yaxis, zaxis); var shapes = Layout.shapes(_Shapes.ToArray()); return(Plot.layout (Layout.autosize(true) // , Layout.width(0) , Layout.height(920) // , Layout.margin(Margin.autoexpand(true)) // , Layout.margin(Margin.pad(5)) // , Layout.margin(Margin.t(5), Margin.b(5)) , scene , shapes )); }
/// <summary> /// 从世界坐标变换到摄像机坐标 /// </summary> /// <param name="eye"></param> /// <param name="at"></param> /// <param name="up"></param> /// <returns></returns> public static Matrix GetViewMatrix(Vector eye, Vector at, Vector up) { Vector Xaxis, Yaxis, Zaxis; Zaxis = at - eye; Zaxis.NormalizedVector(); Xaxis = Vector.CrossMultiply(up, Zaxis); Xaxis.NormalizedVector(); Yaxis = Vector.CrossMultiply(Zaxis, Xaxis); Matrix mat = new Matrix(); mat[0, 0] = Xaxis.x; mat[1, 0] = Xaxis.y; mat[2, 0] = Xaxis.z; mat[3, 0] = -Vector.DotMultiply(Xaxis, eye); mat[0, 1] = Yaxis.x; mat[1, 1] = Yaxis.y; mat[2, 1] = Yaxis.z; mat[3, 1] = -Vector.DotMultiply(Yaxis, eye); mat[0, 2] = Zaxis.x; mat[1, 2] = Zaxis.y; mat[2, 2] = Zaxis.z; mat[3, 2] = -Vector.DotMultiply(Zaxis, eye); mat[0, 3] = 0; mat[1, 3] = 0; mat[2, 3] = 0; mat[3, 3] = 1; //-----------------------得到旋转矩阵------------------ return(mat); }
public override void Running(RunningModes runningMode) { var step = 0; var ScrewIsDone = 0; var CannotTorIn = false; var GetScrewPos = new Point3D <int>(); var ScrewHolePos = new Point3D <int>(); var ZaxisScrewpos = 0; var watchCameratimeout = new Stopwatch(); //var watchScrewtimeout = new Stopwatch(); var tempPut1 = false; var tempPut2 = false; var GetScrew1 = false; var GetScrew2 = false; var pressPulse = false; var startForbid = false; var _watch = new Stopwatch(); _watch.Start(); PlateformAlarm alarm = 0; while (true) { Thread.Sleep(10); InhaleCylinder.Condition.External = externalSign; #region 判断后端设备交互信号 if (tempPut1 && !GetScrew2) { tempPut1 = false; GetScrew1 = true; } if (tempPut2 && !GetScrew1) { tempPut2 = false; GetScrew2 = true; } if (!IoPoints.TDI7.Value && !Global.GetScrew1SignSheild) { tempPut1 = false; } if (!IoPoints.TDI8.Value && !Global.GetScrew2SignSheild) { tempPut2 = false; } if ((IoPoints.TDI7.Value || Global.GetScrew1SignSheild) && !GetScrew1 && !GetScrew2) { tempPut1 = true; } if ((IoPoints.TDI8.Value || Global.GetScrew2SignSheild) && !GetScrew1 && !GetScrew2) { tempPut2 = true; } #endregion #region 自动流程 if (stationOperate.Running) { switch (step) { case 0: Marking.CoderResult.SN = ""; Marking.CoderResult.Result = ""; step = 10; Marking.watchCT.Restart(); break; case 10: //触发读码器读码 ReadCodePort.Trigger(new TriggerArgs() { tryTimes = 1 }); step = 20; break; case 20: //判断读码器是否读到SN Thread.Sleep(300); if (Marking.CoderResult.SN == "") { step = 10; } else { step = 30; } break; case 30: //双按钮启动,双按钮按下的时间间隔必须小于500ms才正常启动设备 if (!pressPulse && (IoPoints.TDI15.Value || IoPoints.TDI16.Value)) { pressPulse = true; startForbid = true; _watch.Restart(); } if (startForbid && IoPoints.TDI15.Value && IoPoints.TDI16.Value) { step = 40; startForbid = false; pressPulse = false; } else { if (500 <= _watch.ElapsedMilliseconds) { startForbid = false; } } if (!IoPoints.TDI15.Value && !IoPoints.TDI16.Value) { pressPulse = false; startForbid = false; } break; case 40: //判断哪个螺丝整列机优先准备好 if (GetScrew1 && !GetScrew2) { GetScrewPos = Position.Put1ScrewPosition; step = 50; } else if (!GetScrew1 && GetScrew2) { GetScrewPos = Position.Put2ScrewPosition; step = 50; } break; case 50: //判断Z轴是否在0位置,X轴移动到取螺丝位置 if (Zaxis.IsInPosition(0)) { Xaxis.MoveTo(GetScrewPos.X, AxisParameter.XvelocityCurve); step = 60; } break; case 60: //X轴到达取螺丝位置,Z轴下降 if (Xaxis.IsInPosition(GetScrewPos.X)) { Zaxis.MoveTo(GetScrewPos.Z, AxisParameter.ZvelocityCurve); step = 70; } break; case 70: //Z轴到达取螺丝位置,吸真空 if (Zaxis.IsInPosition(GetScrewPos.Z)) { InhaleCylinder.Set(); step = 80; } break; case 80: //Z轴上升0位置 if (InhaleCylinder.OutMoveStatus) { Zaxis.MoveTo(0, AxisParameter.ZvelocityCurve); ScrewHolePos = Position.ScrewHolePosition[Marking.WorkIndex - 1]; step = 90; } break; case 90: //Z轴到达0位置,XY轴移动拧螺丝位置 if (Zaxis.IsInPosition(0)) { Xaxis.MoveTo(ScrewHolePos.X, AxisParameter.XvelocityCurve); Yaxis.MoveTo(ScrewHolePos.Y, AxisParameter.YvelocityCurve); step = 100; } break; case 100: //XY轴到达拧螺丝位置,Z轴下降 if (Xaxis.IsInPosition(ScrewHolePos.X) && Yaxis.IsInPosition(ScrewHolePos.Y)) { Zaxis.MoveTo(ScrewHolePos.Z, AxisParameter.ZvelocityCurve); step = 110; } break; case 110: //Z轴到达拧螺丝位置,启动电批,并Z轴慢速下行 if (Zaxis.IsInPosition(ScrewHolePos.Z)) { IoPoints.TDO11.Value = true; ZaxisScrewpos = ScrewHolePos.Z + Position.ScrewDepth; if (IoPoints.TDI9.Value) { Zaxis.MoveTo(ZaxisScrewpos, new VelocityCurve(0, (double)Position.ZScrewSpeed, 0)); step = 120; } } break; case 120: //Z轴到达位置,判断螺丝是否拧紧 if (Zaxis.IsInPosition(ZaxisScrewpos)) { if (alarm == PlateformAlarm.收不到电批的螺丝拧紧正常或拧紧异常信号) { CannotTorIn = true; alarm = PlateformAlarm.无消息; IoPoints.TDO11.Value = false; IoPoints.TDO12.Value = true; Thread.Sleep(200); IoPoints.TDO12.Value = false; step = 130; } if (IoPoints.TDI10.Value || IoPoints.TDI11.Value) { step = 130; } else { if (ScrewIsDone > 2) { alarm = PlateformAlarm.收不到电批的螺丝拧紧正常或拧紧异常信号; m_Alarm = PlateformAlarm.收不到电批的螺丝拧紧正常或拧紧异常信号; } Thread.Sleep(100); ScrewIsDone++; } } break; case 130: //触发读取数据 ScrewPort.Trigger(new TriggerArgs() { tryTimes = 1, message = "0,TR" }); HeightGaugePort.Trigger(new TriggerArgs() { tryTimes = 1 }); Thread.Sleep(200); step = 140; break; case 140: //判断检测结果 if (CannotTorIn) { Marking.ResultScrew[Marking.WorkIndex].Result = "NG"; step = 150; } else { if (Marking.ResultScrew[Marking.WorkIndex].Result == "OK") { var data = Marking.ResultScrew[Marking.WorkIndex].HeightValue - Global.BaseHeight; if (data > Position.MinHeight && data <= Position.MaxHeight) { Marking.ResultScrew[Marking.WorkIndex].Result = "OK"; } else { Marking.ResultScrew[Marking.WorkIndex].Result = "NG"; } step = 150; } if (Marking.ResultScrew[Marking.WorkIndex].Result == "NG") { step = 150; } } break; case 150: //电批停止,真空吸气OFF,Z轴回到0位置 IoPoints.TDO11.Value = false; InhaleCylinder.Reset(); Zaxis.MoveTo(0, AxisParameter.ZvelocityCurve); step = 160; break; case 160: //真空吸气达到,Z轴到达0位置,计数加+1 if (InhaleCylinder.OutOriginStatus && Zaxis.IsInPosition(0)) { Marking.WorkIndex++; if (Marking.WorkIndex < Position.HoleNum) { step = 40; } else { step = 170; } } break; case 170: //判断产品拧螺丝结果 for (var i = 0; i < Position.HoleNum; i++) { if (Marking.ResultScrew[i].Result == "OK") { Marking.ProductResult &= true; } else { Marking.ProductResult &= false; } } if (Marking.ProductResult) { Config.ProductOkTotal++; } else { Config.ProductNgTotal++; } step = 180; break; case 180: //XY轴回到0位置 Xaxis.MoveTo(0, AxisParameter.XvelocityCurve); Yaxis.MoveTo(0, AxisParameter.YvelocityCurve); step = 190; break; case 190: //XY轴到达0位置 if (Xaxis.IsInPosition(0) && Yaxis.IsInPosition(0)) { step = 200; } break; default: Marking.ProductResult = true; stationOperate.RunningSign = false; Marking.WorkIndex = 0; step = 0; break; } } #endregion #region 初始化流程 if (stationInitialize.Running) { switch (stationInitialize.Flow) { case 0: //清除所有标志位的状态 stationInitialize.InitializeDone = false; stationOperate.RunningSign = false; alarm = PlateformAlarm.无消息; Marking.ProductResult = true; Marking.WorkIndex = 0; step = 0; Xaxis.Stop(); Yaxis.Stop(); Zaxis.Stop(); if (!Xaxis.IsAlarmed && !Yaxis.IsAlarmed) { Xaxis.IsServon = true; Yaxis.IsServon = true; Zaxis.IsServon = true; stationInitialize.Flow = 10; } break; case 10: //复位Z轴,真空 IoPoints.ApsController.BackHome(Zaxis.NoId); InhaleCylinder.InitExecute(); InhaleCylinder.Reset(); stationInitialize.Flow = 20; break; case 20: //判断所有气缸到位,启动Z轴回原点 if (InhaleCylinder.OutOriginStatus) { if (IoPoints.ApsController.CheckHomeDone(Zaxis.NoId, 10.0) == 0) { IoPoints.ApsController.BackHome(Xaxis.NoId); IoPoints.ApsController.BackHome(Yaxis.NoId); stationInitialize.Flow = 30; } else { Zaxis.Stop(); stationInitialize.InitializeDone = false;; stationInitialize.Flow = -1; } } break; case 30: //判断XY轴是否异常,为0,正常,为1:原点异常,为<0:故障 var resultX = IoPoints.ApsController.CheckHomeDone(Xaxis.NoId, 10.0); var resultY = IoPoints.ApsController.CheckHomeDone(Yaxis.NoId, 10.0); if (IoPoints.ApsController.CheckHomeDone(Xaxis.NoId, 10.0) == 0 && IoPoints.ApsController.CheckHomeDone(Yaxis.NoId, 10.0) == 0) { stationInitialize.InitializeDone = true; stationInitialize.Flow = 40; } else //异常处理 { stationInitialize.InitializeDone = false;; stationInitialize.Flow = -1; } break; default: break; } } #endregion //故障清除 if (externalSign.AlarmReset) { m_Alarm = PlateformAlarm.无消息; } } }
public Level4() { Console.WriteLine("Level4"); Reset(); timebarSpace = 10.768F; this.Add(new SpriteGameObject("spr_background")); thePlayer = new Player(2, 2); door = new Door(1, 0); xaxis = new Xaxis(8, "Map/spr_horizontal_art_blue"); yaxis = new Yaxis(13, "Map/spr_vertical_art_blue"); goal = new MainGoal(3, 13); Mouse.SetPosition(GameEnvironment.Screen.X / 2, GameEnvironment.Screen.Y / 2); floors = new GameObjectList(); walls = new GameObjectList(); goals = new GameObjectList(); inputScreen = new InputScreen(GameEnvironment.Screen.X / 2 - 64 * 2, GameEnvironment.Screen.Y); inputanswer = new InputAnswer(GameEnvironment.Screen.X / 2 - 64 * 2, GameEnvironment.Screen.Y); timeGround = new SpriteGameObject("Map/time_ground"); guards = new GameObjectList(); lasers = new GameObjectList(); times = new GameObjectList(); score = new Score(12, 20, (int)time); Axis_nums = new Axis_numbers(13, 8); switchBoards = new GameObjectList(); this.Add(floors); this.Add(switchBoards); this.Add(lasers); this.Add(walls); this.Add(door); this.Add(xaxis); this.Add(yaxis); this.Add(Axis_nums); this.Add(goal); this.Add(goals); this.Add(guards); this.Add(thePlayer); this.Add(inputScreen); this.Add(timeGround); this.Add(times); this.Add(score); this.Add(inputanswer); goals.Add(new ExtraGoal(7, 2)); goals.Add(new ExtraGoal(12, 2)); goals.Add(new ExtraGoal(22, 2)); goals.Add(new ExtraGoal(26, 2)); goals.Add(new ExtraGoal(27, 2)); goals.Add(new ExtraGoal(26, 3)); goals.Add(new ExtraGoal(27, 3)); goals.Add(new ExtraGoal(17, 8)); goals.Add(new ExtraGoal(9, 13)); goals.Add(new ExtraGoal(26, 13)); FloorSetup(); WallSetup(); TimeBarSetup(); SoundSetup(); lasers.Add(new Laser(new Vector2(21, 9), new Vector2(28, 6), Color.Red, xaxis.gridPos, yaxis.gridPos)); lasers.Add(new Laser(new Vector2(13, 10), new Vector2(19, 4), Color.Blue, xaxis.gridPos, yaxis.gridPos)); lasers.Add(new Laser(new Vector2(14, 12), new Vector2(26, 15), Color.Yellow, xaxis.gridPos, yaxis.gridPos)); lasers.Add(new Laser(new Vector2(7, 12), new Vector2(5, 15), Color.Purple, xaxis.gridPos, yaxis.gridPos)); lasers.Add(new Laser(new Vector2(1, 9), new Vector2(5, 11), Color.Green, xaxis.gridPos, yaxis.gridPos)); lasers.Add(new Laser(new Vector2(26, 5), new Vector2(28, 5), Color.DarkGray, xaxis.gridPos, yaxis.gridPos)); lasers.Add(new Laser(new Vector2(1, 5), new Vector2(6, 10), Color.Aqua, xaxis.gridPos, yaxis.gridPos)); switchBoards.Add(new SwitchBoard(15, 10, Color.Red)); switchBoards.Add(new SwitchBoard(6, 10, Color.Blue)); switchBoards.Add(new SwitchBoard(23, 10, Color.Yellow)); switchBoards.Add(new SwitchBoard(20, 11, Color.Purple)); switchBoards.Add(new SwitchBoard(10, 11, Color.Green)); switchBoards.Add(new SwitchBoard(17, 11, Color.DarkGray)); switchBoards.Add(new SwitchBoard(4, 4, Color.Aqua)); guards.Add(new Guard(new Vector2(2, 13), new Vector2(25, 13))); guards.Add(new Guard(new Vector2(26, 13), new Vector2(27, 1))); guards.Add(new Guard(new Vector2(5, 8), new Vector2(11, 2))); }