Class ScannableMotionBase

All Implemented Interfaces:
INeXusInfoWriteable, Device, Scannable, ScannableMotion, Configurable, Findable, gda.observable.IObservable
Direct Known Subclasses:
CVScan, CVScan, DummyControlPoint, DummyScannable, EpicsControlPoint, JythonScannableWrapper, MonoMoveWithOffsetScannable, ScannableMotionUnitsBase, ScannableMotionWithScannableFieldsBase, TemperatureBase

public class ScannableMotionBase extends ScannableBase implements ScannableMotion, INeXusInfoWriteable
A base implementation for a ScannableMotion Device.
  • Field Details

    • numberTries

      protected int numberTries
    • tolerance

      protected Double[] tolerance
      Array of tolerance values. Used by the isAt() method. Can be set manually via setTolerance or setTolerances.
  • Constructor Details

    • ScannableMotionBase

      public ScannableMotionBase()
  • Method Details

    • asynchronousMoveTo

      public void asynchronousMoveTo(Object externalPosition) throws DeviceException
      Description copied from class: ScannableBase
      Trigger a move/operation and return immediately. Implementations of this method should be non-blocking to allow concurrent motion; the isBusy method will be used to determine when the move has completed. Converts the external (user) position to an internal position and passes this to rawAsynchronousMoveTo.
      Specified by:
      asynchronousMoveTo in interface Scannable
      Overrides:
      asynchronousMoveTo in class ScannableBase
      Parameters:
      externalPosition - Position to move to should have an element for each input field.
      Throws:
      DeviceException
    • setLimitsComponent

      public void setLimitsComponent(ScannableLimitsComponent limitsComponent)
      Sets the limits component used by this object.
      Parameters:
      limitsComponent - the limits component
    • getLimitsComponent

      public ScannableLimitsComponent getLimitsComponent()
    • setOffsetAndScalingComponent

      public void setOffsetAndScalingComponent(ScannableOffsetAndScalingComponent offsetAndScalingComponent)
    • 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 ScannableBase
      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 ScannableBase
      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.
    • isBusy

      public boolean isBusy() throws DeviceException
      Check if the Scannable is moving/operating.. Calls onto rawIsBusy for historical reasons, although there is currently no need for this.
      Specified by:
      isBusy in interface Scannable
      Returns:
      true - if operation carried out by moveTo has not completed yet
      Throws:
      DeviceException
      See Also:
    • rawIsBusy

      @Deprecated(since="at least 2012") public boolean rawIsBusy() throws DeviceException
      Deprecated.
      Should be implemented by inheriting classes
      Returns:
      true if busy and last action started by asynchronousMoveTo not completed yet
      Throws:
      DeviceException
      See Also:
    • moveTo

      public void moveTo(Object position) throws DeviceException
      If the numberTries and tolerance attributes have been set then repeatedly tries to move this Scannable until the position is within the tolerance range.
      Specified by:
      moveTo in interface Scannable
      Overrides:
      moveTo in class ScannableBase
      Parameters:
      position -
      Throws:
      DeviceException
      See Also:
    • a

      public void a(Object position) throws DeviceException
      Quick-to-type version of asynchronousMoveTo for use in Jython environment
      Specified by:
      a in interface ScannableMotion
      Parameters:
      position -
      Throws:
      DeviceException
    • r

      public void r(Object amount) throws DeviceException
      Quick-to-type version of a relative move for use in Jython environment
      Specified by:
      r in interface ScannableMotion
      Parameters:
      amount -
      Throws:
      DeviceException
    • ar

      public void ar(Object amount) throws DeviceException
      Quick-to-type version of an asynchronous relative move for use in Jython environment
      Specified by:
      ar in interface ScannableMotion
      Parameters:
      amount -
      Throws:
      DeviceException
    • checkPositionValid

      public String checkPositionValid(Object externalPosition) throws DeviceException
      Checks the position against the Scannable's limits and against any additional position validators added with additionalPositionValidators().
      Specified by:
      checkPositionValid in interface Scannable
      Overrides:
      checkPositionValid in class ScannableBase
      Parameters:
      externalPosition -
      Returns:
      null if position is valid, or returns a description if not.
      Throws:
      DeviceException
      See Also:
    • checkPositionWithinGdaLimits

      @Deprecated(since="at least 2012") public String checkPositionWithinGdaLimits(Double[] externalPosition)
      Deprecated.
      Description copied from interface: ScannableMotion
      Returns null if okay, or a descriptive error if not. Code only called if limits are set.
      Specified by:
      checkPositionWithinGdaLimits in interface ScannableMotion
      Parameters:
      externalPosition - position in external representation
      Returns:
      null if okay, or a descriptive error if not
    • checkPositionWithinGdaLimits

      @Deprecated(since="at least 2012") public String checkPositionWithinGdaLimits(Object externalPosition)
      Deprecated.
      Description copied from interface: ScannableMotion
      Returns null if okay, or a descriptive error if not. Code only called if limits are set.
      Specified by:
      checkPositionWithinGdaLimits in interface ScannableMotion
      Parameters:
      externalPosition - position in external representation
      Returns:
      null or description of any error
    • getLowerGdaLimits

      public Double[] getLowerGdaLimits()
      Description copied from interface: ScannableMotion
      Get lower Scannable limits in external representation. Will be null if no lower limits are set. Otherwise, any element can be null indicating that the corresponding field has no limit.
      Specified by:
      getLowerGdaLimits in interface ScannableMotion
      Returns:
      Double[] limit in external representation
    • getUpperGdaLimits

      public Double[] getUpperGdaLimits()
      Description copied from interface: ScannableMotion
      Get upper Scannable limits in external representation
      Specified by:
      getUpperGdaLimits in interface ScannableMotion
      Returns:
      Double[] limit in external representation
    • setLowerGdaLimits

      public void setLowerGdaLimits(Double[] externalLowerLim) throws Exception
      Description copied from interface: ScannableMotion
      Set lower Scannable limits in external representation. Setting the input null will remove lower limits from the Scannable. Otherwise, any element can be null indicating that the corresponding field has no limit.
      Specified by:
      setLowerGdaLimits in interface ScannableMotion
      Parameters:
      externalLowerLim - limit in external representation
      Throws:
      Exception
    • setUpperGdaLimits

      public void setUpperGdaLimits(Double[] externalUpperLim) throws Exception
      Description copied from interface: ScannableMotion
      Set upper Scannable limits in external representation. Setting the input null will remove upper limits from the Scannable. Otherwise, any element can be null indicating that the corresponding field has no limit.
      Specified by:
      setUpperGdaLimits in interface ScannableMotion
      Parameters:
      externalUpperLim - limit in external representation
      Throws:
      Exception
    • setLowerGdaLimits

      public void setLowerGdaLimits(Double lowerLim) throws Exception
      Description copied from interface: ScannableMotion
      Set lower Scannable limit in external representation. Setting the input null will remove the lower limit from the Scannable.
      Specified by:
      setLowerGdaLimits in interface ScannableMotion
      Parameters:
      lowerLim - limit in external representation
      Throws:
      Exception
    • setUpperGdaLimits

      public void setUpperGdaLimits(Double upperLim) throws Exception
      Description copied from interface: ScannableMotion
      Set upper Scannable limit in external representation. Setting the input null will remove the upper limit from the Scannable.
      Specified by:
      setUpperGdaLimits in interface ScannableMotion
      Parameters:
      upperLim - limit in external representation
      Throws:
      Exception
    • getNumberTries

      public int getNumberTries()
      Description copied from interface: ScannableMotion
      This is the number of times the Scannable should attempt to move to the target position. Useful when the underlying hardware is problematic and often fails or ignores calls without throwing an exception. This should be used in conjunction with setting the tolerance attribute.
      Specified by:
      getNumberTries in interface ScannableMotion
      Returns:
      the numberTries
      See Also:
    • setNumberTries

      public void setNumberTries(int numberTries)
      Specified by:
      setNumberTries in interface ScannableMotion
      Parameters:
      numberTries - the numberTries to set
      See Also:
    • isAt

      public boolean isAt(Object positionToTest) throws DeviceException
      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 ScannableBase
      Parameters:
      positionToTest - The position to compare the scannable's position to.
      Returns:
      true if scannable is at positionToTest
      Throws:
      DeviceException
      See Also:
    • setTolerances

      public void setTolerances(Double[] tolerance) throws DeviceException
      WARNING: This method will not work with units.

      Specified by:
      setTolerances in interface ScannableMotion
      Parameters:
      tolerance -
      Throws:
      DeviceException
    • setTolerance

      public void setTolerance(Double tolerence) throws DeviceException
      Specified by:
      setTolerance in interface ScannableMotion
      Parameters:
      tolerence -
      Throws:
      DeviceException
      See Also:
    • getTolerances

      public Double[] getTolerances() throws DeviceException
      WARNING: This method will not work with units.

      Specified by:
      getTolerances in interface ScannableMotion
      Returns:
      double[]
      Throws:
      DeviceException
      See Also:
    • writeNeXusInformation

      public void writeNeXusInformation(NexusFile file, Node node) throws NexusException
      Specified by:
      writeNeXusInformation in interface INeXusInfoWriteable
      Parameters:
      file - nexus file handle
      node -
      Throws:
      NexusException
    • writeNeXusInformationLimits

      protected void writeNeXusInformationLimits(NexusFile file, GroupNode group) throws NexusException
      Throws:
      NexusException
    • getInputLimits

      public static Double[] getInputLimits(ScannableMotion sm, int input)
    • getAttribute

      public Object getAttribute(String attributeName) throws DeviceException
      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 DeviceBase
      Parameters:
      attributeName - is the name of the attribute
      Returns:
      the value of the attribute as an Object type
      Throws:
      DeviceException
      See Also:
    • getInputLimits

      public Double[] getInputLimits(int index)
    • getFirstInputLimits

      public Double[] getFirstInputLimits() throws DeviceException
      Throws:
      DeviceException
    • completeInstantiation

      protected void completeInstantiation() throws InstantiationException
      This method should be called at the end of an inheriting class's constructor.

      It will do things such as validate that the class instantiated was valid, register the scannable with other objects and generally complete the instantiation of the object.

      Throws:
      InstantiationException
    • 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
    • getScalingFactor

      public Double[] getScalingFactor()
      Description copied from interface: ScannableMotion
      Returns scaling factor(s) as Doubles. May be null, or any element may be null, indicating no scale is to be applied/removed.
      Specified by:
      getScalingFactor in interface ScannableMotion
    • setOffset

      public void setOffset(Double... offsetArray)
      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
      Parameters:
      offsetArray - must match number of input fields.
    • setScalingFactor

      public void setScalingFactor(Double... scaleArray)
      Description copied from interface: ScannableMotion
      Set scaling factor(s) as Doubles. May be null, or any element may be null, indicating no scale is to be applied/removed.
      Specified by:
      setScalingFactor in interface ScannableMotion
      Parameters:
      scaleArray - must match number of input fields.
    • addPositionValidator

      public void addPositionValidator(PositionValidator validator)
    • removePositionValidator

      public void removePositionValidator(PositionValidator validator)
      Throws:
      IllegalArgumentException - if validator is null
    • setAdditionalPositionValidators

      public void setAdditionalPositionValidators(Set<PositionValidator> additionalPositionValidators)
    • getAdditionalPositionValidators

      public Set<PositionValidator> getAdditionalPositionValidators()
    • 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 ScannableBase
      Returns:
      string as defined above
    • generateScannableLimitsReport

      protected String generateScannableLimitsReport()