Esempio n. 1
0
  public void moveTo(float inputX) {
    if (controller == null) {
      error(String.format("%s's controller is not set", getName()));
      return;
    }

    // the magic mapping
    float outputY = calc(inputX);

    if (outputY > outputYMax || outputY < outputYMin) {
      if ((int) outputY == outputY) {
        warn(String.format("%s.moveTo(%d) out of range", getName(), (int) outputY));
      } else {
        warn(String.format("%s.moveTo(%f) out of range", getName(), outputY));
      }
      return;
    }

    // FIXME - currently their is no timerPosition
    // this could be gotten with 100 * outputY for some valid range
    log.info("servoWrite({})", outputY);
    controller.servoWrite(getName(), (int) outputY);
    lastActivityTime = System.currentTimeMillis();
    this.inputX = inputX;
  }
Esempio n. 2
0
  @Override
  public String getControllerName() {
    if (controller == null) {
      return null;
    }

    return controller.getName();
  }
Esempio n. 3
0
  public void setSpeed(Float speed) {
    if (speed == null) {
      return;
    }

    if (controller == null) {
      error("setSpeed - controller not set");
      return;
    }
    controller.setServoSpeed(getName(), speed);
  }
Esempio n. 4
0
  public boolean detach() {
    if (!isAttached) {
      log.info(String.format("%s.detach() - already detach - attach first", getName()));
      return false;
    }

    if (controller != null) {
      if (controller.servoDetach(getName())) {
        isAttached = false;
        // changed state
        broadcastState();
        return true;
      }
    }

    return false;
  }
Esempio n. 5
0
  /* (non-Javadoc)
   * @see org.myrobotlab.service.interfaces.ServoControl#attach()
   */
  public boolean attach() {
    lastActivityTime = System.currentTimeMillis();
    if (isAttached) {
      log.info(String.format("%s.attach() - already attached - detach first", getName()));
      return false;
    }

    if (controller == null) {
      error("no valid controller can not attach %s", getName());
      return false;
    }

    isAttached = controller.servoAttach(getName(), pin);

    if (isAttached) {
      // changed state
      broadcastState();
    }

    return isAttached;
  }
Esempio n. 6
0
 /* (non-Javadoc)
  * @see org.myrobotlab.service.interfaces.ServoControl#stopServo()
  */
 @Override
 public void stopServo() {
   controller.servoStop(getName());
 }