untoldwind / KontrolSystem2

Autopilot scripting system for KSP2
Other
54 stars 14 forks source link

Body coordinate systems are inconsistent #157

Closed versvisa closed 2 months ago

versvisa commented 2 months ago

Hello, there seems to be some inconsistency in body coordinate systems. The following screenshots show the output of this code

CONSOLE.print_line("north " + vessel.global_north.to_local(vessel.body_frame).to_fixed(4))
CONSOLE.print_line("east  " + vessel.global_east.to_local(vessel.body_frame).to_fixed(4))
CONSOLE.print_line("up    " + vessel.global_up.to_local(vessel.body_frame).to_fixed(4))

In each case the vessel is oriented such that north, east and up are lined up with body-X, body-Y and body-Z respectively. Thus, according to KS2 they are in the same orientation. But according to the navball and 3D visual they are in different orientations.

img1

img2

untoldwind commented 2 months ago

It should match up in the vessel.control_frame. I suppose this is something of a left-over from KSP1 where cockpit had been tilted by 90 degrees.

versvisa commented 2 months ago

Some more testing shows that the body_frame is directly affected by the VAB/spawn orientation. It can be at any odd angle.

In the control_frame the values are consistent with the navball. Some testing shows that the body axes are [X,Y,Z] = [right, forward, down] ~[forward, right, down]~. Could this be added to the documentation? I think in KSP1 the axes body were [right, up, forward]. So this is a little sursprising.

untoldwind commented 2 months ago

This hierarchy of transformation frame is something of a new invention in KSP2, so some inconsistencies are to be expected I guess.

Here is a little test-script for experimentation:

use { Vessel } from ksp::vessel
use { CONSOLE, RED, WHITE } from ksp::console
use { sleep } from ksp::game
use { DEBUG } from ksp::debug
use { vec3 } from ksp::math

pub fn main_flight(vessel: Vessel) -> Result<Unit, string> = {
    CONSOLE.clear()

    CONSOLE.print_line($"Time: {current_time()}")

    DEBUG.add_vector(fn() -> vessel.global_position, fn() -> vec3(0,10,0).to_global(vessel.body_frame), RED, "up1", 2)
    DEBUG.add_vector(fn() -> vessel.global_position, fn() -> vec3(0,10,0).to_global(vessel.control_frame), WHITE, "up2", 2)

    sleep(10000) // Just keep the vectors up for a while
}

From what I can tell: