kRPC: Control the game using C#, C++, Java, Lua, Python...

kRPC: Control the game using C#, C++, Java, Lua, Python...

7.8k Downloads

Incorrect velocity with hybrid reference frame

djungelorm opened this issue ยท 6 comments

commented

From @LIAOTIANx

Another new problem, it seems that the function create_hybrid() just works for [position] and [rotation] parameters.
I tested the following codes:

ref_frame = conn.space_center.ReferenceFrame.create_hybrid(
position=vessel.orbit.body.reference_frame,
rotation=vessel.surface_reference_frame,
angular_velocity=vessel.orbit.body.surface_reference_frame)

velocity = vessel.flight(ref_frame).velocity
speed = math.sqrt((velocity[0]*velocity[0]+velocity[1]*velocity[1]+velocity[2]*velocity[2]))
print('Surface velocity = (%.2f, %.2f, %.2f)' % velocity)
print('Surface speed = %.2f' % speed)

it should output a velocity without horizontal components because the X-axis always points to the vessel.
However, it outputs a result the same as the function without the angular_velocity parameter:

ref_frame = conn.space_center.ReferenceFrame.create_hybrid(
position=vessel.orbit.body.reference_frame,
rotation=vessel.surface_reference_frame)

another test also exists the same problem:

ref_frame = conn.space_center.ReferenceFrame.create_hybrid(
position=vessel.orbit.body.reference_frame,
rotation=vessel.surface_reference_frame,
angular_velocity=vessel.orbit.body.non_rotating_reference_frame)
commented

problem2 - a problem about function surface_position()

landing_latitude = vessel.flight(body.reference_frame).latitude
landing_longitude = vessel.flight(body.reference_frame).longitude
height = 9 

landing_position = body.surface_position(
    landing_latitude, landing_longitude, body.reference_frame)
q_long = (0,-sin(landing_longitude * 0.5 * pi / 180),0,cos(landing_longitude * 0.5 * pi / 180))
q_lat = (0,0,sin(landing_latitude * 0.5 * pi / 180),cos(landing_latitude * 0.5 * pi / 180))
landing_reference_frame = \
    create_relative(
        create_relative(
            create_relative(body.reference_frame,landing_position,q_long),
            (0, 0, 0),q_lat),
        (height, 0, 0))

X=conn.drawing.add_line((0, 0, 0), (100, 0, 0), landing_reference_frame)
X.color=(1, 0, 0) 
Y=conn.drawing.add_line((0, 0, 0), (0, 100, 0), landing_reference_frame)
Y.color=(0, 1, 0)
Z=conn.drawing.add_line((0, 0, 0), (0, 0, 100), landing_reference_frame)
Z.color=(0, 0, 1) 

I designed a reference frame fixed at launch point, and find the position is not the corresponding position of water lever. It's more likely a position of local ground (but not exactly).

problem2

The frame neither locates on the launch platform nor the center of mass of vessel.

commented

@LIAOTIANx I've just released a new version of the mod with support for the latest KSP 1.12.5. Could you try with that and see if these issues still exist?

commented

I just tested scripts with new version of kRPC. but it still exists the same problem.

It seems that the angular velocity can be only set by the parameter [position ReferenceFrame] in function create_hybrid().

commented

The problem2 has been solved perfectly.

The launch frame locates on the platform with zero height.

landing_latitude = vessel.flight(body.reference_frame).latitude
landing_longitude = vessel.flight(body.reference_frame).longitude
height = 0 
landing_position = body.surface_position(
    landing_latitude, landing_longitude, body.reference_frame)
q_long = (0,-sin(landing_longitude * 0.5 * pi / 180),0,cos(landing_longitude * 0.5 * pi / 180))
q_lat = (0,0,sin(landing_latitude * 0.5 * pi / 180),cos(landing_latitude * 0.5 * pi / 180))
landing_reference_frame = \
    create_relative(
        create_relative(
            create_relative(body.reference_frame,landing_position,q_long),
            (0, 0, 0),q_lat),
        (height, 0, 0))

problem2
problem2-2

So surface_position() actually returns a position with height on the surface of launch platform if the vessel is on the platform, and returns a position with height on the ground surface for other cases.

commented

I think this might be the same issue as #454 ?

commented

Yes that looks to be related. I'll work on a fix for #454 and then we can see if it resolves this too