LightLib
PROS library for VEX V5: EKF/MCL localization, RAMSETE path following, high-level chassis API
Loading...
Searching...
No Matches
util.hpp File Reference

Shared types, enums, math helpers, and unit conversions used across LightLib. More...

#include <algorithm>
#include <atomic>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <memory>
#include <sstream>
#include <string>
#include <vector>
#include "LightLib/api.h"
#include "light/units.hpp"

Go to the source code of this file.

Classes

struct  light::pose
 2D pose: position (in) and heading (deg). More...
 
struct  light::united_pose
 2D pose with okapi units. More...
 
struct  light::odom
 One waypoint of an odom-mode movement. More...
 
struct  light::united_odom
 One waypoint of an odom-mode movement, with okapi units. More...
 

Namespaces

namespace  light
 Public LightLib odometry / pose-estimation API.
 
namespace  light::units
 Single source of truth for unit conversions.
 
namespace  light::util
 Misc math, geometry, and unit-conversion helpers.
 

Functions

void light::ez_template_print ()
 Prints our branding all over your pros terminal.
 
void light::screen_print (std::string text, int line=0)
 Prints to the brain screen in one string.
 
std::string light::exit_to_string (exit_output input)
 Returns a human-readable name for an exit_output code.
 
int light::util::places_after_decimal (double input, int min=0)
 Returns the amount of places after a decimal, maxing out at 6.
 
std::string light::util::to_string_with_precision (double input, int n=2)
 Returns a string with a specific number of decimal points.
 
int light::util::sgn (double input)
 Returns 1 if input is positive and -1 if input is negative.
 
bool light::util::reversed_active (double input)
 Returns true if the input is < 0.
 
double light::util::clamp (double input, double max, double min)
 Returns input restricted to min-max threshold.
 
double light::util::clamp (double input, double max)
 Returns input restricted to min-max threshold.
 
double light::util::to_deg (double input)
 Converts radians to degrees.
 
double light::util::to_rad (double input)
 Converts degrees to radians.
 
double light::util::absolute_angle_to_point (pose itarget, pose icurrent)
 Returns the angle between two points.
 
double light::util::distance_to_point (pose itarget, pose icurrent)
 Returns the distance between two points.
 
double light::util::wrap_angle (double theta)
 Constrains an angle between 180 and -180.
 
float light::util::wrap_rad (float a)
 Wraps an angle in radians to the half-open interval (-pi, pi].
 
pose light::util::vector_off_point (double added, pose icurrent)
 Returns a new pose that is projected off of the current pose.
 
double light::util::turn_shortest (double target, double current, bool print=false)
 Returns the shortest angle for the robot to turn to in order to get to target.
 
double light::util::turn_longest (double target, double current, bool print=false)
 Returns the farthest away angle for the robot to turn to in order to get to target.
 
pose light::util::united_pose_to_pose (united_pose input)
 Converts pose with okapi units to a pose without okapi units.
 
std::vector< odomlight::util::united_odoms_to_odoms (std::vector< united_odom > inputs)
 Converts vector of poses with okapi units to a vector of poses without okapi units.
 
odom light::util::united_odom_to_odom (united_odom input)
 Converts odom movement with united pose to an odom movement without united pose.
 

Variables

pros::Controller master
 Global V5 master controller, used by opcontrol throughout LightLib.
 
constexpr double light::units::MM_PER_IN = 25.4
 Millimeters per inch.
 
constexpr double light::units::IN_PER_MM = 1.0 / 25.4
 Inches per millimeter.
 
constexpr double light::units::M_PER_IN = 0.0254
 Meters per inch.
 
constexpr double light::units::IN_PER_M = 1.0 / 0.0254
 Inches per meter.
 
constexpr double light::units::DEG_PER_RAD = 180.0 / M_PI
 Degrees per radian.
 
constexpr double light::units::RAD_PER_DEG = M_PI / 180.0
 Radians per degree.
 
bool light::util::AUTON_RAN
 Set true once any autonomous routine has run this match.
 
const bool light::util::SD_CARD_ACTIVE = pros::usd::is_installed()
 True if an SD card is currently inserted.
 
const int light::util::DELAY_TIME = 10
 Default loop period for LightLib background tasks, in milliseconds.
 

Public types and enums

enum  light::e_type { light::SINGLE = 0 , light::SPLIT = 1 }
 Arcade joystick layout. More...
 
enum  light::e_swing { light::LEFT_SWING = 0 , light::RIGHT_SWING = 1 }
 Direction for swing-turn motions. More...
 
enum  light::exit_output {
  light::RUNNING = 1 , light::SMALL_EXIT = 2 , light::BIG_EXIT = 3 , light::VELOCITY_EXIT = 4 ,
  light::mA_EXIT = 5 , light::ERROR_NO_CONSTANTS = 6
}
 Result codes returned by PID::exit_condition. More...
 
enum  light::e_mode {
  light::DISABLE = 0 , light::SWING = 1 , light::TURN = 2 , light::TURN_TO_POINT = 3 ,
  light::DRIVE = 4 , light::POINT_TO_POINT = 5 , light::PURE_PURSUIT = 6
}
 Active chassis motion mode. More...
 
enum  light::drive_directions {
  light::FWD = 0 , light::FORWARD = FWD , light::fwd = FWD , light::forward = FWD ,
  light::REV = 1 , light::REVERSE = REV , light::rev = REV , light::reverse = REV
}
 Drive direction with multiple spelling aliases. More...
 
enum  light::e_angle_behavior {
  light::raw = 0 , light::left_turn = 1 , light::LEFT_TURN = 1 , light::counterclockwise = 1 ,
  light::ccw = 1 , light::right_turn = 2 , light::RIGHT_TURN = 2 , light::clockwise = 2 ,
  light::cw = 2 , light::shortest = 3 , light::longest = 4
}
 How to choose a turn direction when reaching an absolute heading. More...
 
typedef struct light::pose light::pose
 2D pose: position (in) and heading (deg).
 
typedef struct light::united_pose light::united_pose
 2D pose with okapi units.
 
typedef struct light::odom light::odom
 One waypoint of an odom-mode movement.
 
typedef struct light::united_odom light::united_odom
 One waypoint of an odom-mode movement, with okapi units.
 
const double light::ANGLE_NOT_SET = 0.0000000000000000000001
 Sentinel value indicating "no angle specified".
 
const okapi::QAngle light::p_ANGLE_NOT_SET = 0.0000000000000000000001_deg
 Sentinel value indicating "no angle specified" (united).
 

Detailed Description

Shared types, enums, math helpers, and unit conversions used across LightLib.

Pulled into nearly every other header.

Definition in file util.hpp.

Variable Documentation

◆ master

pros::Controller master
extern

Global V5 master controller, used by opcontrol throughout LightLib.