Servomotor#

Introducción#

The servo class is used to control and configure an EXP 3-Wire Servo Motor. The EXP 3-Wire Servo Motor provides position-based control within a fixed range of motion.

The EDR VEX Servo Motor

Constructores de clases#

servo( triport::port& port );

Instructor de clase#

Destroys the servo object and releases associated resources.

~servo();

Parámetros#

Parámetro

Tipo

Descripción

port

triport::port&

The 3-Wire Port that the Servo Motor is connected to, written as Brain.ThreeWirePort.X or ExpanderName.X, where X is the port letter (for example, Brain.ThreeWirePort.A or Expander1.A).

Ejemplo#

// Create the servo instance on 3-Wire Port A
servo myServo = servo(Brain.ThreeWirePort.A);

Funciones de los miembros#

The servo class includes the following member functions:

  • setPosition — Moves the servo motor to a specified position.

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

/* This constructor is required when using VS Code.
Servo configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */

// Create the servo instance on 3-Wire Port A
servo myServo = servo(Brain.ThreeWirePort.A);

setPosition#

Moves the servo motor to a specified position.

A diagram of a servo motor showing the degrees that it can rotate, from 100 to 0 degrees.

Available Functions

1 Establece la posición del servo utilizando un valor porcentual.

void setPosition(
 int32_t value,
 percentUnits units );

2 Establece la posición del servo utilizando unidades de rotación.

void setPosition(
 double value,
 rotationUnits units );

Parameters

Parámetro

Tipo

Descripción

value

int32_t

The servo position value when using percentage units.

value

double

The servo position value when using rotation units.

units

percentUnits

The position unit: percent / pct — percent

units

rotationUnits

The position unit:

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

Return Values

Esta función no devuelve ningún valor.

Notes
  • Al utilizar unidades porcentuales, el rango válido es de 0 a 100%.

  • A servo begins each project by automatically centering itself at 50 degrees before completing any movements.

  • Al utilizar unidades de rotación, el servomotor se moverá a la posición absoluta especificada.

Examples
// Set the servo position to 10 percent
myServo.setPosition(10, percent);

// Set the servo position to 45.5 degrees
myServo.setPosition(45.5, degrees);

// Set the servo position to 90 degrees
myServo.setPosition(90, degrees);