Skip to main content
Version: 4.0.0-beta.3

Util

controller​

The pros controller is defined globally in our library as master.

extern pros::Controller master;

screen_print()​

Prints to the LLEMU. This function handles text that's too long for a line by finding the last word and starting it on a new line, and takes \n to set a new line.

There are 8 lines, 0 through 7, and a line holds 38 characters. If the text wraps past line 7, the last line is cut off and ends in ..., and the lines above it are left alone. A line outside of 0 to 7 does nothing, and an empty string clears that line.

text input string
line starting line, 0 through 7. Defaults to 0

void screen_print(std::string text, int line = 0);

to_string_with_precision()​

Returns a string with a specific number of decimal points.

input your input value
n the amount of decimals you want to display

std::string to_string_with_precision(double input, int n = 2);

ez_template_print()​

Prints our branding on your terminal :D.

void ez_template_print();

sgn()​

Returns the sign of the input. Returns 1 if positive, -1 if negative, and 0 if 0.

input value to check the sign of

int sgn(double input);

clamp()​

Returns input restricted to min-max threshold.

input your input value
max the maximum input can be
min the minimum input can be

double clamp(double input, double max, double min);

clamp()​

Returns input restricted to min-max threshold.

The minimum used is negative max.

input your input value
max the absolute value maximum input can be

double clamp(double input, double max);

DELAY_TIME​

Standard delay time for loops in ms.

const int DELAY_TIME = 10;

SD_CARD_ACTIVE​

Boolean that checks if an SD card is installed. True if there is one, false if there isn't.

const bool SD_CARD_ACTIVE = pros::usd::is_installed();

to_deg()​

Converts radians to degrees.

input your input radian

double to_deg(double input);

to_rad()​

Converts degrees to radians.

input your input degree

double to_rad(double input);

absolute_angle_to_point()​

Returns the angle between two points.

itarget target pose
icurrent current pose

double absolute_angle_to_point(pose itarget, pose icurrent);

distance_to_point()​

Returns the distance between two points.

itarget target pose
icurrent current pose

double distance_to_point(pose itarget, pose icurrent);

wrap_angle()​

Constrains an angle between 180 and -180.

theta input angle in degrees

double wrap_angle(double theta);

vector_off_point()​

Returns a new pose that is projected off of the current pose.

added how far to project a new point
icurrent point to project off of

pose vector_off_point(double added, pose icurrent);

Version macros​

Macros that tell you which version of EZ-Template your code is being built against. They're for libraries and shared code that need to work with more than one EZ-Template version. Include EZ-Template/api.hpp and they're available, there's nothing to call.

3.x and early betas don't have these

The version macros are new in 4.0.0-beta.3, and they're not in 4.0.0-beta.1 or 4.0.0-beta.2. On those, and on 3.x, every macro on this page is missing, so your code has to cope with that.

MacroWhat it is
EZ_TEMPLATE_VERSION_MAJOR, EZ_TEMPLATE_VERSION_MINOR, EZ_TEMPLATE_VERSION_PATCHThe version numbers
EZ_TEMPLATE_VERSION_STAGEEZ_TEMPLATE_STAGE_ALPHA, EZ_TEMPLATE_STAGE_BETA, EZ_TEMPLATE_STAGE_RC or EZ_TEMPLATE_STAGE_RELEASE
EZ_TEMPLATE_VERSION_PRERELEASE_NUMThe N in beta.N, or 0 on a full release
EZ_TEMPLATE_VERSION_PRERELEASE"beta.3", or "" on a full release
EZ_TEMPLATE_VERSION_STRING"4.0.0-beta.3"
EZ_TEMPLATE_VERSIONOne integer that sorts correctly: alpha, then beta, then rc, then release. 4.0.0-rc.1 is less than 4.0.0
EZ_TEMPLATE_VERSION_ENCODE(major, minor, patch, stage, num)Builds that integer, for comparing against an exact version
EZ_TEMPLATE_VERSION_AT_LEAST(major, minor, patch)Feature check. Ignores the prerelease, so 4.0.0-beta.3 counts as 4.0.0

Minor, patch and the prerelease number must each stay under 100.

Checking for a version​

Include EZ-Template first, then give 3.x a fallback. 3.x doesn't define the macro, so without the fallback the #if would fail to compile. If the fallback comes before the include, the header's own definition still wins, but the compiler warns macro redefined.

#include "EZ-Template/api.hpp" // before the fallback below

#ifndef EZ_TEMPLATE_VERSION_AT_LEAST
#define EZ_TEMPLATE_VERSION_AT_LEAST(major, minor, patch) 0 // 3.x
#endif

#if EZ_TEMPLATE_VERSION_AT_LEAST(4, 0, 0)
// 4.0 or newer
#else
// 3.x
#endif

Don't write #if defined(EZ_TEMPLATE_VERSION_MAJOR) && EZ_TEMPLATE_VERSION_AT_LEAST(4, 0, 0). The preprocessor still reads the second half on 3.x, where that macro doesn't exist, and stops with a syntax error. Nest the #if instead.

Prereleases are not final​

Alpha, beta and rc releases are not final. APIs can change or be removed between them, and the final release may differ from any prerelease. EZ_TEMPLATE_VERSION_AT_LEAST(4, 0, 0) is true on every 4.0.0 prerelease, so if your code depends on something that changed during the prereleases, compare against a specific stage with EZ_TEMPLATE_VERSION_ENCODE instead.

#ifdef EZ_TEMPLATE_VERSION
#if EZ_TEMPLATE_VERSION >= EZ_TEMPLATE_VERSION_ENCODE(4, 0, 0, EZ_TEMPLATE_STAGE_RC, 1)
// 4.0.0-rc.1 or newer
#endif
#endif

To be told when you're building against a prerelease, add a warning:

#ifdef EZ_TEMPLATE_VERSION_STAGE
#if EZ_TEMPLATE_VERSION_STAGE != EZ_TEMPLATE_STAGE_RELEASE
#warning "Built against an EZ-Template prerelease, the API may change"
#endif
#endif

Printing the version​

void initialize() {
printf("EZ-Template %s\n", EZ_TEMPLATE_VERSION_STRING); // EZ-Template 4.0.0-beta.3
}