Nivekk/KOS — pull request #142 by a1270 (2013-10-09 23:23:23+00:00)
Title: Very basic surfspeed limiter.

No the prettiest code and probably named and placed in the wrong areas. It will hopefully give you an idea how to do it properly. Needed this as driving at 20m/s on minus gets you a bit of air. srfspdlmt(double) returns -0.5 if surfspeed > double and 0.5 if lessthan. Found using 1 was a bit too jumpy. Some ugly sample code follows:

>lights on.
brakes off.
clearscreen.
set geolock to latlng(-0.03,-74.5).
lock wheelsteering to geolock.
set trgspeed to srfspdlmt(-3).
lock wheelthrottle to trgspeed. // 1 == tracks -1 == wheels.
set orbit to 0.
until orbit > 0 {
print "geolockpos: " + geolock at (0,1).
print "geolockhead: " +geolock:heading at (0,2).
print "geolockbear: " +geolock:bearing at (0,3).
print "geolockdistance: " +round(geolock:distance) + "m" at (0,4).
print "srfspeed: " +round(surfacespeed) +"m/s" at (0,6).
if abs(geolock:bearing) < 90
{
set trgspeed to srfspdlmt(10).
lock wheelthrottle to trgspeed.
}.
if geolock:distance < 150
{
set trgspeed to srfspdlmt(5).
lock wheelthrottle to trgspeed.
}.
if geolock:distance < 20
{
unlock wheelthrottle.
brakes on.
set orbit to 1.
}.
on ag5 break.
}