Genhis / KRPC.MechJeb

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

Python API: connection stream not working? #24

Open duchenpaul opened 1 year ago

duchenpaul commented 1 year ago

Describe the bug

I am trying the dem0 python code Advanced Launch into Orbit, and encountered errors, looks like a bug to me.

Code snippet to reproduce it (ideally in Python)

import logging

def ascending(conn):
    sc = conn.space_center
    mj = conn.mech_jeb
    ascent = mj.ascent_autopilot

    ascent.desired_orbit_altitude = 100000
    ascent.desired_inclination = 0

    ascent.force_roll = True
    ascent.vertical_roll = 90
    ascent.turn_roll = 90

    ascent.ascent_path_index = 0  # use AscentClassic as the ascent path

    path = ascent.ascent_path_classic
    path.turn_shape_exponent = 0.5  # set the turn shape to 50%
    path.auto_path = False  # don't use autopath
    path.turn_start_altitude = 3000
    path.turn_start_velocity = 120
    path.turn_end_altitude = 65000

    ascent.autostage = False
    ascent.enabled = True

    with conn.stream(getattr, ascent, "enabled") as enabled:
        enabled.rate = 1  # we don't need a high throughput rate, 1 second is more than enough
        with enabled.condition:
            while enabled():
                enabled.wait()

    print("Launch complete!")
    conn.close()

if __name__ == "__main__":
    conn = krpc.connect(
    name=config['krpc']['name'],
    address=config['krpc']['address'],
    rpc_port=config['krpc']['rpc_port'],
    stream_port=config['krpc']['stream_port'],)

    ascending(conn)

Error is:

Traceback (most recent call last):
  File "C:\Users\duche\Desktop\project\ksp_scripts\ascending\ascending.py", line 50, in <module>
    ascending(conn)
  File "C:\Users\duche\Desktop\project\ksp_scripts\ascending\ascending.py", line 28, in ascending
    with conn.stream(getattr, ascent, "enabled") as enabled:
  File "C:\Users\duche\AppData\Local\Programs\Python\Python310\lib\contextlib.py", line 135, in __enter__
    return next(self.gen)
  File "C:\Users\duche\AppData\Local\Programs\Python\Python310\lib\site-packages\krpc\client.py", line 108, in stream 
    stream = self.add_stream(func, *args, **kwargs)
  File "C:\Users\duche\AppData\Local\Programs\Python\Python310\lib\site-packages\krpc\client.py", line 100, in add_stream
    return_type = self._get_return_type(func, *args, **kwargs)
  File "C:\Users\duche\AppData\Local\Programs\Python\Python310\lib\site-packages\krpc\client.py", line 184, in _get_return_type
    return cast(TypeBase, return_type_fn())
TypeError: 'ValueType' object is not callable

Expected behavior

Expected this code can continuously check the status of asent:

    with conn.stream(getattr, ascent, "enabled") as enabled:
        enabled.rate = 1  # we don't need a high throughput rate, 1 second is more than enough
        with enabled.condition:
            while enabled():
                enabled.wait()

Screenshots

Version details kRPC.MechJeb: v0.7.0

Kerbal Space Program: 1.12.5.3190 kRPC: v0.5.2 MechJeb2: 2.14.3.0

duchenpaul commented 1 year ago

Tried pip package krpc==0.5.0 and 0.5.2, it does not have such problem

afnanwioe456 commented 8 months ago

I've met the same problem.

Genhis commented 8 months ago

Apologies, I somehow missed this issue. Just to check, are you using latest python krpc version (0.5.3)?

afnanwioe456 commented 8 months ago

Yes, I also tried the previous versions and encountered the same issue when initially writing the "Launch into Orbit" tutorial. It seems that the kRPC stream is not the issue.

Genhis @.***> 于2024年1月11日周四 04:33写道:

Apologies, I somehow missed this issue. Just to check, are you using latest python krpc version (0.5.3 https://pypi.org/project/krpc/0.5.3/)?

— Reply to this email directly, view it on GitHub https://github.com/Genhis/KRPC.MechJeb/issues/24#issuecomment-1885677876, or unsubscribe https://github.com/notifications/unsubscribe-auth/A6VBS3EV53DUGCLZXOQVNVDYN33H5AVCNFSM6AAAAAAYQIHRN2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOBVGY3TOOBXGY . You are receiving this because you commented.Message ID: <Genhis/KRPC. @.***>

Genhis commented 8 months ago

This is a krpc issue: https://github.com/krpc/krpc/issues/763

djungelorm commented 3 months ago

Should be fixed in kRPC 0.5.4