Servo Motor#

Introduction#

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

Class Constructors#

servo( triport::port& port );

Class Destructor#

Destroys the servo object and releases associated resources.

~servo();

Parameters#

Parameter

Type

Description

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).

Notes#

  • A Brain or 3-Wire Expander must be created first before they can be used to create an object with the servo class constructor.

Example#

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

Member Functions#

The servo class includes the following member functions:

  • setPosition — Sets the position of the servo motor.

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 Servo = servo(Brain.ThreeWirePort.A);

setPosition#

Sets the position of the servo motor to a specified value.

Available Functions

1 Sets the servo position using a percentage value.

void setPosition(
 int32_t value,
 percentUnits units );

2 Sets the servo position using rotation units.

void setPosition(
 double value,
 rotationUnits units );

Parameters

Parameter

Type

Description

value

int32_t

An integer value for the servo position when using percentage units.

value

double

A double value for the servo position when using rotation units.

units

percentUnits

The unit used to represent position as percentage:

  • percent / pct — percent

units

rotationUnits

The unit used to represent value:

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

Return Values

This function does not return a value.

Notes
  • When using percentage units, the valid range is 0 – 100%.

  • When using rotation units, the servo will move to the absolute position specified.

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

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

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