Utility Functions
package com.seattlesolvers.solverslib.util;
SolversLib comes with many different Utility Functions:
What is a Look Up Table?
A look up table or LUT for short is used to store values and be able to quickly recall them.
The SolversLib provides 2 different variations of look up tables. In this year's game they can be used to store different set and tested velocities or angles. You can either retrieve the closest reference or you can interpolate through them.
LUT (Look Up Table)
Provides a way to store values in a table to quickly retrieve them. For example, this might be used to store different speeds or angles based on certain distances. This class allows you to find the closest entry to the input.
For example if you enter:
0
0
1
1
2
1
When you request 1.1, it will return 1.
Example Usage:
InterpLUT (Interpolated Look Up Table)
Provides a way to fill in the gaps in the data. Similarly to the LUT above, this allows you to add data points and retrieve a data point given an output. The difference between a normal LUT and InterpLUT is that the interpolated LUT uses math to fill in all the gaps. Effectively generating filler data based on the data around it.
Example Usage:
Timing Functions
SolversLib provides its timing utilities through the nested classes of the Timing class: a Stopwatch for measuring elapsed and loop times, a Timer for counting down a fixed duration, and a Rate for limiting how often fast code paths run. They are lightweight alternatives to the SDK's ElapsedTime for quick uses.
Stopwatch
A Stopwatch measures elapsed time. It can be created with a TimeUnit, or defaults to seconds:
stopwatch.start()
void
Starts (or restarts) the stopwatch
stopwatch.start(paused)
void
Restarts the stopwatch, optionally leaving it paused
stopwatch.pause()
void
Pauses the stopwatch, freezing elapsedTime()
stopwatch.resume()
void
Resumes a paused stopwatch
stopwatch.elapsedTime()
long
Returns the elapsed (unpaused) time, in the constructor's TimeUnit
stopwatch.deltaTime()
long
Returns the time since start() or the last deltaTime() call
stopwatch.isTimerOn()
boolean
Returns whether the stopwatch is running (started and not paused)
deltaTime() makes measuring loop times easy:
Timer
A Timer extends Stopwatch to count down a fixed length, so every Stopwatch method above works on a Timer too. It is created with a length, or a length and a TimeUnit (defaulting to seconds):
On top of the Stopwatch methods, it adds:
timer.remainingTime()
long
Returns the time left until the timer is done
timer.done()
boolean
Returns whether at least the timer's length of (unpaused) time has elapsed
Rate (Refresh Rate Timer)
A Rate limits how often something runs — for example, capping hardware reads/writes or telemetry updates. It only works in milliseconds and starts counting when created.
Rate is a non-static inner class of Timing, so it is constructed through a Timing instance:
atTime(): returns whether at least the rate's interval has passed since the lastatTime()(orreset()) call, and restarts the clock either way.reset(): restarts the interval.
Math Utilities
SolversLib provides its math utilities through the MathUtils class. Every method is static, so you never create a MathUtils object — just import the class and call the methods on it directly:
Clamp
clamp lets you restrict a value to a certain max and min and is usable in double and int.
Example Usage:
Double Method:
Int Method:
Round
round(double number, int places) rounds a number to the given amount of decimal places (rounding half up), which is handy for cleaning up telemetry values.
Angle Normalization
These methods wrap an angle back into a standard range, which is useful for heading math — for example, making sure your turn-to-angle code always takes the shortest way around. The boolean parameter picks the output range: true gives 0 to 360° (or 0 to 2π), while false gives -180° to 180° (or -π to π).
normalizeAngle(double angle, boolean zeroToMax, AngleUnit angleUnit)
Normalizes an angle in the unit given by the FTC SDK's AngleUnit (DEGREES or RADIANS)
normalizeDegrees(double angle, boolean zeroToFull)
Shortcut for normalizeAngle with AngleUnit.DEGREES
normalizeRadians(double angle, boolean zeroToFull)
Shortcut for normalizeAngle with AngleUnit.RADIANS
returnMaxForAngleUnit(AngleUnit angleUnit)
Returns the full-circle value for the unit (360 for degrees, 2π for radians)
Signed Square Root
sqrtWithSig(double val) returns the square root of the absolute value while keeping the original sign — useful for shaping joystick inputs without losing direction.
Directional Enums
SolversLib comes with multiple directional enums for all your directional needs! You can use these for any autonomous or TeleOP States or anything you want!
LEFT
0
RIGHT
1
UP
2
DOWN
3
FORWARD
4
BACKWARDS
5
You can find some examples in the sample folder.
Last updated