rotation#

Initializing the rotation Class#

A Rotation Sensor is created by using the following constructor:

The rotation constructor creates a rotation object in the specified Port with the reverse flag set to the specified value.

Parameter

Description

port

A valid Smart Port that the Rotation Sensor is connected to.

reverse

Set to true to reverse the angle and position returned by the Rotation Sensor. The default is false.

// Construct a Rotation Sensor "Rotation" with the
// rotation class.
rotation Rotation = rotation(PORT1, false);

This Rotation object will be used in all subsequent examples throughout this API documentation when referring to rotation class methods.

Class Methods#

setReversed()#

The setReversed(value) method sets the rotation direction to be reversed.

Parameters

Description

value

A boolean value to set the direction reversed or not.

Returns: None.

// Set the rotation direction to reverse.
Rotation.setReversed(true);

angle()#

The angle(units) method returns the angle measured by the Rotation Sensor.

Parameters

Description

units

A valid RotationUnit.

Returns: A double representing the angle measured by the Rotation Sensor in the specified units.

// Get the current angle of the Rotation Sensor
double angle = Rotation.angle(degrees);

// Print the current angle of the Rotation Sensor to the
// Brain's screen.
Brain.Screen.print(angle);

resetPosition()#

The resetPosition() method resets the position of the Rotation Sensor to 0.

Returns: None.

setPosition()#

The setPosition(value, units) method sets the position of the Rotation Sensor. The position returned by the position() method is set to this value.

Parameters

Description

value

The position value to set.

units

A valid RotationUnit.

Returns: None.

position()#

The position(units) method returns the current position of the Rotation Sensor.

Parameters

Description

units

A valid RotationUnit.

Returns: A double representing the current position of the Rotation Sensor in the specified units.

velocity()#

The velocity(units) method returns the velocity of the Rotation Sensor.

Parameters

Description

units

A valid VelocityUnit.

Returns: A double representing the velocity of the Rotation Sensor in the specified units.

changed()#

The changed(callback) method registers a callback function for when the value measured by the Rotation Sensor changes.

Parameters

Description

callback

The callback function to be called when the value measured by the Rotation Sensor changes.

Returns: None.

// Define the rotationChanged function with a void
// return type, showing it doesn't return a value.
void rotationChanged() {
  // The Brain will print that the value of the Rotation Sensor
  // changed on the Brain's screen.
  Brain.Screen.print("Rotation Sensor value changed");
}

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Run rotationChanged when the value of the
  // Rotation Sensor changes.
  Rotation.changed(rotationChanged);
}

installed()#

The installed() method returns if the Rotation Sensor is connected.

Returns: true if the Rotation Sensor is installed. false if it is not.