trajectory/ballistics/models: Update documentation

This commit is contained in:
Ray Healy 2026-03-14 09:36:45 -04:00
parent ef977386d9
commit 800940c2d7
3 changed files with 86 additions and 13 deletions

View File

@ -7,13 +7,27 @@ import edu.wpi.first.units.Units;
import edu.wpi.first.units.measure.Distance; import edu.wpi.first.units.measure.Distance;
import edu.wpi.first.units.measure.Time; import edu.wpi.first.units.measure.Time;
/// Base class for ballistic models
///
/// The model is responsible for:
/// - Tracking its launch and target positions (and relative stats)
/// - Managing
public abstract class BallisticModel<P> { public abstract class BallisticModel<P> {
protected Translation3d posLaunch; /// The launch position (i.e. where the projectile leaves the shooter)
protected Translation3d posTarget; protected final Translation3d posLaunch;
/// The target position (i.e. what we're trying to hit)
protected final Translation3d posTarget;
/// The position of posTarget relative to posLaunch
protected final Translation3d targetPosRelative; protected final Translation3d targetPosRelative;
/// The horizontal disance of targetPosRelative
protected final Distance relativeHorizontalDistance; protected final Distance relativeHorizontalDistance;
/**
* Constructo which sets the model
* @param posLaunch The inital posLaunch
* @param posTarget The inital posTarget
*/
public BallisticModel(Translation3d posLaunch, Translation3d posTarget) { public BallisticModel(Translation3d posLaunch, Translation3d posTarget) {
this.posLaunch = posLaunch; this.posLaunch = posLaunch;
this.posTarget = posTarget; this.posTarget = posTarget;
@ -29,18 +43,36 @@ public abstract class BallisticModel<P> {
// Base getters // Base getters
// //
/**
* Get the current launch position
* @return The current launch position
*/
public Translation3d getPosLaunch() { public Translation3d getPosLaunch() {
return this.posLaunch; return this.posLaunch;
} }
/**
* Get the current target position
* @return The current target position
*/
public Translation3d getPosTarget() { public Translation3d getPosTarget() {
return this.posTarget; return this.posTarget;
} }
/**
* Get the position of posTarget relative to posLaunch
*
* @return The position of posTarget relative to posLaunch
*/
public Translation3d getTargetPosRelative() { public Translation3d getTargetPosRelative() {
return this.targetPosRelative; return this.targetPosRelative;
} }
/**
* Get the horizontal distance between posLaunch and posTarget
*
* @return The horizontal distance between posLaunch and posTarget
*/
public Distance getRelativeHorizontalDistance() { public Distance getRelativeHorizontalDistance() {
return this.relativeHorizontalDistance; return this.relativeHorizontalDistance;
} }
@ -50,6 +82,8 @@ public abstract class BallisticModel<P> {
// //
/** /**
* Returns a recommended starting parameter
*
* @return Returns a recommended starting parameter * @return Returns a recommended starting parameter
*/ */
public abstract P getInitParam(); public abstract P getInitParam();
@ -72,7 +106,7 @@ public abstract class BallisticModel<P> {
/** /**
* Get an initial velocity (in the same coordinate space as posLaunch and * Get an initial velocity (in the same coordinate space as posLaunch and
* posTarget) which will pass thru posLaunch and posTarget with the given * posTarget) which will pass thru posLaunch and posTarget with the given
* model configurations and parameters * model configurations and parameters.
* *
* @param param The parameters used to determine this candidate * @param param The parameters used to determine this candidate
* @return The computed result for the given parameter * @return The computed result for the given parameter
@ -95,7 +129,8 @@ public abstract class BallisticModel<P> {
// //
/** /**
* Check if a given parameter has had a computed velocity * Check if a given parameter has had a computed velocity.
*
* @param param The param to check * @param param The param to check
* @return true iff the parameter has had a computed solution * @return true iff the parameter has had a computed solution
*/ */

View File

@ -13,17 +13,35 @@ import edu.wpi.first.units.measure.LinearAcceleration;
import edu.wpi.first.units.measure.Time; import edu.wpi.first.units.measure.Time;
/**
* Parabolic ballistic model, with solutions computed from time of flight
*/
public class ParabolicTimeOfFlightBM extends ReversableRadialBM<Time> { public class ParabolicTimeOfFlightBM extends ReversableRadialBM<Time> {
/** The linear acceleration of gravity in the +Z axis (positive is upwards) */
public static final LinearAcceleration k_gravity = Units.MetersPerSecondPerSecond.of(-9.81); public static final LinearAcceleration k_gravity = Units.MetersPerSecondPerSecond.of(-9.81);
protected final Time tofMin; /** The minimum time of flight to consider */
protected final Time tofMax; protected final Time tofMin;
protected final Time tofStep; /** The maximum time of flight to consider */
protected final Time tofMax;
/** The step between parameters */
protected final Time tofStep;
protected final Angle azimuth; /** The azimuth angle between posLaunch and posTarget */
protected final Angle azimuth;
private HashSet<Double> computedSeconds; /** The times (in seconds) that have been computed for */
private HashSet<Double> computedSeconds;
/**
* Main constructor
*
* @param posLaunch The position projectiles are launched from
* @param posTarget The target position for projectiles
* @param tofMin The minimum time of flight to consider
* @param tofMax The maximum time of flight to consider
* @param tofStep The timestep between candidate times of flight
*/
public ParabolicTimeOfFlightBM( public ParabolicTimeOfFlightBM(
Translation3d posLaunch, Translation3d posTarget, Translation3d posLaunch, Translation3d posTarget,
Time tofMin, Time tofMax, Time tofStep Time tofMin, Time tofMax, Time tofStep
@ -48,21 +66,39 @@ public class ParabolicTimeOfFlightBM extends ReversableRadialBM<Time> {
// Base getters // Base getters
// //
/**
* Gets the minimum time of flight
* @return the minimum time of flight
*/
public Time getTOFMin() { public Time getTOFMin() {
return this.tofMin; return this.tofMin;
} }
/**
* Get the maximum time of flight
* @return The maximum time of flight
*/
public Time getTOFMax() { public Time getTOFMax() {
return this.tofMax; return this.tofMax;
} }
/**
* Get the timestep between candidate times of flight
*
* @return The timestep between candidate times of flight
*/
public Time getTOFStep() { public Time getTOFStep() {
return this.tofStep; return this.tofStep;
} }
/**
* Get the computed azimuth angle from the launch position to the target position
*
* @return the computed azimuth angle from the launch position to the target position
*/
public Angle getAzimuth() { public Angle getAzimuth() {
return this.azimuth; return this.azimuth;
} }
@ -126,7 +162,6 @@ public class ParabolicTimeOfFlightBM extends ReversableRadialBM<Time> {
return radialDistance.div(candidate.getHorizontalVelocity()); return radialDistance.div(candidate.getHorizontalVelocity());
} }
// //
// Computed parameter check // Computed parameter check
// //

View File

@ -22,11 +22,14 @@ public abstract class ReversableRadialBM<P> extends BallisticModel<P> {
// //
/** /**
* Get the time taken to travel a given radial distance from posLaunch towards posTarget * Get the time taken to travel a given radial distance from posLaunch
* towards posTarget
* *
* @param candidate The generated velocity to compute against * @param candidate The generated velocity to compute against
* @param radialDistance The radial distance from posLaunch to posTarget to solve for * @param radialDistance The radial distance from posLaunch to posTarget to
* @return The time it takes to travel radialDistance from posTarget towards posTarget * solve for.
* @return The time it takes to travel radialDistance from posTarget towards
* posTarget
*/ */
public abstract Time getTimeAtRadius(Velocity3d candidate, Distance radialDistance); public abstract Time getTimeAtRadius(Velocity3d candidate, Distance radialDistance);