/** * Sets the position of specified stage to the specified value using appropriate core calls * * @param devKey * @param dir * @param pos new position of the stage * @param ignoreErrors true will return without any errors (or any action) if device is missing */ public boolean setPosition( Devices.Keys devKey, Joystick.Directions dir, double pos, boolean ignoreErrors) { try { if (ignoreErrors && !devices_.isValidMMDevice(devKey)) { return false; } String mmDevice = devices_.getMMDeviceException(devKey); if (devices_.is1DStage(devKey)) { core_.setPosition(mmDevice, pos); } else if (devices_.isXYStage(devKey)) { if (dir == Joystick.Directions.X) { // would prefer setXPosition but it doesn't exist so we stop any Y motion double ypos = core_.getYPosition(mmDevice); core_.setXYPosition(mmDevice, pos, ypos); } else if (dir == Joystick.Directions.Y) { double xpos = core_.getXPosition(mmDevice); // would prefer setYPosition but it doesn't exist so we stop any X motion core_.setXYPosition(mmDevice, xpos, pos); } } else if (devices_.isGalvo(devKey)) { Point2D.Double pos2D = core_.getGalvoPosition(mmDevice); if (dir == Joystick.Directions.X) { core_.setGalvoPosition(mmDevice, pos, pos2D.y); } else if (dir == Joystick.Directions.Y) { core_.setGalvoPosition(mmDevice, pos2D.x, pos); } } return true; } catch (Exception ex) { MyDialogUtils.showError(ex); return false; } }
/** * Returns the current position of the specified stage, or 0 if the stage wasn't found. Updates * the cache with the value as well. * * @param devKey * @param dir * @return */ public double getUpdatedPosition(Devices.Keys devKey, Joystick.Directions dir) { String mmDevice = devices_.getMMDevice(devKey); if (mmDevice == null) { return 0; } try { if (devices_.is1DStage(devKey)) { double pt = core_.getPosition(mmDevice); oneAxisDrivePositions_.put(devKey, pt); return pt; } Point2D.Double pt; if (devices_.isXYStage(devKey)) { pt = core_.getXYStagePosition(mmDevice); } else if (devices_.isGalvo(devKey)) { pt = core_.getGalvoPosition(mmDevice); } else { pt = new Point2D.Double(); } twoAxisDrivePositions_.put(devKey, pt); if (dir == Joystick.Directions.X) { return pt.x; } else if (dir == Joystick.Directions.Y) { return pt.y; } } catch (Exception ex) { MyDialogUtils.showError(ex); } return 0; }
private void refreshTwoAxisStagePositions() { for (Devices.Keys devKey : Devices.STAGES2D) { String mmDevice = devices_.getMMDevice(devKey); if (mmDevice == null) { // skip devices not set in devices tab twoAxisDrivePositions_.put(devKey, null); continue; } Point2D.Double pt; try { if (devices_.isXYStage(devKey)) { pt = core_.getXYStagePosition(mmDevice); } else if (devices_.isGalvo(devKey)) { pt = core_.getGalvoPosition(mmDevice); } else { pt = new Point2D.Double(); } twoAxisDrivePositions_.put(devKey, pt); } catch (Exception ex) { ReportingUtils.logMessage("Problem getting position of " + mmDevice); } } }
/** * Sets the relative position of specified stage to the specified value using appropriate core * calls * * @param devKey * @param dir * @param pos new position of the stage */ public void setPositionRelative(Devices.Keys devKey, Joystick.Directions dir, double delta) { try { String mmDevice = devices_.getMMDeviceException(devKey); if (devices_.is1DStage(devKey)) { core_.setRelativePosition(mmDevice, delta); } else if (devices_.isXYStage(devKey)) { if (dir == Joystick.Directions.X) { core_.setRelativeXYPosition(mmDevice, delta, 0); } else if (dir == Joystick.Directions.Y) { core_.setRelativeXYPosition(mmDevice, 0, delta); } } else if (devices_.isGalvo(devKey)) { Point2D.Double pos2D = core_.getGalvoPosition(mmDevice); if (dir == Joystick.Directions.X) { core_.setGalvoPosition(mmDevice, pos2D.x + delta, pos2D.y); } else if (dir == Joystick.Directions.Y) { core_.setGalvoPosition(mmDevice, pos2D.x, pos2D.y + delta); } } } catch (Exception ex) { MyDialogUtils.showError(ex); } }