de.jaetzold.art
Class AngleSensor

java.lang.Object
  |
  +--de.jaetzold.art.RawSensor
        |
        +--de.jaetzold.art.StateSensor
              |
              +--de.jaetzold.art.CountSensor
                    |
                    +--de.jaetzold.art.AngleSensor
All Implemented Interfaces:
EventListener, PropertyChangeListener, Sensor, SensorPeer

public class AngleSensor
extends CountSensor

A class for measuring an angle. This angle can be greater than 360 degree and is typically used for measuring the rotation-position of an axle. Negative Values are also possible. The method getValue() returns the angle measured in whole turns. For standard Fischertechnik and Lego an AngleSensor usually gets connected with a CountSensor because angles are measured by counting state-changes.


Inner classes inherited from class de.jaetzold.art.CountSensor
CountSensor.AbsoluteStateDifferenceStateDecider, CountSensor.CountSensorPort
 
Inner classes inherited from class de.jaetzold.art.RawSensor
RawSensor.ValueSensorPort
 
Field Summary
protected  double angleUnits
          The count-value is multiplied by angleUnits/angleUnitsFraction when computing the angle in whole turns.
protected  double angleUnitsFraction
          The count-value is multiplied by angleUnits/angleUnitsFraction when computing the angle in whole turns.
 
Fields inherited from class de.jaetzold.art.StateSensor
stateDecider
 
Fields inherited from class de.jaetzold.art.RawSensor
changes, precision, precisionSet, propertyChangeEventDescriptor
 
Constructor Summary
AngleSensor()
          Constructs an AngleSensor whithone count being one revolution.
AngleSensor(double unitsPerTurn)
          Constructs an AngleSensor whith a scale.
AngleSensor(double unitsPerTurn, double fraction)
          Constructs an AngleSensor whith a scale.
 
Method Summary
 int convertAngleToUnits(double angle)
          Converts an angle to a count-value according to its scale.
protected  double convertToOutgoing(double value)
          This is a Template-Method for subclasses.
 double convertUnitsToAngle(double units)
          Converts a count-value to an angle according to its scale.
 double getAngleDegree()
          Returns the angle relative to the starting-position.
 double getAngleRadians()
          Returns the angle relative to the starting-position.
 double getAngleTurns()
          Returns the angle relative to the starting-position.
 boolean getDeliversFloatingPoint()
          Tells whether this Sensor delivers discrete values or not.
 double getPrecision()
          Returns the maximum of the expectable error in the value.
 double getUnitsPerTurn()
          Returns the count-units that make one revolution.
 double[] getUnitsPerTurnFraction()
          Returns the count-units that make one revolution.
 void setAngle(double angle)
          Calibrates this Sensor to be at the given angle.
 void setUnitsPerTurn(double unitsPerTurn)
          Sets the Units in which this AngleSensor measures one turn.
 void setUnitsPerTurnFraction(double numerator, double denominator)
          Sets the Units in which this AngleSensor measures one turn.
 
Methods inherited from class de.jaetzold.art.CountSensor
connectWith, convertToIncoming, disconnect, getCountSensorPort, getCountValue, isIncomingConversionCacheable, resetCount, setCount, setCountDecider
 
Methods inherited from class de.jaetzold.art.StateSensor
getStateDecider, setStateDecider
 
Methods inherited from class de.jaetzold.art.RawSensor
addPropertyChangeListener, addSensorListener, addSensorListener, connectWith, disableEvent, enableEvent, getChangeEventsEnabled, getIncomingConversionDelegate, getIntValue, getOutgoingConversionDelegate, getPeer, getPeerCacheEnabled, getPort, getSensorPort, getValue, isConnected, isOutgoingConversionCacheable, isReversed, processEvent, propertyChange, removePropertyChangeListener, removeSensorListener, removeSensorListener, setChangeEventsEnabled, setIncomingConversionDelegate, setOutgoingConversionDelegate, setPeerCacheEnabled, setPrecision, setReversed, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

angleUnits

protected double angleUnits
The count-value is multiplied by angleUnits/angleUnitsFraction when computing the angle in whole turns.

angleUnitsFraction

