Class Formula

java.lang.Object
dev.doglog.Formula

@Immutable public final class Formula extends Object
A formula that DogLog Studio calculates a computed entry with, from the values of other entries. Log one with DogLog.computed(String, Formula).

Build formulas from entries and numbers with the static methods and the arithmetic methods, ex. abs(entry("Arm/Position").minus(entry("Arm/Target"))).minus(Inches.of(2)). Studio converts between units, so values with different units of the same measure can be combined. Comparisons, like lessThan(Formula), make a Condition.

Fields of logged structs are entries too, ex. entry("Drive/Pose/translation/x"), and Studio knows the units of WPILib's.

toString() returns the formula's text in the @team581/log-formula language.

  • Method Details

    • abs

      public static Formula abs(Formula value)
      The absolute value.
    • atan2

      public static Formula atan2(Formula y, Formula x)
      The angle of the point (x, y) from the X axis, in radians.
    • avgOverTime

      public static Formula avgOverTime(Condition value)
      The fraction of the time since the first value that the condition was true, from 0 to 1.
    • avgOverTime

      public static Formula avgOverTime(Condition value, org.wpilib.units.measure.Time window)
      The fraction of the last window that the condition was true, from 0 to 1. It has no value until a full window was logged.
    • avgOverTime

      public static Formula avgOverTime(Formula value)
      The average since the first value, weighted by how long each value was held.
    • avgOverTime

      public static Formula avgOverTime(Formula value, org.wpilib.units.measure.Time window)
      The average over the last window, weighted by how long each value was held, ex. a moving average. It has no value until a full window was logged.
    • ceil

      public static Formula ceil(Formula value)
      The value rounded up, for numbers without a unit.
    • clamp

      public static Formula clamp(Formula value, Formula low, Formula high)
      The value limited to low through high.
    • cos

      public static Formula cos(Formula angle)
      The cosine of an angle.
    • count

      public static Formula count(Condition condition)
      How many times the condition became true, ex. game pieces intaken. It counts 1 when the condition is true at its first value.
    • deadband

      public static Formula deadband(Formula value, Formula width)
      0 when the value is within width of 0, otherwise the value.
    • derivative

      public static Formula derivative(Formula value)
      The rate of change per second, ex. acceleration from velocity.
    • entry

      public static Formula entry(String key)
      An entry's value.
      Parameters:
      key - The entry's key, ex. "Drive/Velocity".
    • entry

      public static Formula entry(String key, org.wpilib.units.Unit unit)
      An entry's value in a unit, for entries logged without unit metadata.
      Parameters:
      key - The entry's key, ex. "Gyro/Yaw".
      unit - The unit the entry's values are in.
    • floor

      public static Formula floor(Formula value)
      The value rounded down, for numbers without a unit.
    • hypot

      public static Formula hypot(Formula first, Formula second, Formula... rest)
      The square root of the sum of the values' squares, ex. the length of a vector.
    • integral

      public static Formula integral(Formula value)
      The sum of the value over time in seconds, ex. distance from velocity.
    • max

      public static Formula max(Formula first, Formula second, Formula... rest)
      The largest value, in the first value's unit.
    • maxOverTime

      public static Formula maxOverTime(Formula value)
      The largest value since the first one, including the current value.
    • maxOverTime

      public static Formula maxOverTime(Formula value, org.wpilib.units.measure.Time window)
      The largest value over the last window, including the current value. It has no value until a full window was logged.
    • min

      public static Formula min(Formula first, Formula second, Formula... rest)
      The smallest value, in the first value's unit.
    • minOverTime

      public static Formula minOverTime(Formula value)
      The smallest value since the first one, including the current value.
    • minOverTime

      public static Formula minOverTime(Formula value, org.wpilib.units.measure.Time window)
      The smallest value over the last window, including the current value. It has no value until a full window was logged.
    • of

      public static Formula of(double value)
      A number without a unit.
    • of

      public static Formula of(double value, org.wpilib.units.Unit unit)
      A number in a unit, ex. of(2, Inches).
    • of

      public static Formula of(org.wpilib.units.Measure<?> value)
      A measure, ex. of(Inches.of(2)).
    • round

      public static Formula round(Formula value)
      The value rounded to the nearest integer, halves away from zero, for numbers without a unit.
    • sign

      public static Formula sign(Formula value)
      -1, 0, or 1 for negative, zero, or positive values, without a unit.
    • sin

      public static Formula sin(Formula angle)
      The sine of an angle.
    • sqrt

      public static Formula sqrt(Formula value)
      The square root, its unit's powers are halved.
    • time

      public static Formula time(Condition condition)
      The seconds the condition was true the latest time, counting up while it is and keeping that time's length after it ends, ex. time(Condition.entryEquals("Shooter/State", ShooterState.SCORE)) for how long scoring took.
    • totalTime

      public static Formula totalTime(Condition condition)
      The seconds the condition was true since the first value, ex. time spent defending.
    • unwrap

      public static Formula unwrap(Formula angle)
      An angle that keeps counting past a full turn instead of wrapping, ex. a gyro's heading.
    • wrap

      public static Formula wrap(Formula angle)
      An angle wrapped to a half turn either way, ex. 190° is -170°.
    • div

      public Formula div(double other)
      This divided by a number.
    • div

      public Formula div(Formula other)
      This divided by other.
    • div

      public Formula div(org.wpilib.units.Measure<?> other)
      This divided by a measure.
    • equals

      public boolean equals(@Nullable Object other)
      Overrides:
      equals in class Object
    • greaterThan

      public Condition greaterThan(double other)
      Whether this is more than a number.
    • greaterThan

      public Condition greaterThan(Formula other)
      Whether this is more than other.
    • greaterThan

      public Condition greaterThan(org.wpilib.units.Measure<?> other)
      Whether this is more than a measure.
    • greaterThanOrEqualTo

      public Condition greaterThanOrEqualTo(double other)
      Whether this is at least a number.
    • greaterThanOrEqualTo

      public Condition greaterThanOrEqualTo(Formula other)
      Whether this is at least other.
    • greaterThanOrEqualTo

      public Condition greaterThanOrEqualTo(org.wpilib.units.Measure<?> other)
      Whether this is at least a measure.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • isEqualTo

      public Condition isEqualTo(double other)
      Whether this is exactly a number, see isNear(Formula, Formula) for measured values.
    • isEqualTo

      public Condition isEqualTo(Formula other)
      Whether this is exactly other, see isNear(Formula, Formula).
    • isEqualTo

      public Condition isEqualTo(org.wpilib.units.Measure<?> other)
      Whether this is exactly a measure, see isNear(Formula, Formula).
    • isNear

      public Condition isNear(double other, double tolerance)
      Whether this is within tolerance of a number, like MathUtil.isNear().
    • isNear

      public Condition isNear(Formula other, Formula tolerance)
      Whether this is less than tolerance away from other, like MathUtil.isNear(). Angles aren't wrapped, compare wrap(a.minus(b)) with 0 for that.
    • isNear

      public Condition isNear(Formula other, org.wpilib.units.Measure<?> tolerance)
      Whether this is within tolerance of other, ex. Inches.of(1).
    • isNear

      public Condition isNear(org.wpilib.units.Measure<?> other, org.wpilib.units.Measure<?> tolerance)
      Whether this is within tolerance of a measure.
    • isNotEqualTo

      public Condition isNotEqualTo(double other)
      Whether this isn't exactly a number.
    • isNotEqualTo

      public Condition isNotEqualTo(Formula other)
      Whether this isn't exactly other.
    • isNotEqualTo

      public Condition isNotEqualTo(org.wpilib.units.Measure<?> other)
      Whether this isn't exactly a measure.
    • lessThan

      public Condition lessThan(double other)
      Whether this is less than a number.
    • lessThan

      public Condition lessThan(Formula other)
      Whether this is less than other.
    • lessThan

      public Condition lessThan(org.wpilib.units.Measure<?> other)
      Whether this is less than a measure.
    • lessThanOrEqualTo

      public Condition lessThanOrEqualTo(double other)
      Whether this is at most a number.
    • lessThanOrEqualTo

      public Condition lessThanOrEqualTo(Formula other)
      Whether this is at most other.
    • lessThanOrEqualTo

      public Condition lessThanOrEqualTo(org.wpilib.units.Measure<?> other)
      Whether this is at most a measure.
    • minus

      public Formula minus(double other)
      This minus a number.
    • minus

      public Formula minus(Formula other)
      This minus other.
    • minus

      public Formula minus(org.wpilib.units.Measure<?> other)
      This minus a measure.
    • negate

      public Formula negate()
      The negative of this.
    • plus

      public Formula plus(double other)
      This plus a number.
    • plus

      public Formula plus(Formula other)
      This plus other.
    • plus

      public Formula plus(org.wpilib.units.Measure<?> other)
      This plus a measure.
    • pow

      public Formula pow(double exponent)
      This to the power of a number, an integer when this has a unit.
    • pow

      public Formula pow(Formula exponent)
      This to the power of exponent, which has no unit.
    • times

      public Formula times(double other)
      This times a number.
    • times

      public Formula times(Formula other)
      This times other.
    • times

      public Formula times(org.wpilib.units.Measure<?> other)
      This times a measure.
    • toString

      public String toString()
      The formula's text, ex. derivative(`/Drive/Velocity`).
      Overrides:
      toString in class Object