Genhis / KRPC.MechJeb

kRPC service for MechJeb2 (Kerbal Space Program)
https://genhis.github.io/KRPC.MechJeb/
GNU General Public License v3.0
15 stars 8 forks source link

AscentAutopilot launch to rendezvous can not run #8

Closed SkyEagle8352 closed 4 years ago

SkyEagle8352 commented 4 years ago

Describe the bug

When calling the function launch_to_rendezvous(using the python), it reported an error as shown in the following part. But I can operate it by hand in MJ's UI. I want to know how to call the function launch_to_rendezvous by code. Code snippet to reproduce it (ideally in Python)

import math
import time
import krpc

conn = krpc.connect(name='sim_demo')
vessel = conn.space_center.active_vessel
space_center = conn.space_center
mech_jeb = conn.mech_jeb
mj_ascent = mech_jeb.ascent_autopilot

for i in conn.space_center.vessels:
    if(i.name == "target"):
        target = i
conn.space_center.target_vessel = target
conn.mech_jeb.ascent_autopilot.warp_count_down = 10
conn.mech_jeb.ascent_autopilot.launch_phase_angle = 24
conn.mech_jeb.ascent_autopilot.launch_to_rendezvous()

Screenshots Traceback (most recent call last): File "C:\Users\XXX\KSP_simulation\test\test.py", line 17, in conn.mech_jeb.ascent_autopilot.launch_to_rendezvous() File "", line 1, in File "C:\Users\XXX\AppData\Local\Programs\Python\Python36\lib\site-packages\krpc\client.py", line 163, in _invoke raise self._build_error(response.results[0].error) krpc.error.RPCError: Object reference not set to an instance of an object Server stack trace: at KRPC.MechJeb.LaunchTiming.TimeToPhaseAngle (System.Double launchPhaseAngle) [0x0003c] in :0

at KRPC.MechJeb.AscentAutopilot.LaunchToRendezvous () [0x00020] in :0

at (wrapper managed-to-native) System.Reflection.MonoMethod.InternalInvoke(System.Reflection.MonoMethod,object,object[],System.Exception&)

at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00032] in :0

Version details kRPC.MechJeb: 0.5.0

Kerbal Space Program: 1.9 kRPC: 0.4.8 MechJeb2: 2.9.1.0

Genhis commented 4 years ago

Thank you for reporting the issue, I will look into it.

Genhis commented 4 years ago

Fixed. Don't forget to engage the autopilot by setting enabled = True after launch_to_rendezvous() call - basically the same way as you would do in GUI. :-)