protected double angleUnitsFraction
The count-value is multiplied by angleUnits/angleUnitsFraction when computing the angle in whole turns.
Constructor Detail

AngleSensor

public AngleSensor()
Constructs an AngleSensor whithone count being one revolution.

AngleSensor

public AngleSensor(double unitsPerTurn)
Constructs an AngleSensor whith a scale. The scale is unitsPerTurn counts making up one revolution.

AngleSensor

public AngleSensor(double unitsPerTurn,
                   double fraction)
Constructs an AngleSensor whith a scale. The scale is unitsPerTurn/fraction counts making up one revolution.
Method Detail

convertUnitsToAngle

public double convertUnitsToAngle(double units)
Converts a count-value to an angle according to its scale.

convertAngleToUnits

public int convertAngleToUnits(double angle)
Converts an angle to a count-value according to its scale.

convertToOutgoing

protected double convertToOutgoing(double value)
Description copied from class: RawSensor
This is a Template-Method for subclasses. It converts the internal value into the value which this sensor represents to the outside. It is called when the Sensor is asked for its value or sends a SensorEvent. Because this Method also calls the outgoingConversionDelegate (if one exists) it should not be overridden without calling super.
Overrides:
convertToOutgoing in class RawSensor
Following copied from class: de.jaetzold.art.RawSensor
See Also:
RawSensor.convertToIncoming(double), RawSensor.isOutgoingConversionCacheable()

setAngle

public void setAngle(double angle)
Calibrates this Sensor to be at the given angle.
See Also:
CountSensor.setCount(double)

getAngleTurns

public double getAngleTurns()
Returns the angle relative to the starting-position. The angle is computed as whole turns of 360 degree and a fraction of them (2*PI radians = 360 degree = 1 turn).

getAngleRadians

public double getAngleRadians()
Returns the angle relative to the starting-position. The angle is measured in radians (2*PI radians = 360 degree = 1 turn).

getAngleDegree

public double getAngleDegree()
Returns the angle relative to the starting-position. The angle is measured in degrees (2*PI radians = 360 degree = 1 turn).

setUnitsPerTurn

public void setUnitsPerTurn(double unitsPerTurn)
Sets the Units in which this AngleSensor measures one turn. If the actual hardware-sensor for the angle is implemented by counting some changes in a state (e.g. standard LEGO or Fischertechnik), it would be best, to set this value equal to (or to a multiple of) the number of state-changes making a whole turn of 360 degree. If the hardware-sensor is implemented by some device which instead measures the angle in some analog form, the angleUnits value is also used to tell this Sensor which value makes up one revolution. But since it is more likely in this case, that one revolution is not measured by a whole number, it might be necessary to use another method: setCountsPerTurnFraction(double, double). It is actually possible to set countsPerTurn to a negative value, but that would have the same effect as reversing the sensors value and is therefore not encouraged.
See Also:
RawSensor.setReversed(boolean), setUnitsPerTurnFraction(double,double)

getUnitsPerTurn

public double getUnitsPerTurn()
Returns the count-units that make one revolution.
See Also:
setUnitsPerTurn(double)

setUnitsPerTurnFraction

public void setUnitsPerTurnFraction(double numerator,
                                    double denominator)
Sets the Units in which this AngleSensor measures one turn. This method can set angleUnit sometimes more intuitively and precisely.
See Also:
setUnitsPerTurn(double)

getUnitsPerTurnFraction

public double[] getUnitsPerTurnFraction()
Returns the count-units that make one revolution. The value is returned as an array of double with the numerator at position 0 and the denominator at position 1.
See Also:
getUnitsPerTurn()

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

getDeliversFloatingPoint

public boolean getDeliversFloatingPoint()
Description copied from class: RawSensor
Tells whether this Sensor delivers discrete values or not. A result of false means that the result of a getValue() can be cast to int without a loss of precision. The result of this method is only valid as long as no one of the conversion delegates changes.
Overrides:
getDeliversFloatingPoint in class CountSensor
Following copied from class: de.jaetzold.art.RawSensor
See Also:
RawSensor.convertToIncoming(double), RawSensor.setIncomingConversionDelegate(Conversion), RawSensor.setOutgoingConversionDelegate(Conversion)