I have come up with some pseudo-code to brute force leveling on uneven terrain between four height-adjusting landing legs. The problem is that the universe loves triangles and three points of contact, a limitation I refuse to bow to.
I can’t seem to think my way around how once the object is levelled, there is nothing stopping a single leg from hanging up in the air, and I’m struggling to think of a way around it. This is the flow as I currently have it.
increase = .1 per tick
tolerance = 5 degrees
function Level() runs multiple times until level == true
Get the orientation vector, and get pitch and roll variables.
if roll < tolerance
leftLegs += increase
else if roll > tolerance
rightLegs += increase
else
rollCheck = true
if pitch < tolerance
frontLegs += increase
else if pitch > tolerance
backLegs += increase
else
pitchCheck = true
if pitchCheck and rollCheck then
level = true
return
Take the shortest leg and shorten it to the minimum length, then shorten all the others by an equal amount to ensure the legs stay as retracted as possible.
Please let me know if I’m missing something obvious here.