/// <summary> /// Applies a calibration to the lens. This scales the focal power based off the distance sensor reading according to a piecewise linear interpolant /// </summary> /// <param name="data">2D array of calibration data. Column 1 contains input voltage, column 2 contains output voltage</param> /// <param name="stage">Parent stage of the lens to indicate which lens to calibrate</param> /// <returns>True if calibration was valid</returns> public bool ApplyCalibration(double[,] data, RCCMStage stage) { int rows = data.GetLength(0); int cols = data.GetLength(1); // Data must be formatted into rows of input voltage - output voltage pairs if (cols != 2) { return(false); } // Get controller based on specified stage IController controller; if (stage == RCCMStage.RCCM1) { controller = this.NFOV1Controller; this.NFOV1Calibration = data; } else { controller = this.NFOV2Controller; this.NFOV2Calibration = data; } return(true); }
/// <summary> /// Get position of WFOV camera in specified coordinate system /// </summary> /// <param name="stage">Enum value corresponding to desired camera</param> /// <param name="sys">Enum value corresponding to desired coordinate system</param> /// <returns>PointF with X and Y coordinates of camera</returns> public PointF GetWFOVLocation(RCCMStage stage, CoordinateSystem sys) { PointF coarselocation = new PointF((float)this.motors["coarse X"].GetPos(), (float)this.motors["coarse Y"].GetPos()); double xOffset; double yOffset; if (stage == RCCMStage.RCCM1) { xOffset = this.WFOV1X + this.motors["fine 1 X"].GetPos(); yOffset = this.WFOV1Y + this.motors["fine 1 Y"].GetPos(); } else { xOffset = this.WFOV2X + this.motors["fine 2 X"].GetPos(); yOffset = this.WFOV2Y + this.motors["fine 2 Y"].GetPos(); } double xOffRotated = this.fineStageRotation[0, 0] * xOffset + this.fineStageRotation[0, 1] * yOffset; double yOffRotated = this.fineStageRotation[1, 0] * xOffset + this.fineStageRotation[1, 1] * yOffset; PointF globalPt = PointF.Add(coarselocation, new SizeF((float)xOffRotated, (float)yOffRotated)); switch (sys) { case CoordinateSystem.Local: return(this.GlobalVectorToPanelVector(this.motors["coarse X"].GetPos() + xOffRotated, this.motors["coarse Y"].GetPos() + yOffRotated)); default: return(globalPt); } }
/// <summary> /// Unpause autofocus loop for specified stage /// </summary> /// <param name="stage">Enum value corresponding to desired stage</param> public void ResumeFocusing(RCCMStage stage) { if (stage == RCCMStage.RCCM1) { this.readThread1Paused = false; } else { this.readThread2Paused = false; } }
/// <summary> /// Pause autofocus loop for specified stage /// </summary> /// <param name="stage">Enum value corresponding to desired stage</param> public void PauseFocusing(RCCMStage stage) { if (stage == RCCMStage.RCCM1) { this.readThread1Paused = true; } else { this.readThread2Paused = true; } }
/// <summary> /// Sends command to specified controller to set a constant focal power value /// </summary> /// <param name="power">Focal power to use, in diopters</param> /// <param name="stage">Stage indicating which controller to send the command to</param> /// <returns>True if command succeded</returns> public bool SetFocalPower(double power, RCCMStage stage) { IController controller = stage == RCCMStage.RCCM1 ? this.NFOV1Controller : this.NFOV2Controller; try { controller.SendCommand(string.Format("{0},{1}", NFOVLensController.SET_FOCALPOWER_CMD, power)); } catch { return(false); } return(true); }
/// <summary> /// Initialize NFOV display /// </summary> /// <param name="rccm">RCCMSystem object, needed for getting location and zoom status</param> /// <param name="camera">NFOV camera to display</param> /// <param name="cracks">List of cracks to display</param> public NFOVViewForm(RCCMSystem rccm, NFOV camera, ObservableCollection <MeasurementSequence> cracks) { this.rccm = rccm; this.camera = camera; this.stage = camera == rccm.NFOV1 ? RCCMStage.RCCM1 : RCCMStage.RCCM2; this.cameraName = camera == rccm.NFOV1 ? "nfov 1" : "nfov 2"; this.cracks = cracks; this.cracks.CollectionChanged += cracksChangedHandler; this.Drawing = false; this.ActiveIndex = -1; this.ActivePoint = -1; this.bwRepaint = new BackgroundWorker(); InitializeComponent(); this.editFocus.Value = (decimal)(camera == rccm.NFOV1 ? rccm.LensController.FocusOffset1 : rccm.LensController.FocusOffset2); this.updateMeasurementControls(); }
/// <summary> /// Get current height of specified NFOV /// </summary> /// <param name="stage">Enum value of desired stage</param> /// <returns>Current focal height in user units</returns> public double GetHeight(RCCMStage stage) { // Get controller based on specified stage IController controller = stage == RCCMStage.RCCM1 ? this.NFOV1Controller : this.NFOV2Controller; // Send get input command and pull reading from resulting string try { double input = this.GetReading(stage); return(stage == RCCMStage.RCCM1 ? this.ToHeight1(input) : this.ToHeight2(input)); } catch { return(-1); } }
/// <summary> /// Get current input voltage to distanc sensor of specified NFOV /// </summary> /// <param name="stage">Enum value of desired lens</param> /// <returns>Current input voltaget</returns> public double GetReading(RCCMStage stage) { // Get controller based on specified stage IController controller = stage == RCCMStage.RCCM1 ? this.NFOV1Controller : this.NFOV2Controller; // Send get input command and pull reading from resulting string try { string response = controller.SendCommand(NFOVLensController.GET_VOLTAGE_CMD); Match m = NFOVLensController.PARSE_GET.Match(response); // Convert reading to distance return((0.51 * Double.Parse(m.Value.Substring(2)) - 59.9) / 100.0); } catch { return(-1); } }
/// <summary> /// Create form and initialize given camera /// </summary> /// <param name="rccm">Reference to the RCCM object</param> /// <param name="camera">Camera to be displayed</param> /// <param name="cracks">Reference to the list of all measurement sequences</param> public WFOVViewForm(RCCMSystem rccm, WFOV camera, ObservableCollection <MeasurementSequence> cracks) { this.rccm = rccm; this.camera = camera; this.stage = this.camera == rccm.WFOV1 ? RCCMStage.RCCM1 : RCCMStage.RCCM2; this.cameraName = this.camera == rccm.WFOV1 ? "wfov 1" : "wfov 2"; this.cracks = cracks; this.cracks.CollectionChanged += cracksChangedHandler; this.Drawing = false; this.ActiveIndex = -1; this.ActivePoint = -1; InitializeComponent(); this.updateMeasurementControls(); this.panelWFOVOverlay = new WFOVPanel(this.wfovContainer); this.Controls.Add(this.panelWFOVOverlay); this.panelWFOVOverlay.BringToFront(); this.wfovRepaint = new System.Windows.Forms.Timer(); }
/// <summary> /// Get current focal power of specified NFOV lens /// </summary> /// <param name="stage">Enum value of desired lens</param> /// <returns>Current focal power output</returns> public double GetFocalPower(RCCMStage stage) { // Get controller based on specified stage IController controller = stage == RCCMStage.RCCM1 ? this.NFOV1Controller : this.NFOV2Controller; // Send get input command and pull reading from resulting string string response; try { response = controller.SendCommand(NFOVLensController.GET_STATUS_CMD); } catch { return(-10000); } Match m = NFOVLensController.PARSE_GETOUTPUT.Match(response.Substring(0, 1024)); // Convert reading to distance return(Double.Parse(m.Value.Substring(3))); }
/// <summary> /// Create a calibration UI form for the specified stage. Saves changes to specified settings object /// </summary> /// <param name="controller">NFOV lens controller</param> /// <param name="stage">Parent stage of NFOV camera to be adjusted</param> public LensCalibrationForm(RCCMSystem rccm, RCCMStage stage) { InitializeComponent(); this.rccm = rccm; this.controller = this.rccm.LensController; this.stage = stage; this.oldCalibration = stage == RCCMStage.RCCM1 ? this.controller.NFOV1Calibration : this.controller.NFOV2Calibration; this.calibration = new SortedList <double, CalibrationPoint>(); if (this.oldCalibration != null) { for (int i = 0; i < this.oldCalibration.GetLength(0); i++) { this.calibration.Add(this.oldCalibration[i, 0], new CalibrationPoint(this.oldCalibration[i, 0], this.oldCalibration[i, 1])); } } // Set text box values Motor zMotor = this.stage == RCCMStage.RCCM1 ? this.rccm.motors["fine 1 Z"] : this.rccm.motors["fine 2 Z"]; this.heightEdit.Value = (decimal)zMotor.GetPos(); this.focalPowerEdit.Value = (decimal)this.controller.GetFocalPower(this.stage); if (this.stage == RCCMStage.RCCM1) { this.editFocusOffset.Value = (decimal)this.controller.FocusOffset1; } else { this.editFocusOffset.Value = (decimal)this.controller.FocusOffset2; } this.updateListView(); this.controller.PauseFocusing(this.stage); }
/// <summary> /// Create a controlled z actuator /// </summary> /// <param name="controller">RCCM Trio controller object</param> /// <param name="axisNum">Number of port where axis is connected to Trio controller</param> /// <param name="rccm">The RCCM object</param> /// <param name="stage">Enum value of the set of fine actuators containing this actuator</param> public TrioStepperZMotor(TrioController controller, short axisNum, RCCMSystem rccm, RCCMStage stage) { this.controller = controller; this.axisNum = axisNum; this.Jogging = false; // Create height function reference from lens controller height property if (stage == RCCMStage.RCCM1) { this.height = delegate() { return(rccm.LensController.Height1); }; } else { this.height = delegate() { return(rccm.LensController.Height2); }; } // Create function reference that computes height of panel at current location this.minPosition = delegate() { PointF pos = rccm.GetNFOVLocation(stage, CoordinateSystem.Local); return(rccm.GetPanelDistance(pos.X, pos.Y)); }; this.commandHeight = this.height(); // Start background thread this.bw = new BackgroundWorker(); this.bw.DoWork += new DoWorkEventHandler(this.heightAdjustLoop); this.adjustThreadExited = new AutoResetEvent(false); this.adjust = true; this.adjustThreadPaused = false; this.bw.RunWorkerAsync(); }