Rotation Sensor#

Introduction#

The rotation class is used to control and access data from the V5 Rotation Sensor. The Rotation Sensor measures angular position, total rotation, and rotational velocity.

Class Constructor#

rotation Rotation1 = rotation(
  int32_t index,
  bool    reverse = false );

Class Destructor#

Destroys the rotation object and releases associated resources.

virtual ~rotation();

Parameters#

Parameter

Type

Description

index

int32_t

The Smart Port that the Rotation Sensor is connected to, written as PORTx, where x is the port number (for example, PORT1).

reverse

bool

Determines whether the reported angle and position values are reversed:

  • true — Reverses the direction of the reported angle and position values.
  • false (default) — Reports angle and position values in the standard direction.

Examples#

// Create a rotation instance in Port 1
rotation Rotation1 = rotation(PORT1);

Member Functions#

The rotation class includes the following member functions:

  • setPosition — Sets the current position of the Rotation Sensor.

  • angle — Returns the detected angle of the Rotation Sensor.

  • position — Returns the detected position of the Rotation Sensor.

  • velocity — Returns the detected velocity of the Rotation Sensor.

Before calling any rotation member functions, a rotation instance must be created, as shown below:

// Create a rotation instance in Port 1
rotation Rotation1 = rotation(PORT1);

setPosition#

Sets the position of the Rotation Sensor. The position returned by position is set to this value.

Available Functions
void setPosition(
    double        value, 
    rotationUnits units );

Parameters

Parameter

Type

Description

value

double

The position value to set.

units

rotationUnits

The units that represent value:

  • deg / degrees — degrees
  • turns / rev — revolutions

Return Values

This function does not return a value.

angle#

Returns the angle measured by the Rotation Sensor.

Available Functions
double angle( rotationUnits units = degrees );

Parameters

Parameter

Type

Description

units

rotationUnits

The unit that represents the angle:

  • deg / degrees (default) — degrees
  • turns / rev — revolutions

Return Values

Returns a double representing the angle measured by the Rotation Sensor in degrees.

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

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

position#

Returns the current position of the Rotation Sensor.

Available Functions
double position( rotationUnits units );

Parameters

Parameter

Type

Description

units

rotationUnits

The units that represent the position:

  • deg / degrees — degrees
  • turns / rev — revolutions

Return Values

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

velocity#

Returns the velocity of the Rotation Sensor.

Available Functions
double velocity( velocityUnits units );

Parameters

Parameter

Type

Description

units

velocityUnits

The unit that represents the detected velocity:

  • dps — degrees per second
  • rpm — rotations per minute
Return Values

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