autopilot roll behavior is not clear and is not well described
mrantmet opened this issue ยท 0 comments
I'd like to highlight suprizing (for me at least) and timewasting experience with the way how krpc autopilot handles roll depending on how far its direction is from the vertical one.
the goal is to be able to launch rockets in any initial orientation and keep that orientation all the way to orbit. I'm using KSP 1.7.3 and here is the small code example to answer possible questions about reference frame, target direction, roll settings etc.
import krpc
import time
conn = krpc.connect()
vessel = conn.space_center.active_vessel
body = vessel.orbit.body
target_direction = (1, 0, 0)
ref_frame = vessel.surface_reference_frame
vessel.auto_pilot.reference_frame = ref_frame
vessel.auto_pilot.target_direction = (1, 0, 0)
vessel.auto_pilot.target_roll = 180
vessel.control.throttle = 1
vessel.control.activate_next_stage()
vessel.auto_pilot.engage()
while True:
roll_error = vessel.auto_pilot.roll_error
current_roll = vessel.flight(vessel.auto_pilot.reference_frame).roll
print("my roll error =", roll_error)
print("my flight roll =", current_roll)
time.sleep(0.5)
I noticed that when rocket just left the launchpad and ascending upwards then the 0 roll seems to be an orientation when "up" (roof of the capsule) of the rocket is pointing to the north. But, if to start pitching sufficiently enough, e.g.:
vessel.auto_pilot.target_direction = (0.997, 0, 0.003)
then the roll is seems to be an angle between the "up" of the rocket and the plane going through vessel direction and upward direction (not between the the "up" of the rocket and normal to that plane as confusingly described in this example https://krpc.github.io/krpc/tutorials/pitch-heading-roll.html, or maybe I'm wrong somewhere).
so basically the issue of keeping the rocket's attitude happens when it starts pitching and the angle is sufficient enough.
There are 2 workarounds I see for myself here:
- use the minimal pitching from the beginning
- use target_roll = 90 when ascending upwards and re-set it to target_roll = 180 when pitching east (e.g. I have mk1 pod windiow points to east, "up" to west and want to keep that orientation, so Jeb could see the Kerbin beneath from the window)
I understand there should be some definition of 0 roll for vertical position but please make it possible to at least turn the roll off. Unfortunatelly not setting the target_roll (NaN) at all is not an option despite the documentation claims it should make autopilot to supress rolling i.e. keep it and not rotate the vessel. No, it still rolls by some internal logic and that makes this option completelly useless to me. I'd say this is a bug - there must be a way to supress any roll or to specify not a scalar angle but a vector/direction which the autopilot should align the "up" of the rocket with as it is done in KoS.
Issue is 100% reproducible and doesn't depend on the craft. mk1 pod + fl-t800 tank + lv-t45 will do. I just played with target_direction and target_roll in the example above to determine the described behaviour.
By the way, vessel.auto_pilot.roll_error seems to return some pointless big values even when there is no visible error, so there is something wrong with this parameter too.