de.jaetzold.art
Class StepperMotor

java.lang.Object
  |
  +--de.jaetzold.art.RawSensor
        |
        +--de.jaetzold.art.RawActuator
              |
              +--de.jaetzold.art.Motor
                    |
                    +--de.jaetzold.art.StepperMotor
All Implemented Interfaces:
Actuator, EventListener, PropertyChangeListener, Sensor, SensorPeer
Direct Known Subclasses:
Servo

public class StepperMotor
extends Motor

This class is an abstraction of a stepper motor. A stepper motor is able to control the amount of movement it does, it can "make one step" at a time. How big such a step is is not defined, but they are equal in size. That way a StepperMotor is positionable in a relative sort of fashion.

It should be noted that the getValue()-method of StepperMotor doesn't return the position of the motor, but it's state (exactly as Motor does). So keep especially in mind, that getValue() usually doesn't return what has been previously set with setValue(). To retrieve the position use the CountSensor delivered by getCountSensor().

Calls to methods from Motor like on() or forward() stop any positioning of the StepperMotor and let it move freely. It still keeps track of the current position then.

If a Port can't deliver a real StepperMotorPeer this class is able to simulate the required behavior by using a CountSensor and the capabilities of its superclass Motor.

See Also:
getCountSensor(), StepperMotorPeer, CountSensor

Inner classes inherited from class de.jaetzold.art.RawSensor
RawSensor.ValueSensorPort
 
Field Summary
protected  CountSensor countSensor
          The CountSensor representing the position of this StepperMotor.
protected  double desiredCount
          The position the StepperMotor currently wants to be at.
 
Fields inherited from class de.jaetzold.art.Motor
backward, on, power
 
Fields inherited from class de.jaetzold.art.RawActuator
localReturn, vetos, waitForCompletion
 
Fields inherited from class de.jaetzold.art.RawSensor
changes, precision, precisionSet, propertyChangeEventDescriptor
 
Constructor Summary
StepperMotor()
          Constructs a new StepperMotor.
StepperMotor(CountSensor sensor)
          Constructs a new StepperMotor.
 
Method Summary
 void calibrate()
          This method is called when (re)calibration is required.
 void connectWith(ActuatorPort port)
          Connects this Object with the given Port.
 void disconnect()
          Disconnects this Sensor from it's Peer and it's Port.
 CountSensor getCountSensor()
          Returns the CountSensor representing the position of this StepperMotor.
 BooleanSensor getPositionReachedSensor()
          Returns a BooleanSensor that represents the positioning-state of this StepperMotor.
 double getPrecision()
          Returns the maximum of the expectable error in the value.
 double getSpeed()
          Returns the speed of this StepperMotor.
 boolean isPositionedAt(double count)
          Tells whether this StepperMotor is currently at the position given by count.
 void keepCurrentPosition()
          Sets the current position as the desired position.
 void setBackward(boolean backward)
          Controls whether the output should reverse its default polarity.
 void setCountSensor(CountSensor sensor)
          Sets the CountSensor for representing the position of this StepperMotor.
 void setOn(boolean on)
          Turns the motor on or of depending on the given value.
 void setPrecision(double precision)
          Sets the local value for precision.
 void setSpeed(double speed)
          Sets the speed of this StepperMotor to the given value.
 void setValue(double value)
          Sets the position the StepperMotor currently wants to be at.
 void step(double value)
          Move relatively from the currently desired position a number of steps given by value.
 
Methods inherited from class de.jaetzold.art.Motor
backward, forward, getBackward, getPower, isOn, off, on, reverse, setPower
 
Methods inherited from class de.jaetzold.art.RawActuator
addVetoableChangeListener, connectWith, convertToActuatorIncoming, convertToActuatorOutgoing, getActuatorIncomingConversionDelegate, getActuatorOutgoingConversionDelegate, getLocalReturn, getValue, getWaitForCompletion, removeVetoableChangeListener, setActuatorIncomingConversionDelegate, setActuatorOutgoingConversionDelegate, setLocalReturn, setReversed, setValue, setWaitForCompletion
 
Methods inherited from class de.jaetzold.art.RawSensor
addPropertyChangeListener, addSensorListener, addSensorListener, connectWith, convertToIncoming, convertToOutgoing, disableEvent, enableEvent, getChangeEventsEnabled, getDeliversFloatingPoint, getIncomingConversionDelegate, getIntValue, getOutgoingConversionDelegate, getPeer, getPeerCacheEnabled, getPort, getSensorPort, isConnected, isIncomingConversionCacheable, isOutgoingConversionCacheable, isReversed, processEvent, propertyChange, removePropertyChangeListener, removeSensorListener, removeSensorListener, setChangeEventsEnabled, setIncomingConversionDelegate, setOutgoingConversionDelegate, setPeerCacheEnabled, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.jaetzold.art.Sensor
addPropertyChangeListener, addSensorListener, connectWith, getIntValue, getPort, getSensorPort, isConnected, processEvent, propertyChange, removePropertyChangeListener, removeSensorListener, update
 

Field Detail

countSensor

protected CountSensor countSensor
The CountSensor representing the position of this StepperMotor. It may be the one used for simulating the step-behavior or the one directly from the StepperMotorPeer.

desiredCount

