Skip to content

Commit 9d1f939

Browse files
committed
working adaptable path
1 parent 7300ce7 commit 9d1f939

File tree

3 files changed

+49
-10
lines changed

3 files changed

+49
-10
lines changed

src/main/java/com/github/mittyrobotics/pathfollowing/Parametric.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -543,17 +543,12 @@ public Vector2D getAbsoluteMaxCoordinates(double steps) {
543543

544544
/**
545545
* Return a new {@link Parametric} path to this parametric's setpoint from a position, velocity, and acceleration
546-
* @param newPos {@Pose2D} to start from
547-
* @param newVel {@Vector2D} velocity to start from
548-
* @param newAcc {@Vector2D} acceleration to start from
546+
* @param newPos {@link Pose2D} to start from
547+
* @param newVel {@link Vector2D} velocity to start from
548+
* @param newAcc {@link Vector2D} acceleration to start from
549549
* @return a new {@link Parametric} path to this parametric's setpoint from a position, velocity, and acceleration
550550
*/
551551
public Parametric getNewPath(Pose2D newPos, Vector2D newVel, Vector2D newAcc) {
552-
if(this instanceof QuinticHermiteSpline) {
553-
//for quintic hermite splines
554-
return new QuinticHermiteSpline(newPos, ((QuinticHermiteSpline) this).getPose1(), newVel,
555-
((QuinticHermiteSpline) this).getVelocity1(), newAcc, ((QuinticHermiteSpline) this).getAcceleration1());
556-
}
557552
return new Parametric();
558553
}
559554

src/main/java/com/github/mittyrobotics/pathfollowing/QuinticHermiteSpline.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,17 @@ public void setAcceleration1(Vector2D acceleration) {
255255
this.length = getGaussianQuadratureLength(17);
256256
}
257257

258+
/**
259+
* Return a new {@link QuinticHermiteSpline} path to this spline's setpoint from a position, velocity, and acceleration
260+
* @param newPos {@link Pose2D} to start from
261+
* @param newVel {@link Vector2D} velocity to start from
262+
* @param newAcc {@link Vector2D} acceleration to start from
263+
* @return a new {@link QuinticHermiteSpline} path to this spline's setpoint from a position, velocity, and acceleration
264+
*/
265+
@Override
266+
public QuinticHermiteSpline getNewPath(Pose2D newPos, Vector2D newVel, Vector2D newAcc) {
267+
//for quintic hermite splines
268+
return new QuinticHermiteSpline(newPos, pose1, newVel, velocity1, newAcc, acceleration1);
269+
}
270+
258271
}

src/main/java/com/github/mittyrobotics/pathfollowing/QuinticHermiteSplineGroup.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ public Point2D getDerivative(double t, int n) {
147147
return splines.get(index).getDerivative(getSplineTFromT(t, index), n);
148148
}
149149

150+
/**
151+
* Returns the closest associated t value on the spline from a {@link Point2D} using Newton's method on the distance function
152+
* @param point the {@link Point2D} that to get closest point from
153+
* @param steps the number of steps to start Newton's method from
154+
* @param iterations the number of iterations to run Newton's method on a single step
155+
* @return the closest associated t value on the spline from a {@link Point2D} using Newton's method on the distance function
156+
*/
150157
@Override
151158
public double findClosestPointOnSpline(Point2D point, int steps, int iterations) {
152159
Vector2D cur_min = new Vector2D(Double.POSITIVE_INFINITY, 0);
@@ -186,6 +193,11 @@ public double getGaussianQuadratureLength(double start, double end, int steps) {
186193
return length;
187194
}
188195

196+
/**
197+
* Returns the t parameter associated with a certain length from the beginning
198+
* @param length length to get the t parameter of
199+
* @return the t parameter associated with a certain length from the beginning
200+
*/
189201
@Override
190202
public double getTFromLength(double length) {
191203
double t = 0;
@@ -202,11 +214,30 @@ public double getTFromLength(double length) {
202214
return t;
203215
}
204216

217+
/**
218+
* Returns the index of the spline closest to a {@link Point2D}
219+
* @param point {@link Point2D} to get closest spline to
220+
* @param newtonsSteps the number of steps to start Newton's method from
221+
* @return the index of the spline closest to a {@link Point2D}
222+
*/
205223
public int getIndexOfSplineFromPoint(Point2D point, int newtonsSteps) {
206224
return getSplineFromT(findClosestPointOnSpline(point, newtonsSteps, 5));
207225
}
208226

209-
public double getIndexOfSplineFromPointI(Point2D point, int newtonsSteps) {
210-
return findClosestPointOnSpline(point, newtonsSteps, 5);
227+
/**
228+
* Return a new {@link QuinticHermiteSplineGroup} path to this spline group's setpoint from a position, velocity, and acceleration
229+
* @param newPos {@link Pose2D} to start from
230+
* @param newVel {@link Vector2D} velocity to start from
231+
* @param newAcc {@link Vector2D} acceleration to start from
232+
* @return a new {@link QuinticHermiteSplineGroup} path to this spline group's setpoint from a position, velocity, and acceleration
233+
*/
234+
@Override
235+
public QuinticHermiteSplineGroup getNewPath(Pose2D newPos, Vector2D newVel, Vector2D newAcc) {
236+
int index = getIndexOfSplineFromPoint(newPos.getPosition(), 100);
237+
QuinticHermiteSplineGroup group = new QuinticHermiteSplineGroup(new QuinticHermiteSpline(newPos, splines.get(index).getPose1()));
238+
for(int i = index + 1; i < splines.size(); i++) {
239+
group.addSpline(splines.get(i));
240+
}
241+
return group;
211242
}
212243
}

0 commit comments

Comments
 (0)