Class ScannableMotionUnitsBase

All Implemented Interfaces:
INeXusInfoWriteable, Device, Scannable, ScannableMotion, ScannableMotionUnits, Configurable, Findable, gda.observable.IObservable
Direct Known Subclasses:
BeamlineWavelength, BeamSize, BeforeAfterScannable, BeforeAfterScannables, BeforeCheckScannable, ConvertorScannable, CoupledScannable, DeferredScannable, DummyContinuouslyScannable, DummyMultiFieldUnitsScannable, DummyRealPositionReader, DummyUnitsScannable, EpicsScannable, GapControlCheckingEnergyController, I18SampleFocusScannable, KeyenceLightScannable, MultiPVScannable, QexafsTestingScannable, SampleXYZAxis, ScannableMotionUnitsObservableWrapper, ScannableMotionWithScannableFieldsBase.ScannableField, ScannableMotor, ScannableRotatingGonio, TwoJawSlitPosition, VmxmJacksPiezoScannable, XESEnergyScannable, XesSpectrometerScannableBase

public abstract class ScannableMotionUnitsBase extends ScannableMotionBase implements ScannableMotionUnits
A base implementation for a ScannableMotionUnits Device.

The position passed to asynchronousMoveTo and returned by getPosition will be in the external (user) representation. getPosition will return the amount of the the Scannable's position Quantity in external (user) units as a Double (or array of Doubles). See UnitsComponent.internalTowardExternal(Object). getPositionQuantity will return the position as a quantity in external (user) units. asynchronousMoveTo asynchronousMoveTo will accept a Quantity that is compatible with the internal (hardware) unit. A String will be parsed into quantity. Otherwise it will take will take anything that ScannableMotionBase's will take (except an arbitrary String). See UnitsComponent.externalTowardInternal(Object)

As units are important, then the objects probably are representing hardware, so the isPositionValid method should be implemented.

