djungelorm

[1.4.x,1.3.x,1.2.2] kRPC: Remote Procedure Call Server (v0.4.7, 27th July 2018)

Recommended Posts

The documentation tells about a streaming port. Some time there was a post about how to add_stream(getattr ... ). add_stream is nowhere documented, though. Is it still required?

Share this post


Link to post
Share on other sites
@djunglelorm can you quickly once-over how extending the services of KRPC works? I'd love to add support to DangIt! at some point.

It's quite simple, you just need to annotate your classes/methods/etc. with C# attributes provided in the KRPC.Service.Attributes namespace. kRPC will scan all the DLLs loaded by the game for these attributes to add the functionality to the server. There are also a few restrictions on the structure/types of the classes/methods etc. It's documented here: http://djungelorm.github.io/krpc/docs/extending.html

For fully fledged examples, take a look at kRPCKerbalAlarmClock (https://github.com/djungelorm/krpc/tree/master/src/kRPCKerbalAlarmClock) or kRPCInfernalRobotics (https://github.com/djungelorm/krpc/tree/master/src/kRPCInfernalRobotics) which add services for the KAC and IR mods.

- - - Updated - - -

The documentation tells about a streaming port. Some time there was a post about how to add_stream(getattr ... ). add_stream is nowhere documented, though. Is it still required?

Streams aren't properly documented yet, but they are used in this tutorial which should give you some hints on how to use them: http://djungelorm.github.io/krpc/docs/tutorials/launch-into-orbit.html

They aren't required, they just provide a more efficient way to get data out of KSP in a continuous fashion without having to invoke repeated remote calls.

- - - Updated - - -

Is there a way to set the warp factor (0-7) using kRPC?

No, currently the only control over warping is space_center.warp_to(ut). Sounds like something that should be added though, so I'll put it on the todo list for the next version.

- - - Updated - - -

No there is no error being reported in the log file. And the bug happens really frequently for me. it happens when i revert to launch a few times. or at times even right when i go to the launch pad with a new craft.

OK, I'll investigate... Added an issue for this on github here: https://github.com/djungelorm/krpc/issues/133

Edited by djungelorm
Add more detail to response...

Share this post


Link to post
Share on other sites
Are there any other mods people would be interested in having access to via kRPC?

What about RemoteTech?

Share this post


Link to post
Share on other sites

Two more things:

1. Also I noted the connect() call has features - like using a different IP address - which are not documented.

2. the krpc namespace has functions - like get_status() - which are not documented.

Please add to the github.io manual.

NB: working on migrating my mission toolkit from http://kos.wikia.com/wiki/Mission_toolkit_v3

Share this post


Link to post
Share on other sites
What about RemoteTech?

It already is ;)http://djungelorm.github.io/krpc/docs/python-api/space-center/comms.html

- - - Updated - - -

Two more things:

1. Also I noted the connect() call has features - like using a different IP address - which are not documented.

2. the krpc namespace has functions - like get_status() - which are not documented.

Please add to the github.io manual.

Will do! The client and krpc service are only documented via the tutorials at the moment, reference docs are indeed missing.

NB: working on migrating my mission toolkit from http://kos.wikia.com/wiki/Mission_toolkit_v3

Awesome :) Keen to see how it turns out!

Share this post


Link to post
Share on other sites
The documentation tells about a streaming port. Some time there was a post about how to add_stream(getattr ... ). add_stream is nowhere documented, though. Is it still required?
Two more things:

1. Also I noted the connect() call has features - like using a different IP address - which are not documented.

2. the krpc namespace has functions - like get_status() - which are not documented.

Please add to the github.io manual.

I've started adding documentation for this here: http://djungelorm.github.io/krpc/docs/python-client.html

Share this post


Link to post
Share on other sites

Unless I totally misread the docs last time (a assumption I will not dismiss too eagerly) this looks like a major update with tons of new properties. Atmospheric flight now seems to expose a lot of properties (like terminal velocity -- so a kRPC script can throttle back where needed)

AWESOME!!!

Is there any way to determine the longitude (and lattitude maybe too)? I'd like to use it to time re-entry for landings at the KSC.

Share this post


Link to post
Share on other sites

You didn't misread - I've added lots of new aero functionality in line with the changes from KSP 1.0 :)

And you can get the current latitude and longitude by calling vessel.flight().latitude and vessel.flight().longitude

http://djungelorm.github.io/krpc/docs/python-api/space-center/flight.html#Flight.latitude

Edited by djungelorm
fix link

Share this post


Link to post
Share on other sites

