/** * Add a Servo the ServoController. * @param config Servo's configuration parameters */ public void addServo(ServoConf config){ myConfig.addServoConfig(config); }
@Override protected ServoConfig<Id> newServoConfig( Id id, String name, int minPos, int maxPos, int defPos) { return new DefaultServoConfig<MaestroServo.Id>( id, name, minPos, maxPos, defPos); }
/** * Sets the Servo name. * @param name new Servo name */ @Override public void setName(String name){ String oldName = myName; myName = name; firePropertyChange(ServoConfig.PROP_NAME, oldName, name); }
/** * Returns the absolute goal position as used by the ServoController. * @return the absolute goal position as used by the ServoController */ public Integer getAbsoluteGoalPosition(){ if(myGoalPosition == null){ return null; } double goal = myGoalPosition.getValue(); double range = myConfig.getMaxPosition() - myConfig.getMinPosition(); return (int)(goal*range + myConfig.getMinPosition()); }
public OpenServo( ServoConfig<OpenServo.Id> config, OpenServoController controller){ super(config, controller); myEnabledFlag = false; double range = myConfig.getMaxPosition() - myConfig.getMinPosition(); double defVal = myConfig.getDefaultPosition() - myConfig.getMinPosition(); double def = defVal/range; myDefaultPosition = new NormalizedDouble(def); }
@Override public String getName() { return myConfig.getName(); }
@Override public int getMinPosition() { return myConfig.getMinPosition(); }
@Override public int getMaxPosition() { return myConfig.getMaxPosition(); }
@Override protected void run(PropertyChangeEvent event) { ServoConf config = (ServoConf)event.getNewValue(); removingServo(servoId(config.getServoId())); } });
/** * Sets the Servo default position. * @param pos new Servo default position */ @Override public void setDefaultPosition(Integer pos){ if(pos == null){ throw new NullPointerException("Cannot set null position."); } checkAbsPosition(pos); Integer oldPos = myDefaultPosition; myDefaultPosition = pos; firePropertyChange(ServoConfig.PROP_DEF_POSITION, oldPos, pos); }
/** * Creates a new ServoConfig with the given parameters. * @param servoId The Servo's Id with respect to the ServoController * @param name Servo name (used for display purposes) * @param minPos minimum position in absolute terms for the ServoController * @param maxPos maximum position in absolute terms for the ServoController * @param defPos default position in absolute terms for the ServoController */ public DefaultServoConfig(Id servoId, String name, int minPos, int maxPos, int defPos){ myServoId = servoId; myName = name; myMinPosition = minPos; myMaxPosition = maxPos; checkAbsPosition(defPos); myDefaultPosition = defPos; }
/** * Remove a Servo from the ServoController. * @param servo Servo to remove */ public void removeServo(S servo){ myConfig.removeServoConfig(servo.getConfig()); }
@Override public Integer getValue() { double min = myServo.getConfig().getMinPosition(); double max = myServo.getConfig().getMaxPosition(); NormalizedDouble val = myServo.getCurrentPosition(); if(val == null){ return null; } double cur = val.getValue(); double range = max - min; cur = cur*range + min; return (int)cur; }
@Override protected ServoConfig<OpenServo.Id> newServoConfig( OpenServo.Id id, String name, int minPos, int maxPos, int defPos) { return new DefaultServoConfig<OpenServo.Id>( id, name, minPos, maxPos, defPos); }
/** * Sets the Servo minimum position. * @param pos new Servo minimum position */ @Override public void setMinPosition(Integer pos){ if(pos == null){ throw new NullPointerException("Cannot set null position."); } Integer oldPos = myMinPosition; myMinPosition = pos; firePropertyChange(ServoConfig.PROP_MIN_POSITION, oldPos, pos); }
@Override public Integer getValue() { double min = myServo.getConfig().getMinPosition(); double max = myServo.getConfig().getMaxPosition(); NormalizedDouble val = myServo.getCurrentPosition(); if(val == null){ return null; } double cur = val.getValue(); double range = max - min; cur = cur*range + min; return (int)cur; }
@Override protected ServoConfig<DynamixelServo.Id> newServoConfig( Id id, String name, int minPos, int maxPos, int defPos) { return new DefaultServoConfig<DynamixelServo.Id>( id, name, minPos, maxPos, defPos); }
/** * Sets the Servo id. * @param id new Servo id */ @Override public void setServoId(Id id){ if(id == null){ throw new NullPointerException("Cannot set null Servo id."); } Id oldId = myServoId; myServoId = id; firePropertyChange(ServoConfig.PROP_ID, oldId, id); }
@Override public Integer getValue() { double min = myServo.getConfig().getMinPosition(); double max = myServo.getConfig().getMaxPosition(); NormalizedDouble val = myServo.getGoalPosition(); if(val == null){ return null; } double cur = val.getValue(); double range = max - min; cur = cur*range + min; return (int)cur; }
/** * Sets the Servo maximum position. * @param pos new Servo maximum position */ @Override public void setMaxPosition(Integer pos){ if(pos == null){ throw new NullPointerException("Cannot set null position."); } Integer oldPos = myMaxPosition; myMaxPosition = pos; firePropertyChange(ServoConfig.PROP_MAX_POSITION, oldPos, pos); }