Package org.team1126.lib.math
Class PAPFController
java.lang.Object
org.team1126.lib.math.PAPFController
- All Implemented Interfaces:
Tunables.Tunable
Implements a predictive artificial potential field (P-APF),
capable of real-time motion planning with obstacle avoidance.
This implementation improves upon traditional APF algorithms by predicting the future movement of the robot to determine intermediate setpoints, with the goal of achieving smoother motion and preventing oscillation caused by suboptimal interactions with potentials generated by obstacles.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA circle with a specified radius.static interfaceRepresents a heuristic for transforming the force profile of an obstacle.static interfaceRepresents a heuristic for calculating the strength of the attractive force generated by the goal location.static final classAn infinite line that pushes parallel to the Y axis, to constrain left/right field-relative movement.static final classA line segment that pushes perpendicular from its length.static final classAn infinite line that pushes parallel to the X axis, to constrain forwards/backwards field-relative movement.static classA generic obstacle.static final classA simple point obstacle. -
Constructor Summary
ConstructorsConstructorDescriptionPAPFController(double horizon, double resolution, double tolerance, boolean savePrediction, PAPFController.GoalHeuristic goalHeuristic, PAPFController.Obstacle[] obstacles) Creates a new P-APF controller.PAPFController(double horizon, double resolution, double tolerance, boolean savePrediction, PAPFController.Obstacle[] obstacles) Creates a new P-APF controller. -
Method Summary
Modifier and TypeMethodDescriptionedu.wpi.first.math.kinematics.ChassisSpeedscalculate(edu.wpi.first.math.geometry.Pose2d currentPose, edu.wpi.first.math.geometry.Translation2d goal, double maxVelocity, double maxDeceleration) Returns the next velocity output of the potential field.edu.wpi.first.math.kinematics.ChassisSpeedscalculate(edu.wpi.first.math.geometry.Pose2d currentPose, edu.wpi.first.math.geometry.Translation2d goal, double maxVelocity, double maxDeceleration, PAPFController.Obstacle... tempObstacles) Returns the next velocity output of the potential field.edu.wpi.first.math.geometry.Translation2dgetGoal()Returns the current goal of the controller from the last invocation ofPAPFController.calculate().List<edu.wpi.first.math.geometry.Translation2d> Returns the current predicted motion of the robot from the last invocation ofPAPFController.calculate().edu.wpi.first.math.geometry.Translation2dReturns the current setpoint of the controller from the last invocation ofPAPFController.calculate().voidinitTunable(TunableTable table) Initializes the object to be tuned.edu.wpi.first.math.kinematics.ChassisSpeedsrepulsorDrive(edu.wpi.first.math.kinematics.ChassisSpeeds input, edu.wpi.first.math.geometry.Pose2d currentPose) Utilizes the potential field to alter an arbitrary input chassis speed and minimize collisions with obstacles.List<edu.wpi.first.math.geometry.Pose2d> visualizeField(int rows, double padding, double fieldLength, double fieldWidth) Returns a list of samples from the potential field for visualization in AdvantageScope.
-
Constructor Details
-
PAPFController
public PAPFController(double horizon, double resolution, double tolerance, boolean savePrediction, PAPFController.Obstacle[] obstacles) Creates a new P-APF controller.- Parameters:
horizon- The horizon at which to predict the robot's motion, in meters. Larger horizons increase computational cost, with the benefit of generally smoother motion.resolution- The resolution at which to sample the horizon in meters. Higher resolutions (i.e. smaller values) will increase accuracy of predicted motion, however are more computationally expensive.tolerance- The distance from the goal in meters at which to return a velocity output of 0.savePrediction- If the robot's predicted motion should be saved. Useful for debugging, however does increase GC pressure.obstacles- The field's obstacles.
-
PAPFController
public PAPFController(double horizon, double resolution, double tolerance, boolean savePrediction, PAPFController.GoalHeuristic goalHeuristic, PAPFController.Obstacle[] obstacles) Creates a new P-APF controller.- Parameters:
horizon- The horizon at which to predict the robot's motion, in meters. Larger horizons increase computational cost, with the benefit of generally smoother motion.resolution- The resolution at which to sample the horizon in meters. Higher resolutions (i.e. smaller values) will increase accuracy of predicted motion, however are more computationally expensive.tolerance- The distance from the goal in meters at which to return a velocity output of 0.savePrediction- If the robot's predicted motion should be saved. Useful for debugging, however does increase GC pressure.goalHeuristic- A heuristic for calculating the strength of the attractive force generated by the goal location.obstacles- The field's obstacles.
-
-
Method Details
-
getSetpoint
public edu.wpi.first.math.geometry.Translation2d getSetpoint()Returns the current setpoint of the controller from the last invocation ofPAPFController.calculate(). -
getGoal
public edu.wpi.first.math.geometry.Translation2d getGoal()Returns the current goal of the controller from the last invocation ofPAPFController.calculate(). -
getPrediction
Returns the current predicted motion of the robot from the last invocation ofPAPFController.calculate(). Note that this list will be empty ifsavePredictionisfalse. -
calculate
public edu.wpi.first.math.kinematics.ChassisSpeeds calculate(edu.wpi.first.math.geometry.Pose2d currentPose, edu.wpi.first.math.geometry.Translation2d goal, double maxVelocity, double maxDeceleration) Returns the next velocity output of the potential field. Note that while deceleration is accounted for, acceleration from rest is not. If acceleration limiting is desired, it must be implemented downstream.- Parameters:
currentPose- The current blue origin relative pose of the robot.goal- The desired position of the robot.maxVelocity- The desired cruise velocity of the robot, in m/s.maxDeceleration- The desired deceleration rate of the robot, in m/s/s.- Returns:
- Blue origin relative chassis speeds.
-
calculate
public edu.wpi.first.math.kinematics.ChassisSpeeds calculate(edu.wpi.first.math.geometry.Pose2d currentPose, edu.wpi.first.math.geometry.Translation2d goal, double maxVelocity, double maxDeceleration, PAPFController.Obstacle... tempObstacles) Returns the next velocity output of the potential field. Note that while deceleration is accounted for, acceleration from rest is not. If acceleration limiting is desired, it must be implemented downstream.- Parameters:
currentPose- The current blue origin relative pose of the robot.goal- The desired position of the robot.maxVelocity- The desired cruise velocity of the robot, in m/s.maxDeceleration- The desired deceleration rate of the robot, in m/s/s.tempObstacles- Additional temporary obstacles. Can be null.- Returns:
- Blue origin relative chassis speeds.
-
repulsorDrive
public edu.wpi.first.math.kinematics.ChassisSpeeds repulsorDrive(edu.wpi.first.math.kinematics.ChassisSpeeds input, edu.wpi.first.math.geometry.Pose2d currentPose) Utilizes the potential field to alter an arbitrary input chassis speed and minimize collisions with obstacles. Typically, this method is used for manipulating driver input such that the robot doesn't crash into field walls or game elements.- Parameters:
input- Blue origin relative input speeds, typically from the driver.currentPose- The current blue origin relative pose of the robot.- Returns:
- The new blue origin relative chassis speeds.
-
visualizeField
public List<edu.wpi.first.math.geometry.Pose2d> visualizeField(int rows, double padding, double fieldLength, double fieldWidth) Returns a list of samples from the potential field for visualization in AdvantageScope. Represented asPose2ds, the translation of the pose is the sample location, and the rotation is the direction of force at the sample. Useful for debugging purposes, but is not recommended for regular use due to performance implications.- Parameters:
rows- The number of rows (X+ direction) to sample. Columns are sampled relative to the ratio offieldWidth / fieldLength.padding- The distance past the field perimeter to sample in meters.fieldLength- The length of the field in meters.fieldWidth- The width of the field in meters.
-
initTunable
Description copied from interface:Tunables.TunableInitializes the object to be tuned. This method is called when adding the object to aTunableTable.- Specified by:
initTunablein interfaceTunables.Tunable- Parameters:
table- The table the object is being added to.
-