コード例 #1
0
  protected void moveMotor(
      final IProgressMonitor monitor, final IScannableMotor motor, final double newPosition)
      throws DeviceException, InterruptedException {

    double motorSpeed = motor.getSpeed();

    double position = (Double) motor.getPosition();

    double distance = Math.abs(position - newPosition);

    double timeInSeconds = distance / motorSpeed;

    logger.debug(String.format("Time to move %1$f is %2$f", distance, timeInSeconds));
    logger.debug(String.format("Speed of motor %1$s is %2$f", motor.getName(), motor.getSpeed()));
    motorsRunning.add(motor);

    motor.asynchronousMoveTo(newPosition);

    int totalTimeTakenInMills = (int) (timeInSeconds * 1000);

    final int step = totalTimeTakenInMills / 10000;

    SubMonitor progress =
        SubMonitor.convert(
            monitor,
            String.format("Moving %s from %.3g to %.3g", motor.getName(), position, newPosition),
            10000);
    int count = 0;
    while (motor.isBusy()) {
      Double currPos = (Double) motor.getPosition();
      progress.subTask(String.format("%s position: %.3g", motor.getName(), currPos));
      progress.worked(1);
      Sleep.sleep(step);
      count++;
      if (monitor.isCanceled()) {
        motor.stop();
        throw new InterruptedException("User Cancelled");
      }
    }
    logger.debug("Motor queried count is {}", count);
    motorsRunning.remove(motor);
  }
コード例 #2
0
 protected void stopAllMotors() throws DeviceException {
   for (IScannableMotor motor : motorsRunning) {
     motor.stop();
   }
   motorsRunning.clear();
 }