Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python API: connection stream not working? #24

Open
duchenpaul opened this issue May 26, 2023 · 6 comments
Open

Python API: connection stream not working? #24

duchenpaul opened this issue May 26, 2023 · 6 comments
Labels
bug Something isn't working core krpc Caused by core kRPC mod

Comments

@duchenpaul
Copy link

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
Copy link
Author

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

@afnanwioe456
Copy link

I've met the same problem.

@Genhis
Copy link
Owner

Genhis commented Jan 10, 2024

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

@afnanwioe456
Copy link

afnanwioe456 commented Jan 11, 2024 via email

@Genhis
Copy link
Owner

Genhis commented Jan 15, 2024

This is a krpc issue: krpc/krpc#763

@Genhis Genhis added bug Something isn't working core krpc Caused by core kRPC mod labels Jan 15, 2024
@djungelorm
Copy link

Should be fixed in kRPC 0.5.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working core krpc Caused by core kRPC mod
Projects
None yet
Development

No branches or pull requests

4 participants