Util
Util​
controller​
The pros controller is defined globally in our library as master
.
- Prototype
- Example
void opcontrol() {
while (true) {
int l_stick = opcontrol_curve_left(master.get_analog(ANALOG_LEFT_Y));
int r_stick = opcontrol_curve_left(master.get_analog(ANALOG_RIGHT_Y));
chassis.drive_set(l_stick, r_stick);
pros::delay(ez::util::DELAY_TIME);
}
}
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.
text
input string
line
starting line
- Prototype
- Example
- Example 2
Returns:
hello, this is line 0
this is line 1
void initialize() {
ez::screen_print("hello, this is line 0\nthis is line 1");
}
void screen_print(std::string text, int line)
Returns:
01234567890123456789012345678901
hello
void initialize() {
std::string 32char = 01234567890123456789012345678901;
ez::print_to_screen(32char + "hello", 2);
}
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
- Prototype
- Example
std::string to_string_with_precision(double input, int n = 2);
void initialize() {
// This will print 1.23
double test = 1.23456789;
std::cout << ez::util::to_string_with_precision(test) << std::endl;
}
print_ez_template()​
Prints our branding on your terminal :D.
- Prototype
- Example
void initialize() {
print_ez_template();
}
void print_ez_template();
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
- Prototype
- Example
void opcontrol() {
while (true) {
printf("Sgn of Controller: %i \n", sgn(master.get_analog(ANALOG_LEFT_Y)));
pros::delay(ez::util::DELAY_TIME);
}
}
double 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
- Prototype
- Example
void opcontrol() {
while (true) {
int joy = master.get_analog(ANALOG_LEFT_Y);
// When the joystick is between 100 and 127
// (or -100 and -127) this will print 100 (or -100).
printf("Clipped Controller: %i \n", clamp(joy, 100, -100));
}
}
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 maximum input can be
min
the absolute value maximum input can be
- Prototype
- Example
void opcontrol() {
while (true) {
int joy = master.get_analog(ANALOG_LEFT_Y);
// When the joystick is between 100 and 127
// (or -100 and -127) this will print 100 (or -100).
printf("Clipped Controller: %i \n", clamp(joy, 100));
}
}
double clamp(double input, double max);
DELAY_TIME​
Standard delay time for loops in ms.
- Prototype
- Example
void opcontrol() {
while (true) {
chassis.opcontrol_tank();
pros::delay(ez::util::DELAY_TIME);
}
}
const int DELAY_TIME = 10;
IS_SD_CARD​
Boolean that checks if an SD card is installed. True if there is one, false if there isn't.
- Prototype
- Example
void initialize() {
if (!ez::util::IS_SD_CARD)
printf("No SD Card Found!\n");
}
const bool IS_SD_CARD = pros::usd::is_installed();
to_deg()​
Converts radians to degrees.
input
your input radian
- Prototype
- Example
double to_deg(double input);
void initialize() {
double test = ez::util::to_deg(3.14);
std::cout << ez::util::to_string_with_precision(test) << std::endl;
}
to_rad()​
Converts degrees to radians.
input
your input degree
- Prototype
- Example
double to_deg(double input);
void initialize() {
double test = ez::util::to_rad(180.0);
std::cout << ez::util::to_string_with_precision(test) << std::endl;
}
absolute_angle_to_point()​
Returns the angle between two points.
itarget
target pose
icurrent
current pose
- Prototype
- Example
double absolute_angle_to_point(pose itarget, pose icurrent);
void initialize() {
double test = ez::util::absolute_angle_to_point({12, 12}, {0, 0});
std::cout << ez::util::to_string_with_precision(test) << std::endl;
}
distance_to_point()​
Returns the distance between two points.
itarget
target pose
icurrent
current pose
- Prototype
- Example
double distance_to_point(pose itarget, pose icurrent);
void initialize() {
double test = ez::util::distance_to_point({12, 12}, {0, 0});
std::cout << ez::util::to_string_with_precision(test) << std::endl;
}
wrap_angle()​
Constrains an angle between 180 and -180.
wrap_angle
input angle in degrees
- Prototype
- Example
double wrap_angle(double theta);
void initialize() {
double test = ez::util::wrap_angle(3600);
std::cout << ez::util::to_string_with_precision(test) << std::endl;
}
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
- Prototype
- Example
pose vector_off_point(double added, pose icurrent);
void initialize() {
ez::pose test = ez::util::vector_off_point(24, {0, 0, 0});
printf("(%.2f, %.2f, %.2f)\n", test.x, test.y, test.theta);
}