private void cmbPostionList_SelectionChanged(object sender, SelectionChangedEventArgs e) { ViewMassMove view = DataContext as ViewMassMove; if (cmbPostionList.SelectedIndex == 0) { // read current position btnSave.IsEnabled = true; btnDelete.IsEnabled = false; btnMove.IsEnabled = false; btnStop.IsEnabled = false; for (int i = 0; i < view.AxisControlCollection.Count; i++) { Axis4MassMove _axis_view = view.AxisControlCollection[i]; LogicalAxis _log_axis = view.MotionComponent.LogicalAxisCollection[i]; _axis_view.Position = _log_axis.PhysicalAxisInst.UnitHelper.RelPosition; _axis_view.IsAbsMode = _log_axis.PhysicalAxisInst.IsAbsMode; _axis_view.Speed = 100; } } else { // load the saved position btnSave.IsEnabled = true; btnDelete.IsEnabled = true; btnMove.IsEnabled = true; btnStop.IsEnabled = true; } }
/// <summary> /// Move the specified axis with specified args /// </summary> /// <param name="Axis"></param> /// <param name="Args"></param> public async void MoveLogicalAxis(LogicalAxis Axis, MoveByDistanceArgs Args) { if (GetSystemState() != SystemState.BUSY) { SetSystemState(SystemState.BUSY); this.LastMessage = new MessageItem(MessageType.Normal, "{0} Move with argument {1}{2} ...", Axis, Args, Axis.PhysicalAxisInst.UnitHelper.Unit); var t = new Task <bool>(() => { return(Axis.PhysicalAxisInst.Move(Args.Mode, Args.Speed, Args.Distance)); }); t.Start(); bool ret = await t; if (ret == false) { this.LastMessage = new MessageItem(MessageType.Error, "{0} Unable to move, {1}", Axis, Axis.PhysicalAxisInst.LastError); PostErrorMessageToFrontEnd(this.LastMessage.Message); } else { this.LastMessage = new MessageItem(MessageType.Normal, "{0} Move is completed, the final position is {1}/{2}{3}", new object[] { Axis, Axis.PhysicalAxisInst.AbsPosition, Axis.PhysicalAxisInst.UnitHelper.AbsPosition, Axis.PhysicalAxisInst.UnitHelper.Unit }); } SetSystemState(SystemState.IDLE); } else { this.LastMessage = new MessageItem(MessageType.Warning, "System is busy"); } }
/// <summary> /// Bind the physical axis to the logical aligner /// </summary> /// <param name="ParentAligner">which logical aligner belongs to</param> /// <param name="Axis"></param> /// <returns></returns> bool BindPhysicalAxis(LogicalAxis Axis) { bool ret = false; // find the physical motion controller by the device class if (this.PhysicalMotionControllerCollection.ContainsKey(Axis.Config.DeviceClass)) { // find the axis in the specified controller by the axis name // and bind the physical axis to the logical axis Axis.PhysicalAxisInst = this.PhysicalMotionControllerCollection[Axis.Config.DeviceClass].FindAxisByName(Axis.Config.AxisName); if (Axis.PhysicalAxisInst == null) // if the physical axis was not found { // Create a fake physical axis instance to tell UI this axis is disabled Axis.PhysicalAxisInst = new AxisBase(-1, null, null); this.LastMessage = new MessageItem(MessageType.Error, "{0} bind physical axis error, unable to find the axis", Axis); ret = false; } else { ret = true; } } else // the controller with the specified DevClass does not exist { // Create a fake physical axis instance to tell UI this axis is disabled Axis.PhysicalAxisInst = new AxisBase(-1, null, null); this.LastMessage = new MessageItem(MessageType.Error, "{0} bind physical axis error, unable to find the controller DevClass *{1}*", Axis, Axis.Config.DeviceClass); ret = false; } return(ret); }
public SystemService() { ThreadPool.SetMinThreads(50, 50); // read version from AssemblyInfo.cs Version version = Assembly.GetExecutingAssembly().GetName().Version; // force to enable the log, otherwise the initial message could not be recored LogHelper.LogEnabled = true; StringBuilder sb = new StringBuilder(); sb.Append("\r\n"); sb.Append("> =================================================================\r\n"); sb.Append("> = 4x25G/10x10G Alignment System =\r\n"); sb.Append("> = Copyright (C) 2017 Irixi =\r\n"); sb.Append("> =================================================================\r\n"); LogHelper.WriteLine(sb.ToString()); this.LastMessage = new MessageItem(MessageType.Normal, "System startup ..."); this.LastMessage = new MessageItem(MessageType.Normal, "Application Version {0}", version); // read the configuration from the file named SystemCfg.json // the file is located in \Configuration ConfigManager conf_manager = SimpleIoc.Default.GetInstance <ConfigManager>(); // whether output the log LogHelper.LogEnabled = conf_manager.ConfSystemSetting.LogEnabled; // initialize the properties BusyComponents = new List <IServiceSystem>(); PhysicalMotionControllerCollection = new Dictionary <Guid, IMotionController>(); LogicalAxisCollection = new ObservableCollection <LogicalAxis>(); LogicalMotionComponentCollection = new ObservableCollection <LogicalMotionComponent>(); MeasurementInstrumentCollection = new ObservableCollection <InstrumentBase>(); ActiveInstrumentCollection = new ObservableCollection <InstrumentBase>(); State = SystemState.BUSY; SpiralScanArgs = new SpiralScanArgs(); AlignmentXDArgs = new AlignmentXDArgs(); /* * enumerate all physical motion controllers defined in the config file, * and create the instance of the motion controller class. */ foreach (var conf in conf_manager.ConfSystemSetting.PhysicalMotionControllers) { IMotionController motion_controller = null; switch (conf.Model) { case MotionControllerModel.LUMINOS_P6A: motion_controller = new LuminosP6A(conf); motion_controller.OnMoveBegin += PhysicalMotionController_OnMoveBegin; motion_controller.OnMoveEnd += PhysicalMotionController_OnMoveEnd; break; case MotionControllerModel.THORLABS_TDC001: //TODO create the instance of thorlabs TDC001 break; case MotionControllerModel.IRIXI_EE0017: motion_controller = new IrixiEE0017(conf); motion_controller.OnMoveBegin += PhysicalMotionController_OnMoveBegin; motion_controller.OnMoveEnd += PhysicalMotionController_OnMoveEnd; ((IrixiEE0017)motion_controller).OnMessageReported += ((sender, message) => { Application.Current.Dispatcher.Invoke(() => { this.LastMessage = new MessageItem(MessageType.Normal, string.Format("{0} {1}", sender, message)); }); }); break; default: this.LastMessage = new MessageItem(MessageType.Error, "Unrecognized controller model {0}.", conf.Model); break; } // Add the controller to the dictionary<Guid, Controller> if (motion_controller != null) { this.PhysicalMotionControllerCollection.Add(motion_controller.DeviceClass, motion_controller); } } // create the instance of the Logical Motion Components foreach (var cfg_motion_comp in conf_manager.ConfSystemSetting.LogicalMotionComponents) { LogicalMotionComponent comp = new LogicalMotionComponent(cfg_motion_comp.Caption, cfg_motion_comp.Icon); int axis_id = 0; foreach (var cfg_axis in cfg_motion_comp.LogicalAxisArray) { // new logical axis object will be added to the Logical Motion Component LogicalAxis axis = new LogicalAxis(this, cfg_axis, cfg_motion_comp.Caption, axis_id); axis.OnHomeRequsted += LogicalAxis_OnHomeRequsted; axis.OnMoveRequsted += LogicalAxis_OnMoveRequsted; axis.OnStopRequsted += LogicalAxis_OnStopRequsted; // bind the physical axis instance to logical axis object BindPhysicalAxis(axis); comp.LogicalAxisCollection.Add(axis); this.LogicalAxisCollection.Add(axis); axis_id++; } this.LogicalMotionComponentCollection.Add(comp); } // create the instance of the cylinder try { IrixiEE0017 ctrl = PhysicalMotionControllerCollection[Guid.Parse(conf_manager.ConfSystemSetting.Cylinder.Port)] as IrixiEE0017; CylinderController = new CylinderController(conf_manager.ConfSystemSetting.Cylinder, ctrl); } catch (Exception e) { this.LastMessage = new MessageItem(MessageType.Error, "Unable to initialize the cylinder controller, {0}", e.Message); } // create instance of the keithley 2400 foreach (var cfg in conf_manager.ConfSystemSetting.Keithley2400s) { this.MeasurementInstrumentCollection.Add(new Keithley2400(cfg)); } // create instance of the newport 2832C foreach (var cfg in conf_manager.ConfSystemSetting.Newport2832Cs) { this.MeasurementInstrumentCollection.Add(new Newport2832C(cfg)); } }
public override void Start() { base.Start(); Args.ScanCurveGroup.ClearCurvesContent(); double hDir = 1; double hMoved = 0, vMoved = 0; LogicalAxis hAxis = Args.Axis, vAxis = Args.Axis2; do { #region Horizontal Scan do { // read indensity var indensity = Args.Instrument.Fetch(); // draw curve Args.ScanCurve.Add(new Point3D(hMoved, vMoved, indensity)); // move along the horizontal direction hAxis.PhysicalAxisInst.Move(MoveMode.REL, Args.MoveSpeed, hDir * Args.ScanInterval); // cancel the alignment process if (cts_token.IsCancellationRequested) { break; } if (hDir > 0) { hMoved += Args.ScanInterval; if (hMoved >= Args.AxisRestriction) { break; } } else { hMoved -= Args.ScanInterval; if (hMoved <= 0) { break; } } } while (true); // cancel the alignment process if (cts_token.IsCancellationRequested) { return; } #endregion // check if the vertical position is out of the restriction if (vMoved < Args.Axis2Restriction) { // change the direction of the next horizontal scan hDir *= -1; // move along the vertical direction vAxis.PhysicalAxisInst.Move(MoveMode.REL, Args.MoveSpeed, Args.ScanInterval); vMoved += Args.ScanInterval; } else { break; } } while (true); var maxPoint = Args.ScanCurve.FindMaximalPosition3D(); var lastPoint = Args.ScanCurve.Last(); var last_x = lastPoint.X; var last_y = lastPoint.Y; var max_x = maxPoint.X; var max_y = maxPoint.Y; hAxis.PhysicalAxisInst.Move(MoveMode.REL, Args.MoveSpeed, -(last_x - max_x)); vAxis.PhysicalAxisInst.Move(MoveMode.REL, Args.MoveSpeed, -(last_y - max_y)); }
public override void Start() { base.Start(); int state = 0; LogicalAxis activeAxis = Args.Axis; double restriction = Args.HorizonalRange, interval = Args.HorizonalInterval; double moved = 0; AddLog("Start to align ..."); try { PauseInstruments(); _align: // reset arguments Args.ScanCurveGroup.ClearCurvesContent(); moved = 0; // move to the start point if (activeAxis.PhysicalAxisInst.Move(MoveMode.REL, Args.MoveSpeed, -(restriction / 2)) == false) { throw new InvalidOperationException(activeAxis.PhysicalAxisInst.LastError); } do { // start to scan var indensity = Args.Instrument.Fetch(); var indensity2 = Args.Instrument2.Fetch(); Args.ScanCurve.Add(new Point2D(moved, indensity)); Args.ScanCurve2.Add(new Point2D(moved, indensity2)); if (moved < restriction) { // move the interval activeAxis.PhysicalAxisInst.Move(MoveMode.REL, Args.MoveSpeed, interval); moved += interval; } else { break; } // cancel the alignment process if (cts_token.IsCancellationRequested) { AddLog($"{this} is stopped by user!"); return; } } while (true); var maxPos = Args.ScanCurve.FindPositionWithMaxIntensity(); var maxPos2 = Args.ScanCurve2.FindPositionWithMaxIntensity(); var diffPos = maxPos.X - maxPos2.X; // return to the position with maximum indensity var returnToPos = maxPos.X - diffPos / 2; // output messages var unitHelper = activeAxis.PhysicalAxisInst.UnitHelper; AddLog($"Position with Max Intensity: ({maxPos.X.ToString("F1")}{unitHelper}, {maxPos.Y.ToString("F3")}), ({maxPos2.X.ToString("F1")}{unitHelper}, {maxPos2.Y.ToString("F3")})"); AddLog($"ΔPosition: {diffPos.ToString("F1")}{activeAxis}"); AddLog($"Middle of ΔPosition: {returnToPos.ToString("F1")}{unitHelper}"); if (activeAxis.PhysicalAxisInst.Move(MoveMode.REL, Args.MoveSpeed, -(moved - returnToPos)) == false) { throw new InvalidOperationException(activeAxis.PhysicalAxisInst.LastError); } // switch to the next axis to scan if (state < 1) { state++; activeAxis = Args.Axis2; restriction = Args.VerticalRange; Task.Delay(500); goto _align; } AddLog($"{this} has done!"); } catch (Exception ex) { AddLog($"{ex.Message}"); throw ex; } finally { ResumeInstruments(); } }
public override void Start() { base.Start(); int state = 0; ADCSamplingPointMissException pointsMissedEx = null; LogicalAxis activeAxis = Args.Axis; var range = Args.HorizonalRange; var interval = Args.HorizonalInterval; double moved = 0; AddLog($"Start to align ..."); _align: // reset arguments Args.ScanCurveGroup.ClearCurvesContent(); moved = 0; // move to the start point if (activeAxis.PhysicalAxisInst.Move(MoveMode.REL, Args.MoveSpeed, -(range / 2)) == false) { throw new InvalidOperationException(activeAxis.PhysicalAxisInst.LastError); } var axis = activeAxis.PhysicalAxisInst as IrixiM12Axis; var m12 = axis.Parent as IrixiM12; List <Point2D> points = null; List <Point2D> points2 = null; try { m12.StartFast1D(axis, range, interval, Args.MoveSpeed, ADCChannels.CH3, out points, ADCChannels.CH4, out points2); } catch (ADCSamplingPointMissException ex) { pointsMissedEx = ex; } // convert position from step to distance. for (int i = 0; i < points.Count; i++) { points[i].X = axis.UnitHelper.ConvertStepsToDistance((int)points[i].X); points2[i].X = axis.UnitHelper.ConvertStepsToDistance((int)points2[i].X); } Args.ScanCurve.AddRange(points); Args.ScanCurve2.AddRange(points2); var maxPos = Args.ScanCurve.FindPositionWithMaxIntensity(); var maxPos2 = Args.ScanCurve2.FindPositionWithMaxIntensity(); var diffPos = maxPos.X - maxPos2.X; // return to the position with maximum indensity var returnToPos = maxPos.X - diffPos / 2; // output messages var unitHelper = activeAxis.PhysicalAxisInst.UnitHelper; AddLog($"Max Intensity Position: ({maxPos.X.ToString("F1")}{unitHelper}, {maxPos.Y.ToString("F3")}), ({maxPos2.X.ToString("F1")}{unitHelper}, {maxPos2.Y.ToString("F3")})"); AddLog($"ΔPosition: {diffPos.ToString("F1")}{activeAxis}"); AddLog($"Middle of ΔPosition: {returnToPos.ToString("F1")}{unitHelper}"); if (activeAxis.PhysicalAxisInst.Move(MoveMode.REL, Args.MoveSpeed, -(moved - returnToPos)) == false) { throw new InvalidOperationException(activeAxis.PhysicalAxisInst.LastError); } // switch to the next axis to scan if (state < 1) { state++; activeAxis = Args.Axis2; range = Args.VerticalRange; Task.Delay(500); goto _align; } AddLog($"Done! {(DateTime.Now - alignStarts).TotalSeconds.ToString("F1")}s costs."); }
public override void Start() { base.Start(); int state = 0; LogicalAxis activeAxis = Args.Axis; double restriction = Args.AxisRestriction, interval = Args.ScanIntervalHorizontal; double moved = 0; Args.Log.Add(string.Format(">>> Start to align ...")); _align: // reset arguments Args.ScanCurveGroup.ClearCurvesContent(); moved = 0; // move to the start point if (activeAxis.PhysicalAxisInst.Move(MoveMode.REL, Args.MoveSpeed, -(restriction / 2)) == false) { throw new InvalidOperationException(activeAxis.PhysicalAxisInst.LastError); } do { // start to scan var indensity = Args.Instrument.Fetch(); var indensity2 = Args.Instrument2.Fetch(); Args.ScanCurve.Add(new Point(moved, indensity)); Args.ScanCurve2.Add(new Point(moved, indensity2)); if (moved < restriction) { // move the interval activeAxis.PhysicalAxisInst.Move(MoveMode.REL, Args.MoveSpeed, interval); moved += interval; } else { break; } // cancel the alignment process if (cts_token.IsCancellationRequested) { Args.Log.Add(string.Format("{0} is stopped by user!", this.ToString())); return; } } while (true); var maxPos = Args.ScanCurve.FindMaximalPosition(); var maxPos2 = Args.ScanCurve2.FindMaximalPosition(); var diffPos = maxPos.X - maxPos2.X; // return to the position with maximum indensity var returnToPos = maxPos.X - diffPos / 2; // output messages Args.Log.Add(string.Format(" Position of max power: ({0}{4}, {1})/({2}{4}, {3})", new object[] { maxPos.X, maxPos.Y, maxPos2.X, maxPos2.Y, activeAxis.PhysicalAxisInst.UnitHelper })); Args.Log.Add(string.Format(" ΔPosition: {0}{1}", diffPos, activeAxis)); Args.Log.Add(string.Format(" Middle of ΔPosition: {0}{1}", returnToPos, activeAxis.PhysicalAxisInst.UnitHelper)); if (activeAxis.PhysicalAxisInst.Move(MoveMode.REL, Args.MoveSpeed, -(moved - returnToPos)) == false) { throw new InvalidOperationException(activeAxis.PhysicalAxisInst.LastError); } // switch to the next axis to scan if (state < 1) { state++; activeAxis = Args.Axis2; restriction = Args.Axis2Restriction; Task.Delay(500); goto _align; } Args.Log.Add(string.Format("{0} is done!", this)); }