C++#
This guide provides detailed information on how to use the C++ classes available in VEXcode V5.
Each device or system is represented as a C++ class. Class pages include information about:
Constructors – How to create an instance of the class.
Member Functions – The functions you can call on that instance.
Other API Elements – Additional elements such as properties, control sequences, or related types when applicable.
API Reference Categories#
Browse the C++ API by device, system, or programming feature:
Drivetrain – Control a drivetrain with or without an attached Inertial, GPS, or Gyro Sensor.
Motors and Motor Controllers – Control Smart Motors and legacy motor controllers.
Controller – V5 Controller input, output, buttons, joysticks, and screen interaction.
Brain – V5 Brain screen drawing, and retrieving system information.
Competition – Competition control structure, including how to code for autonomous and driver control modes.
Smart Port Devices – Devices connected to V5 Smart Ports.
3-Wire Devices – Devices connected to 3-Wire ports.
Console – Console printing and output formatting.
Logic – Core programming features such as control flow, variables, functions, events, math utilities, threading, and timing tools.
VEXlink – Communication between multiple V5 Brains using wired or wireless linking.
CTE Workcell – Classes and utilities required to control and configure a CTE Workcell system.
Understanding API Entries#
Each API entry is organized to help you quickly understand what a function, constructor, or property does and how to use it in your code.
Depending on the type of API element, you may see the following sections:
Description – Explains what the function or element does and what effect it has in your code.
Available Functions / Syntax – Shows the exact C++ syntax you must use. If there are multiple versions, each one is listed separately.
Parameters – Describes the inputs you can provide, including valid values and units.
Return Values – Explains what the function returns, if anything.
Notes – Highlights important behavior, limitations, or interactions with other functions.
Examples – Provides commented C++ code that demonstrates how the function is commonly used.
Not every entry includes every section. Simpler functions may only include syntax and return information, while more advanced features may include detailed notes and complex examples.
All code examples are written to be practical and realistic, so you can copy and paste them into your own projects with minimal edits.
Example API Entry#
Below is a simplified example showing how a typical function entry is structured:
stopStops the drivetrain.
Available Functions1 — Stops the drivetrain using the currently configured stopping mode.
void stop();
Parameters2 — Stops the drivetrain using the specified brake mode.
void stop( brakeType mode );
Parameter |
Type |
描述 |
|---|---|---|
|
|
The brake type to use when stopping the drivetrain:
|
This function does not return a value.
Examples// Drive forward, then coast to a stop
myDrivetrain.setDriveVelocity(100, percent);
myDrivetrain.drive(forward);
wait(2, seconds);
myDrivetrain.stop(coast);