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 |
|---|---|---|
|
|
The Smart Port that the Rotation Sensor is connected to, written as |
|
|
Determines whether the reported angle and position values are reversed:
|
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.
void setPosition(
double value,
rotationUnits units );
Parameter |
Type |
Description |
|---|---|---|
|
|
The position value to set. |
|
|
The units that represent
|
This function does not return a value.
angle#
Returns the angle measured by the Rotation Sensor.
Available Functionsdouble angle( rotationUnits units = degrees );
Parameter |
Type |
Description |
|---|---|---|
|
|
The unit that represents the angle:
|
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 Functionsdouble position( rotationUnits units );
Parameter |
Type |
Description |
|---|---|---|
|
|
The units that represent the position:
|
Returns a double representing the current position of the Rotation Sensor in the specified units.
velocity#
Returns the velocity of the Rotation Sensor.
Available Functionsdouble velocity( velocityUnits units );
Parameter |
Type |
Description |
|---|---|---|
|
|
The unit that represents the detected velocity:
|
Returns a double representing the velocity of the Rotation Sensor in the specified units.