Class RCXRotationSensor

    • Field Detail

      • ONE_ROTATION

        public static final int ONE_ROTATION
        The incremental count for one whole rotation (360 degrees).
        See Also:
        Constant Field Values
      • count

        protected int count
      • inc

        protected static final int[][] inc
        The following table when indexed by [previous phase][current phase] provides the current direction of rotation. Invalid phase combinations result in zero.
    • Constructor Detail

      • RCXRotationSensor

        public RCXRotationSensor​(Port p)
        Create an RCX rotation sensor object attached to the specified port.
        Parameters:
        p - port, e.g. Port.S1
    • Method Detail

      • getPhase

        protected int getPhase()
        Returns the current phase of the sensor. The sensor returns four distinct values read by the ADC port. Each value represents a phase in the rotation. The sequence of the phases is: 0 1 3 2 and 0 2 3 1 The transition from one phase to another can be used to identify the direction of rotation.
        Returns:
        the current rotation phase.
      • getTachoCount

        public int getTachoCount()
        Returns the tachometer count. NOTE: Because the RCX rotation sensor only counts 16 increments for a full rotation, the degree values are only accurate to +- 22.5 degrees.
        Specified by:
        getTachoCount in interface Encoder
        Returns:
        tachometer count in degrees, in increments of 22.5 degrees (rounded off)
      • getRawTachoCount

        public int getRawTachoCount()
        Returns the raw values from the rotation sensor instead of degrees. A full rotation of 360 degrees results in count increasing by 16.
        Returns:
        the raw tachometer reading
      • resetTachoCount

        public void resetTachoCount()
        Reset the tacho count to zero.
        Specified by:
        resetTachoCount in interface Encoder
      • getRotationSpeed

        public int getRotationSpeed()
        Description copied from interface: Tachometer
        Returns the actual speed.
        Specified by:
        getRotationSpeed in interface Tachometer
        Returns:
        speed in degrees per second, negative value means motor is rotating backward