Sensor de rotación#
Introducción#
The rotation class is used to control and access data from a V5 Rotation Sensor.
The Rotation Sensor measures the rotation of a shaft. It can be used anywhere on a robot where a shaft is rotating, even if that shaft is not connected directly to a motor.
A motor has a built-in encoder that can track its own rotation. The Rotation Sensor works like an external encoder that can track the rotation of a separate shaft.
The Rotation Sensor can return the shaft’s angle, position, and velocity. Angle is the shaft’s absolute position from 0 to 359.99 degrees. It does not reset when a project starts or when the robot is powered off. Position tracks how many degrees or turns the shaft has rotated forward or reverse during a project, and it can be reset as needed.
The Rotation Sensor is compatible with 1/8 inch and 1/4 inch standard VEX shafts.
Constructor de clases#
rotation(
int32_t index,
bool reverse = false );
Instructor de clase#
Destroys the rotation object and releases associated resources.
virtual ~rotation();
Parámetros#
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
The Smart Port that the Rotation Sensor is connected to, written as |
|
|
Optional. Whether to reverse the Rotation Sensor output:
|
Ejemplos#
// Create a Rotation Sensor instance in Port 1
rotation Rotation1 = rotation(PORT1);
Funciones de los miembros#
The rotation class includes the following member functions:
setPosition— Sets the Rotation Sensor’s current position to a specific value.angle— Returns the shaft’s current angle from 0 to 359.99 degrees.position— Returns how far the shaft has rotated in degrees or turns.velocity— Returns how fast the shaft is rotating.
Before calling any rotation member functions, a rotation instance must be created, as shown below:
// Create a Rotation Sensor instance in Port 1
rotation Rotation1 = rotation(PORT1);
setPosition#
Sets the Rotation Sensor’s current position to a specific value.
Position is how far the shaft has rotated during a project. Setting the position changes the current position value without moving the shaft.
Available Functionsvoid setPosition(
double value,
rotationUnits units );
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
The position value to assign to the Rotation Sensor. This can be an integer or a decimal. |
|
|
The position unit:
|
Esta función no devuelve ningún valor.
angle#
Returns the shaft’s current angle.
Angle reports the shaft’s absolute position within one rotation, from 0 to 359.99 degrees. It does not reset when a project starts or when the robot is powered off.
Available Functionsdouble angle( rotationUnits units = degrees );
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
Optional. The angle unit:
|
Returns a double representing the shaft’s current angle in the specified units.
// Get the current angle of the shaft
double angle = Rotation1.angle(degrees);
// Print the current angle of the shaft to the
// Brain's screen.
Brain.Screen.print(angle);
position#
Returns how far the shaft has rotated.
Unlike angle, position can increase past 359.99 degrees or decrease below 0 degrees. Position tracks how far the shaft rotates forward or reverse during a project and can be reset as needed.
Available Functionsdouble position( rotationUnits units );
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
The position unit:
|
Returns a double representing how far the shaft has rotated in the specified units.
velocity#
Returns how fast the shaft is rotating.
Available Functionsdouble velocity( velocityUnits units );
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
The velocity unit:
|
Returns a double representing how fast the shaft is rotating in the specified units.