handle undershot and ok cases

This commit is contained in:
Kistaro Windrider 2024-01-28 01:33:25 -08:00
parent 5d2dafa64c
commit 8fa98e3132
Signed by: kistaro
SSH Key Fingerprint: SHA256:TBE2ynfmJqsAf0CP6gsflA0q5X5wD5fVKWPsZ7eVUg8

View File

@ -165,10 +165,23 @@ constraints = {
function constraints:constrain(s, want) function constraints:constrain(s, want)
self.color=10 self.color=10
if (not self.xmin) return want
local v1 = calc_velocity(s.dx, want, s.maxspd, s.drag) -- bmx: brake max
local bd, bf = brake_dist(v1, s.thrust + s.drag) local v1, bmx = calc_velocity(s.dx, want, s.maxspd, s.drag), s.thrust + s.drag
local bd, bf = brake_dist(v1, bmx)
local bx, txm = s.x + bd, self.xmax
if bx < self.xmin then
self.color = 9
want = s.thrust
txm = self.xmin
v1 = calc_velocity(s.dx, want, s.maxspd, s.drag)
bd, bf = brake_dist(v1, bmx)
bx = bd + s.x
end
if (bx < txm) return want
self.color = 8
-- TODO: implement overshot constraint
return want return want
end end