Skip to content

Commit

Permalink
Tests augmented.
Browse files Browse the repository at this point in the history
  • Loading branch information
markmaker committed Jul 6, 2020
1 parent 777ed4a commit 9aed71f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/main/java/org/openpnp/model/MotionProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ public void solveProfile(final int iterations, final double vtol, final double t
System.out.println("Vmax symmetrical move, immediate solution");
return;
}

// Need to solve this numerically. Because the solution can have many roots and local minimae, we need to split it into multiple
// regions with known qualities.

Expand Down Expand Up @@ -656,7 +657,7 @@ else if (t[5] > (-t[4]*0.25)) {
if (sValid0 && sValid1 &&
Math.min(vEffEntry, vEffExit) <= vPeak0
&& Math.max(vEffEntry, vEffExit) >= vPeak1
&& vPeak0 != 0 && vPeak1 != 0) {
/*&& vPeak0 != 0 && vPeak1 != 0*/) {
// We're between two valid entry/exit velocities. There may be an invalid region in the middle.
// --> Find it!
// Work hypothesis (from observing many curves empirically):
Expand All @@ -680,16 +681,19 @@ else if (t[5] > (-t[4]*0.25)) {
tResult = time;
if (sResult < 0) {
// Great, we found it.
System.out.println(" found invalid mid area "+vSearch+" s "+sResult+" t "+tResult);
break;
}
if (sResult > sSecant) {
// Raising result -> overshoot, this means there is no invalid section.
System.out.println(" overshot invalid mid area "+vSearch+" s "+sResult+" t "+tResult);
break;
}
// Apply secant method.
double gradient = (sResult-sSecant)/(vSecant-vSearch);
if (Math.abs(gradient) < vttol) {
// Stuck in a local minimum. This must be a near miss situation (otherwise we should see overshoot).
System.out.println(" stuck local minimum invalid mid area "+vSearch+" s "+sResult+" t "+tResult);
break;
}
double delta = -sResult/gradient;
Expand Down Expand Up @@ -745,6 +749,10 @@ else if (t[5] > (-t[4]*0.25)) {
System.out.println(" re-establish");
computeProfile(bestVelocity, vEffEntry, vEffExit, tMin);
}
if (tMin > time - ttol) {
// The solver may have slightly approximated. Stretch the profile into the exact minimum time.
retimeProfile(tMin);
}
// Result is now stored in the profile i.e. you can get v[4], a[2], a[6] to get the (signed) solution.
solvingTime = NanosecondTime.getRuntimeSeconds() - tStart;
setOption(ProfileOption.Solved);
Expand Down Expand Up @@ -1317,9 +1325,6 @@ protected static boolean isCoordinated(MotionProfile[] profile1) {

public void computeProfile(double vPeak, double vEffEntry, double vEffExit, double tMin) {

// Determine the direction of travel.
double signum = Math.signum(vPeak);

// Compare effective entry/exit velocities to vMax to know whether we need to accelerate or decelerate on entry/exit.
double signumEntry, signumExit;
signumEntry = Math.signum(vPeak - vEffEntry);
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/AdvancedMotionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ public void testMotionProfiles() throws Exception {
0.0, Double.POSITIVE_INFINITY, 0);
testProfile("recheck solution", profile2);

// Impossible move.
profile = new MotionProfile(
20, 0, 0, -181.71043395996094, 0, 0,
0, 1000, 700, 2000, 2000, 15000, 0.277342, Double.POSITIVE_INFINITY, 0);
testProfile("Impossible move", profile);

for (int s = -1; s <= 401; s++) {
Double tf = profile.getForwardCrossingTime(s, true);
Double tb = profile.getBackwardCrossingTime(s, true);
Expand Down

0 comments on commit 9aed71f

Please sign in to comment.