Skip to content
16 changes: 16 additions & 0 deletions Scripts/Approach/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Approach
_Automated approach script using RangeFinders and a PID loop_

This script is assembled from [this reddit thread][1], piecing together the info from various comments and adjusting it to work with the Jilted.
Setup assumes a single RangeFinder for the Distance calculation and a number of RangeFinders to assist it.

*Field names*:
```
:Approach bool enable approach
:Distance float RangeFinderDistance
:RFC float RangeFinderDistance of optional extra RangeFinders
```

Testing the actual approach PID loop is not possible without having an environment in the test runner that responds to eg. FCU* commands.

[1]: https://www.reddit.com/r/starbase/comments/p5mifp/safely_approach_asteroids_with_a_pid_controller/
8 changes: 8 additions & 0 deletions Scripts/Approach/approach.yolol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sp=19 Kp=0.3 Ki=0 Kd=0.5 le=0 int=0
IF NOT :Approach THEN GOTO1 END
d=:Distance IF :RFC AND :RFC<d THEN d=:RFC END
e=d-sp de=e-le int=int+e o=Kp*e+(Ki*int)+(Kd*de) le=e
IF d>999 OR e<10 THEN :Approach=0 GOTO8 END
IF o>0 THEN :FCUForward=o ELSE :FCUForward=0 END
IF o<0 THEN :FCUBackward=-o ELSE :FCUBackward=0 END
IF :Approach THEN GOTO3 ELSE :FCUForward=0 :FCUBackward=0 END