From 81ac0962bff0bd21c571c8a43f99b1793456a94c Mon Sep 17 00:00:00 2001
From: Jake Read <jake.read@cba.mit.edu>
Date: Wed, 30 Oct 2019 09:46:11 -0400
Subject: [PATCH] ramp ramp completion

---
 hunks/adhoc/saturn.js | 73 ++++++++++++++++++++++++++++++-------------
 1 file changed, 52 insertions(+), 21 deletions(-)

diff --git a/hunks/adhoc/saturn.js b/hunks/adhoc/saturn.js
index 524ad12..9bcbfc3 100644
--- a/hunks/adhoc/saturn.js
+++ b/hunks/adhoc/saturn.js
@@ -325,27 +325,58 @@ export default function Saturn() {
               writeDownTick()
             }
           } else if (tSeg1 < period){
-            // write slow-triangle up to pb,
-            // HERE 
-            // and last seg. as normal
-            ramps.push({
-              vi: cruise,
-              vf: vf,
-              t: tSeg3,
-              pi: pb,
-              pf: pf
-            })
+            // check that enough space to make slow triangle,
+            if(tSeg1 + tSeg2 < period){
+              // sweet lord there must be a better way
+              if(vf > vi){
+                writeUpTick()
+              } else {
+                writeDownTick()
+              }
+            } else {
+              // slow-triangle up,
+              ramps.push({
+                vi: vi,
+                vf: cruise,
+                t: 2 * vDist(pi, pb) / (vi + cruise),
+                pi: pi,
+                pf: pb
+              })
+              // and last seg. as normal
+              ramps.push({
+                vi: cruise,
+                vf: vf,
+                t: tSeg3,
+                pi: pb,
+                pf: pf
+              })
+            }
           } else if (tSeg3 < period){
-            // write first seg as normal,
-            ramps.push({
-              vi: vi,
-              vf: cruise,
-              t: tSeg1,
-              pi: pi,
-              pf: pa
-            })
-            // second as slow-loss from pa -> vf
-            // HERE
+            if(tSeg2 + tSeg3 < period){
+              // ibid
+              if(vf > vi){
+                writeUpTick()
+              } else {
+                writeDownTick()
+              }
+            } else {
+              // write first seg as normal,
+              ramps.push({
+                vi: vi,
+                vf: cruise,
+                t: tSeg1,
+                pi: pi,
+                pf: pa
+              })
+              // second as slow-loss from pa -> vf
+              ramps.push({
+                vi: cruise,
+                vf: vf,
+                t: 2 * vDist(pa, pf) / (cruise + vf),
+                pi: pa,
+                pf: pf
+              })
+            }
           } else {
             // 3 segs
             ramps.push({
@@ -461,7 +492,7 @@ export default function Saturn() {
       console.timeLog('lookahead')
       // we do one last check:
       for (let r of ramps) {
-        if (r.vi < minSpeed || r.vf < minSpeed || r.vi > cruise || r.vf > cruise || r.t < period) {
+        if (r.vi < minSpeed || r.vf < minSpeed || r.vi > (cruise * 1.1) || r.vf > (cruise * 1.1) || r.t < period) {
           console.warn(`troublesome ramp found on final check`, r)
         }
       }
-- 
GitLab