By default the hardware and user units are the dimensionless ONE. The hardware and user unit cannot be configured to be incompatible.

  • Field Details

    • unitsComponent

      protected UnitsComponent<? extends javax.measure.Quantity<?>> unitsComponent
  • Constructor Details

    • ScannableMotionUnitsBase

      public ScannableMotionUnitsBase()
  • Method Details

    • internalToExternal

      public Object internalToExternal(Object internalPosition)
      Description copied from class: ScannableBase
      Converts a position in its internal representation to its external representation.

      Verifies that the object (represented as an array) has the same number of fields as the scannable.

      Overrides:
      internalToExternal in class ScannableMotionBase
      Parameters:
      internalPosition -
      Returns:
      an object array if the scannable has multiple fields, otherwise an object.
    • externalToInternal

      public Object externalToInternal(Object externalPosition)
      Description copied from class: ScannableBase
      Converts a position in its external representation to its internal representation.

      Verifies that the object (represented as an array) has the same number of fields as the scannable has input fields, or the total number of fields of the scannable. The later allows scripts to provide the output of getPosition to moveTo methods, e.g. "pos scannable_with_extra_fields scannable_with_extra_fields()".

      Overrides:
      externalToInternal in class ScannableMotionBase
      Parameters:
      externalPosition - an object array if the Scannable has multiple input fields, otherwise an object. The length must match the number of the Scannables input fields.
      Returns:
      an object array if the Scannable has multiple input fields, otherwise an object. The length will match the number of the Scannables input fields.
    • isAt

      public boolean isAt(Object externalPosition) throws DeviceException
      Description copied from class: ScannableMotionBase
      Tests if the scannable is at (or if appropriate, close to) the value positionToTest. If positionToTest is a string (as will be the case for valves or pneumatics for example), this is compared to the value obtained from getPosition(). An exception is thrown if this is not also a string.

      Otherwise if positionToTest is not a string the object is compared to the value from getPosition(), after having first pushed both values through objectToArray() from ScannableUtils.

      This behaviour should be extended where possible, and has been in ScannableMotionBase If positionToTest is a string (as will be the case for valves or pneumatics for example), this is compared to the value obtained from getPosition(). An exception is thrown if this is not also a string.

      Otherwise if positionToTest is not a string the object is compared to the value from getPosition() to see if they are within the tolerance specified in the scannable's tolerance array. Both values are first converted to arrays using objectToArray() from ScannableUtils.

      Specified by:
      isAt in interface Scannable
      Overrides:
      isAt in class ScannableMotionBase
      Parameters:
      externalPosition - The position to compare the scannable's position to.
      Returns:
      true if scannable is at positionToTest
      Throws:
      DeviceException
      See Also:
    • getAttribute

      public Object getAttribute(String attributeName) throws DeviceException
      Description copied from class: ScannableMotionBase
      Get the value of the specified attribute To distributed some of the extra methods in the ScannableMotion interface
      Specified by:
      getAttribute in interface Device
      Overrides:
      getAttribute in class ScannableMotionBase
      Parameters:
      attributeName - is the name of the attribute
      Returns:
      the value of the attribute as an Object type
      Throws:
      DeviceException
      See Also:
    • getUserUnits

      public String getUserUnits()
      Description copied from interface: ScannableMotionUnits
      Returns a string representation of the current reporting units
      Specified by:
      getUserUnits in interface ScannableMotionUnits
      Returns:
      Returns the reportingUnitsString.
    • setUserUnits

      public void setUserUnits(String userUnitsString) throws DeviceException
      Description copied from interface: ScannableMotionUnits
      Sets the user unit to userUnitString. If a hardware unit has not been explicitly set, then the hardware unit is also set to userUnitString. If a hardware unit has been set, and the userUnit is not compatible with this, then a DeviceException is thrown.
      Specified by:
      setUserUnits in interface ScannableMotionUnits
      Parameters:
      userUnitsString - The reportingUnitsString to set.
      Throws:
      DeviceException - if string not found in list of acceptable units
    • getHardwareUnitString

      public String getHardwareUnitString()
      Specified by:
      getHardwareUnitString in interface ScannableMotionUnits
      Returns:
      Returns the motorUnitString.
    • setHardwareUnitString

      public void setHardwareUnitString(String hardwareUnitString) throws DeviceException
      Description copied from interface: ScannableMotionUnits
      Sets the hardware unit to hardwareUnitString. If a user unit has not been explicitly set then the user unit is also set to hardwareUnitString. If the user unit has been explicitly set and the new hardware unit would invalidate this then a DeviceException is thrown.

      Based on this string, this method will build a list of acceptable user-units. Afterwards, the acceptable units list can be added to via the addAcceptableUnits method if the defaults do not cover enough.

      Specified by:
      setHardwareUnitString in interface ScannableMotionUnits
      Parameters:
      hardwareUnitString - The motorUnitString to set.
      Throws:
      DeviceException
    • getAcceptableUnits

      public String[] getAcceptableUnits()
      Specified by:
      getAcceptableUnits in interface ScannableMotionUnits
      Returns:
      Returns the acceptableUnitStrings.
    • addAcceptableUnit

      public void addAcceptableUnit(String newUnit) throws DeviceException
      Description copied from interface: ScannableMotionUnits
      Adds a new unit to the list of acceptable units based on the supllied string
      Specified by:
      addAcceptableUnit in interface ScannableMotionUnits
      Parameters:
      newUnit - - string representation of the new acceptable unit
      Throws:
      DeviceException
    • getInitialUserUnits

      public String getInitialUserUnits()
      Returns:
      Returns the initialUserUnits.
    • setInitialUserUnits

      public void setInitialUserUnits(String initialUserUnits) throws DeviceException
      Sets the initial user units.
      Throws:
      DeviceException
    • toFormattedString

      public String toFormattedString()
      Description copied from interface: Scannable
      Returns a string representation of the Scannable and its current position/value/status

      Typically should return:

      name : position

      or for detectors, name : status

      If the position/status cannot be determined, the function should return Scannable.VALUE_UNAVAILABLE in its place.

      Specified by:
      toFormattedString in interface Scannable
      Overrides:
      toFormattedString in class ScannableMotionBase
      Returns:
      string as defined above
    • getOffset

      public Double[] getOffset()
      Description copied from interface: ScannableMotion
      Returns offset(s) in amounts of external quantities. May be null, or any element may be null, indicating no offset is to be applied/removed.
      Specified by:
      getOffset in interface ScannableMotion
      Overrides:
      getOffset in class ScannableMotionBase
    • setOffset

      public void setOffset(Double... offsetAmountsInExternalUnits)
      Description copied from interface: ScannableMotion
      Set offset(s) in amounts of external quantities. May be null, or any element may be null, indicating no offset is to be applied/removed.
      Specified by:
      setOffset in interface ScannableMotion
      Overrides:
      setOffset in class ScannableMotionBase
      Parameters:
      offsetAmountsInExternalUnits - must match number of input fields.
    • setOffset

      public void setOffset(Object offsetPositionInExternalUnits)
      Description copied from interface: ScannableMotionUnits
      Set offset(s) in amounts of external quantities as ScannableMotion.setOffset(Double...), but allows any position container containing objects that may be quantities. ScannableMotion.setOffset(Double...)
      Specified by:
      setOffset in interface ScannableMotionUnits
      Parameters:
      offsetPositionInExternalUnits -