de.jaetzold.art
Interface Sensor

All Superinterfaces:
EventListener, PropertyChangeListener
All Known Subinterfaces:
Actuator
All Known Implementing Classes:
RawSensor

public interface Sensor
extends PropertyChangeListener

Classes that represent an input-device should implement this interface. Implementations of this interface represent specific interpretations of the value this Sensor delivers.


Method Summary
 void addPropertyChangeListener(PropertyChangeListener l)
          A PropertyChangeListener receives PropertyChangeEvents whenever this Sensor receives a SensorEvent.
 void addSensorListener(SensorListener listener)
          Adds the specified SensorListener to this Sensor so that it receives SensorEvents from it.
 void connectWith(Port port)
          Connects the Sensor with the given Port.
 void disconnect()
          Disconnects this Sensor from it's Peer and it's Port.
 int getIntValue()
          Returns the value this Sensor represents as an int.
 Port getPort()
          Returns the Port to which this Sensor is connected.
 double getPrecision()
          Returns the maximum of the expectable error in the value.
 SensorPort getSensorPort()
          Returns a Port through which other Sensors can be connected to this Sensor.
 double getValue()
          Returns the value this Sensor represents as a double.
 boolean isConnected()
          Tells wether this Sensor has a Peer and whether the Peer is also connected.
 void processEvent(SensorEvent event)
          This Method is called when the value this Sensor resembles has changed and events are enabled.
 void propertyChange(PropertyChangeEvent event)
          This is the method through which a Sensor gets informed about changes in the hardware-value it resembles.
 void removePropertyChangeListener(PropertyChangeListener l)
          Remove the specified listener.
 void removeSensorListener(SensorListener listener)
          Removes the specified SensorListener so that it no longer receives SensorEvents from this Sensor.
 void update()
          Causes a new SensorEvent for this Sensor to be generated and delivered.
 

Method Detail

getIntValue

public int getIntValue()
Returns the value this Sensor represents as an int. This method is only for convenience. Better use getValue() because this method may involve casting with a loss of precision.
See Also:
getValue()

getValue

public double getValue()
Returns the value this Sensor represents as a double.

connectWith

public void connectWith(Port port)
Connects the Sensor with the given Port. The Sensor gets its peer from the Port so it is therefore required before the Sensor can be properly used.
See Also:
SensorPort

isConnected

public boolean isConnected()
Tells wether this Sensor has a Peer and whether the Peer is also connected. For example a Peer can be not connected if it is a Peer that only forwards calls to another Peer and that one is not connected or if the RobotInterface this Peer belongs to is not connected.
See Also:
SensorPeer.isConnected(), RobotInterface.isConnected(), connectWith(Port)

disconnect

public void disconnect()
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.
See Also:
connectWith(Port)

addSensorListener

public void addSensorListener(SensorListener listener)
Adds the specified SensorListener to this Sensor so that it receives SensorEvents from it. The Events are sent whenever a change in the value is detected but are also allowed to be sent when no change happened.
See Also:
removeSensorListener(SensorListener), SensorListener.processEvent(SensorEvent)

removeSensorListener

public void removeSensorListener(SensorListener listener)
Removes the specified SensorListener so that it no longer receives SensorEvents from this Sensor. This method performs no function, nor does it throw an exception, if the listener specified by the argument was not previously added to this Sensor. If listener is null, no exception is thrown and no action is performed.
See Also:
addSensorListener(SensorListener), SensorListener.processEvent(SensorEvent)

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener l)
A PropertyChangeListener receives PropertyChangeEvents whenever this Sensor receives a SensorEvent. The PropertyChangeEvent has the SensorEvent as it's new value and the last SensorEvent as the old value. The property name used for this is value. This mechanism in the Sensor is not really used for anything else right now but may be in future releases.
See Also:
addSensorListener(SensorListener), SensorListener.processEvent(SensorEvent)

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener l)
Remove the specified listener.
See Also:
addPropertyChangeListener(PropertyChangeListener)

propertyChange

public void propertyChange(PropertyChangeEvent event)
This is the method through which a Sensor gets informed about changes in the hardware-value it resembles. The internal value of this sensor is set to the new value and a SensorEvent is generated with this Sensor as the source. This new SensorEvent is then passed to processEvent(SensorEvent).
Specified by:
propertyChange in interface PropertyChangeListener
See Also:
processEvent(SensorEvent)

processEvent

public void processEvent(SensorEvent event)
This Method is called when the value this Sensor resembles has changed and events are enabled. The given SensorEvent is then passed to any registered listeners, the SensorListeners as well as the PropertyChangeListeners. Unlike propertyChange(PropertyChangeEvent) this method is not interested in the new value but in the SensorEvent which resembles the change.
See Also:
propertyChange(java.beans.PropertyChangeEvent)

getSensorPort

public SensorPort getSensorPort()
Returns a Port through which other Sensors can be connected to this Sensor. This way Sensor-Objects can be cascaded. A Sensor which is connected to the SensorPort returned by this method gets a Peer which represents the value of the Sensor the SensorPort came from. Events are also forwarded. Note the difference between getSensorPort() and getPort().
See Also:
getPort()

getPort

public Port getPort()
Returns the Port to which this Sensor is connected. Note the difference between getSensorPort() and getPort().
See Also:
getPort()

update

public void update()
Causes a new SensorEvent for this Sensor to be generated and delivered. This Event is delivered by the usual Thread which delivers the Events. If this is not the case it is at least a different Thread than the one calling this method.
See Also:
processEvent(SensorEvent), SensorPeer.update(), SensorEvent

getPrecision

public double getPrecision()
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.