Jump to content

[PYTHON][LIBRARY][WIP] PyKSP: A Python KSP interface library


Recommended Posts

Presenting...

PyKSP

A Linear, Pythonic KSP API For Telemachus

Get yours today: https://github.com/602p/pyksp

THIS IS A MOD OF A MOD! YOU NEED TELEMACHUS RUNNING TO INTERACT WITH KSP!

Interact with KSP (thru telemachus) using code as simple as

import pyksp,time

vessel=pyksp.WrappedVessel()
vessel.subscribe("vessel_altitude")
vessel.start()
vessel.sas()
time.sleep(2)
vessel.stage()
while 1:
print vessel.vessel_altitude


A quick runthru:

Import pyksp:

import pyksp

Create and start a Vessel object:

v=pyksp.WrappedVessel()
v.subscribe("vessel_altitude")
v.start()

Do whatever LINEAR code jazz you want:

vessel.sas()
time.sleep(2)
vessel.stage()

Receive data WITHOUT even needing to call update:

while 1:
print vessel.vessel_altitude


There are two classes, ActiveVessel, and its subtype WrappedVessel. And they bolth talk to python thru Telemachus (IP and Port configurable!)

ActiveVessel allows you to subscribe_string("vessel_vertical_speed"),do run_command("action_group_3"), and get("resource_lf_max")

WrappedVessel allows you to do vessel.string, and automatically subscribe to it in the background, and additionally do vessel.sas() or vessel.stage()

For both, you can subscribe to any number of strings, representing datapoints. For example, target_periapsis would track the selected vessels periapsis, or resource_xg_current would track the current XenonGas level. For ActiveVessel, you need to first subscribe to a datapoint with

vessel.subscribe("resource_xg_current")

and then get the current value with

vessel.get("rescource_xg_current")

WrappedVessel simplifies this, by allowing you to access datapoints by doing vessel.value (ex vessel.docking_delta_y_angle) and it will automatically subscribe if you are not already.

For both you can run commands with vessel.run_command("brake") or vessel.run_command("abort"). Once again, WrappedVessel simplifies this by allowing you to do vessel.ag1() or vessel.stage().

Here is a list of all datapoint names, but their behavior is dictated by telemachus :confused:

Datapoints and Commands (for ActiveVessel.run_command())

Im sorry if this post is a mess (it kinda is :P ) and Id happily explain it to y'all or have a look at your code!

Edited by Coffeeman
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...