I like the way reference frames are designed. It is so much more explicit and cleaner than in kOS. Fun to work with.

Share this post


Link to post
Share on other sites
No there is no error being reported in the log file. And the bug happens really frequently for me. it happens when i revert to launch a few times. or at times even right when i go to the launch pad with a new craft.

I'm unable to reproduce this. Can you provide me with more details? Are you on Windows/Linux? What version of KSP/kRPC/KER/KAC are you using? Do you still have issues with just kRPC installed (without KER and KAC installed)? Could you maybe provide a save file with a list of steps to reproduce the bug?

Share this post


Link to post
Share on other sites

Are minor performance hits normal with this? all I have installed is hyperedit (for testing on my dev save) and this.

running ubuntu 15.04 with ksp 1.0.2

Share this post


Link to post
Share on other sites

I also have the disappearing guis issue.

(Silly) Reproduction steps:

-Start ksp

-start a new career game

-enter VAB

-If the name bar is not missing (typical first symptom), exit and reenter VAB. Or go into flight and revert back. Until it's triggered. Never took more than 5 times, if that much.

I put a log extract in the github issue, which indicates its reproduction is dependent on system variables rather than procedure.

Short version: kRPC is not catching a System.Net.NetworkInformation.NetworkInformationException thrown on the callstack of RenderingManager.OnGUI ()

Unless that's an unrelated error, which is spamming the log anyway.

Share this post


Link to post
Share on other sites

I've added a fix to catch the exception, which should hopefully fix the UI disappearing issue. Could you test it out for me as I'm unable to reproduce it on my system? Here's a version with the fix: https://github.com/djungelorm/krpc/releases/tag/v0.1.9-ui-fix

- - - Updated - - -

Are minor performance hits normal with this? all I have installed is hyperedit (for testing on my dev save) and this.

running ubuntu 15.04 with ksp 1.0.2

Yes, performance is kinda bad with 0.1.9, but should improve drastically in 0.1.10 thanks to a bunch of changes to the main server loop. If you want details and a pre-release to play around with, see here: https://github.com/djungelorm/krpc/releases/tag/v0.1.10-pre-performance

Share this post


Link to post
Share on other sites

Is there a way to determine when your vehicle has crashed? I see that you added various vessel status streams (splashed, landed, prelaunch,...) from Vessel.situation, but could you also add a stream for whether a vehicle has crashed? I don't know how difficult it would be to implement one of the GameEvents callbacks..

Thanks

Share this post


Link to post
Share on other sites

This is very exciting! Forgive me if this is mentioned elsewhere in this thread, but is there a kind of library or eco system of sorts of scripts people did for kRPC? One of the benefits of KOS is that whatever you want to do with it, you'll probably find code that does something similar, and if not, you're probably trying to do something that is just not possible easily.

I feel that a place to share works would help a lot when writing new scripts. For example, I recently looked into pyKEP - anyone else thought about using it together with KSP?

Share this post


Link to post
Share on other sites
This is very exciting! Forgive me if this is mentioned elsewhere in this thread, but is there a kind of library or eco system of sorts of scripts people did for kRPC? One of the benefits of KOS is that whatever you want to do with it, you'll probably find code that does something similar, and if not, you're probably trying to do something that is just not possible easily.

I feel that a place to share works would help a lot when writing new scripts. For example, I recently looked into pyKEP - anyone else thought about using it together with KSP?