protected double desiredCount
The position the StepperMotor currently wants to be at.
See Also:
step(double), setValue(double)
Constructor Detail

StepperMotor

public StepperMotor()
Constructs a new StepperMotor. It is not specified whether it will have a StepperMotorPeer or an explicit CountSensor to use in simulating the step-behavior.

StepperMotor

public StepperMotor(CountSensor sensor)
Constructs a new StepperMotor. The given CountSensor is used to simulate the step-behavior.
Method Detail

getCountSensor

public CountSensor getCountSensor()
Returns the CountSensor representing the position of this StepperMotor. It may be the one used for simulating the step-behavior or the one directly from the StepperMotorPeer. Keep in mind that it is possible that this StepperMotor gets a new Peer in which case the CountSensor returned by this method may not be valid anymore for this StepperMotor. It is possible that future versions don't have this limitation.
See Also:
setCountSensor(CountSensor)

setCountSensor

public void setCountSensor(CountSensor sensor)
Sets the CountSensor for representing the position of this StepperMotor. It is not required to set the CountSensor when using a StepperMotor as long as it has a StepperMotorPeer. Otherwise the given CountSensor is used to simulate the step-behavior.
See Also:
StepperMotorPeer.getCountSensor()

getPositionReachedSensor

public BooleanSensor getPositionReachedSensor()
Returns a BooleanSensor that represents the positioning-state of this StepperMotor. If the StepperMotor is correctly positioned (within its precision) the BooleanSensor is true, otherwise false. Listeners may be added to the BooleanSensor which then get informed whenever that state changes.
See Also:
getPrecision(), isPositionedAt(double)

setPrecision

public void setPrecision(double precision)
Description copied from class: RawSensor
Sets the local value for precision. This is not required because usually the precision is taken from the peer. However it may be useful to tune the value for precision according to the algorithm which will use this Sensor.
Overrides:
setPrecision in class RawSensor
Following copied from class: de.jaetzold.art.RawSensor
See Also:
RawSensor.precisionSet, RawSensor.setPrecision(double)

getPrecision

public double getPrecision()
Description copied from interface: Sensor
Returns the maximum of the expectable error in the value. This is just a guess, what means that nothing really important should depend on it. It is meant to give an algorithm using this Sensor an idea of how precise the value is so that it either can refuse to use it or try to compensate if necessary.
Overrides:
getPrecision in class RawSensor

isPositionedAt

public boolean isPositionedAt(double count)
Tells whether this StepperMotor is currently at the position given by count. The precision is taken into account.
See Also:
getPositionReachedSensor()

setBackward

public void setBackward(boolean backward)
Description copied from class: Motor
Controls whether the output should reverse its default polarity. Dependig on the value of waitMode this Method returns immediately after it has been registerd that this is now the state the motor should have, or it returns after the state has been set.
Overrides:
setBackward in class Motor
Following copied from class: de.jaetzold.art.Motor
See Also:
RawActuator.waitForCompletion

setOn

public void setOn(boolean on)
Description copied from class: Motor
Turns the motor on or of depending on the given value. Dependig on the value of waitMode this Method returns immediately after it has been registerd that this is now the state the motor should have, or it returns after the state has been set.
Overrides:
setOn in class Motor
Following copied from class: de.jaetzold.art.Motor
See Also:
RawActuator.waitForCompletion

keepCurrentPosition

public void keepCurrentPosition()
Sets the current position as the desired position. This way the StepperMotor stops and holds the current position.

calibrate

public void calibrate()
This method is called when (re)calibration is required. This may take a while. It is called implicitly when initializing with a new Peer.

step

public void step(double value)
Move relatively from the currently desired position a number of steps given by value.
See Also:
setValue(double)

setValue

public void setValue(double value)
Sets the position the StepperMotor currently wants to be at. That means it repositions itself as long as the value of it's CountSensor does not match value in terms of precision. A call to Motor-specific methods like forward() stops the positioning until the next call to setValue(double), step(double) or calibrate().
Overrides:
setValue in class Motor
See Also:
step(double), desiredCount

connectWith

public void connectWith(ActuatorPort port)
Description copied from class: Motor
Connects this Object with the given Port. This sets the peer for this Object and is therefore required before it can be properly used.
Overrides:
connectWith in class Motor

disconnect

public void disconnect()
Description copied from interface: Sensor
Disconnects this Sensor from it's Peer and it's Port. This is implicitly called when the Sensor is already connected and asked to connect with another Port.
Overrides:
disconnect in class Motor
Following copied from interface: de.jaetzold.art.Sensor
See Also:
Sensor.connectWith(Port)

getSpeed

public double getSpeed()
Returns the speed of this StepperMotor. This implementation of StepperMotor does not really control the Speed by itself. If it is not connected to a StepperMotorPeer speed has the same effect as power.
See Also:
Motor.getPower()

setSpeed

public void setSpeed(double speed)
Sets the speed of this StepperMotor to the given value. This often has an effect to the torque of the motor. In fact, this implementation of StepperMotor does not control the speed by itself. If it is not connected to a StepperMotorPeer it just forwards any call to setSpeed(double) to setPower(double). Dependig on the value of waitForCompletion this Method returns immediately after it has been registerd that this is now the state the motor should have, or it returns after the state has been set.
See Also:
Motor.setPower(double), RawActuator.waitForCompletion