Stay tuned on this. I have a working "proof-of-principal" python module which can be used with krpc. It is very much like pyKEP but geared for KSP - and much more "pythonic" in the sense that my only dependency is numpy/scipy (though I'm using python version 3 and have no time/desire to back-port it to 2.x). I have maps with ground tracks and I'm working on interstellar calculations. I recently went into the code and started a major clean-up so it has been delayed a bit.

The main power of the module is in its predictions. You should be able to calculate/plot an orbit patch outside of KSP (i.e. in a separate thread). For example: this module can get the state vector (or orbital elements) using krpc and from there can tell you the latitude and longitude the vessel will be over at periapsis - very useful for landing in the right ocean on return from the Mun!

When I do finally release it, I'll post in this thread. It will be available on github.

Share this post


Link to post
Share on other sites

Lorentz !!!!!!!!! Looking forward to it send me a PM when you upload a alpha I will check out

Also great mod so amazing, it can be used for a lot of things.

Edited by mikes3ds
Added something

Share this post


Link to post
Share on other sites
This is very exciting! Forgive me if this is mentioned elsewhere in this thread, but is there a kind of library or eco system of sorts of scripts people did for kRPC? One of the benefits of KOS is that whatever you want to do with it, you'll probably find code that does something similar, and if not, you're probably trying to do something that is just not possible easily.

I feel that a place to share works would help a lot when writing new scripts. For example, I recently looked into pyKEP - anyone else thought about using it together with KSP?

There isn't a collection of scripts anywhere yet - but I agree it'd be very useful to set something up! Maybe a wiki linked from the documentation website and on here?

The only existing example scripts I know of are those in the tutorials on the documentation site, and a couple of scripts which I've put on github here: https://github.com/djungelorm/krpc-toolkit

Share this post


Link to post
Share on other sites

New to kRPC/Python and having trouble returning the current throttle value of my engines. Tried various combination of .parts/.part/.engine/.engine but met with various errors mainly pointing to it can't find the "throttle" attribute. The following line is attempting to print the current throttle % in the console. Do I need to setup a stream for this?

print ('Throttle % = %f' % vessel.parts.engines.throttle)

Thanks,

Share this post


Link to post
Share on other sites
New to kRPC/Python and having trouble returning the current throttle value of my engines. Tried various combination of .parts/.part/.engine/.engine but met with various errors mainly pointing to it can't find the "throttle" attribute. The following line is attempting to print the current throttle % in the console. Do I need to setup a stream for this?

print ('Throttle % = %f' % vessel.parts.engines.throttle)

Thanks,

Welcome!

To get the main throttle (the same as the one displayed on the HUD) you want vessel.control.throttle, e.g.:

print ('Throttle % = %f' % vessel.control.throttle)

vessel.parts.engine returns a list of engine objects. Each one has a (read-only) throttle property that returns the throttle setting for that specific engine. E.g. to print out the throttle of each individual engine:


for engine in vessel.parts.engines:
print engine.throttle

.part and .parts return generic part objects that don't have a throttle property.

Hope that helps!

Share this post


Link to post
Share on other sites

Version 0.1.10 has been released!

Download link: https://kerbalstuff.com/mod/636/kRPC:%20Remote%20Procedure%20Call%20Server

The main changes are:

  • KSP 1.0.4 compatible
  • Major performance improvements
  • Any vessel within physics range of the active one can now be controlled!
  • Improved time warp functionality
  • Support for radiator parts
  • Lots of bug fixes (including the UI disappearing bug)

There is also an (experimental) Lua client, available here: https://luarocks.org/modules/djungelorm/krpc It's almost feature complete (just missing streams and documentation...)

Enjoy!

Share this post


Link to post
Share on other sites

Hey guys, I have been plugging away at a more complete toolkit for krpc. I put it all on github here

https://github.com/theodoregoetz/wernher

There is virtually no documentation as yet and it is only tested with python version 3. It will probably not work at all with python v2. It uses newton's method (scipy.optimize.newton) to solve for universal anomaly and calculates the Lagrange coefficients, but it can fall back to eccentric/mean anomaly calculations if you want. It makes heavy use of unicode. Here is a short example (let's say you put the python module directory under your PYTHONPATH):


import numpy as np
from matplotlib import pyplot

import krpc, wernher

def orbit_from_krpc_orbit(ksc,obt):
body = wernher.CelestialBody(
name = obt.body.name,
gravitational_parameter = obt.body.gravitational_parameter,
equatorial_radius = obt.body.equatorial_radius,
rotational_speed = obt.body.rotational_speed)
return wernher.Orbit(
t0 = ksc.ut,
i = obt.inclination,
Ω = obt.longitude_of_ascending_node,
̉ۡ = obt.argument_of_periapsis,
e = obt.eccentricity,
a = obt.semi_major_axis,
M0 = obt.mean_anomaly_at_epoch,
body = body)


conn = krpc.connect(name='laptop0', address='192.168.1.9')
ksc = conn.space_center
vessel = ksc.active_vessel
obt = vessel.orbit

o = orbit_from_krpc_orbit(ksc,obt)
t0 = o.epoch
t = np.linspace(t0,t0+1*60*60,200)
lat = o.latitude_at_time(t)
lon = o.longitude_at_time(t)
pyplot.plot(lat,lon)
pyplot.show()

This should show you the latitude and longitude of the active vessel for the next hour. This includes accounting for the rotation of the orbited body. One problem I have is that I need the right ascension of the prime meridian for each of the planets - I've only just measured these quantities in-game, using kerbal engineer, for Kerbin (0 deg), Minmus (140 deg) and Dres (-65 deg). If anyone knows how I get this information from an outside source, please let me know!

Edited by Lorentz

Share this post


Link to post
Share on other sites

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.