djungelorm

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

Recommended Posts

Anyone know how I could get this working with PowerShell? Not sure but I might be able to use the C# library, just not sure how.

Share this post


Link to post
Share on other sites

Powershell supports all the fineries of .NET (including inline compiling of C# code), so you'd be using the C# client library package and probably something like

Add-Type -Path "path\to\KRPC.Client.dll" 
$connection = New-Object KRPC.Client.Connection -ArgumentList "Powershell Client"
# etc.

 

 

 

Share this post


Link to post
Share on other sites

Great. Thanks for that; sounds like just the start I needed.

Share this post


Link to post
Share on other sites

I'm just following a Python programming course, so I had to try this plugin. I managed to use it quite easily and I've made a video about it.

 

Edited by BaryonicMan

Share this post


Link to post
Share on other sites

Bug!!!

C# function vessel.Flight().Speed/VerticalSpeed/HorizintalSpeed return 0.

version: KRPC.Client 0.35 -pre

upd:

I connected with another PC via LAN

Edited by Leroki

Share this post


Link to post
Share on other sites
8 minutes ago, Leroki said:

C# function vessel.Flight().Speed/VerticalSpeed/HorizintalSpeed return 0.

Take a look at the docs regarding Reference Frames.

Namely, the default reference frame for Flight is the vessel's surface reference frame.  The origin of this reference frame is located at the origin of the vessel.  In otherwords: from the vessel's perspective, the vessel will always have 0 velocity.

From Kerbin's perspective, that might be different.  And from Kerbol's perspective, that will be very, very different.

 

 

Share this post


Link to post
Share on other sites
52 minutes ago, dewin said:

Take a look at the docs regarding Reference Frames.

Namely, the default reference frame for Flight is the vessel's surface reference frame.  The origin of this reference frame is located at the origin of the vessel.  In otherwords: from the vessel's perspective, the vessel will always have 0 velocity.

From Kerbin's perspective, that might be different.  And from Kerbol's perspective, that will be very, very different.

 

 

Thank you for helping to understand!

Share this post


Link to post
Share on other sites

Is there a way to get ground slope? If it's already there I haven't been able to find it.

Great mod, thanks for all your efforts.

Share this post


Link to post
Share on other sites

Hi @djungelorm!

I'm currently in the planning stage of hardware modules for my new control panel and had these crazy ideas about being able to pump fuel around or control docking ports using actual switches that say "click". A problem is that there's no way to identify which part is selected as all docking ports and fuel tanks of the same type have identical names.

Would it be possible to add a function in the Parts class for turning highlighting off and on for a specific part?

Pretty please with sugar on top? :kiss:

Share this post


Link to post
Share on other sites

I've been a bit busy the past few weeks, but that's over now so will have time to work on the mod :)

On 8/1/2016 at 10:08 PM, Crashtack said:

Is there a way to get ground slope? If it's already there I haven't been able to find it.

Great mod, thanks for all your efforts.

Not directly, but you could calculate it by getting the surface height at different positions using CelestialBody.SurfaceHeight(latitude, longitude) Might be nicer if we add an RPC to get a the normal vector of the surface under the vessel (or at some arbitrary position)?

On 8/8/2016 at 5:30 AM, Antipaten said:

Would it be possible to add a function in the Parts class for turning highlighting off and on for a specific part?

Sure thing! I'm also looking into being able to name parts, by reusing kOS's part tagging dialog.

Share this post


Link to post
Share on other sites

Any recommendation on what client library to use? I see that sometimes Java is updated late compared to C#. Is it always the case? Any advantage to using particular language? KSP itself is written in C#, so would using C# be better just in case I like to interact directly with KSP in the future?

Share this post


Link to post
Share on other sites
On 9/6/2016 at 9:54 PM, gowthamn said:

Any recommendation on what client library to use? I see that sometimes Java is updated late compared to C#. Is it always the case? Any advantage to using particular language? KSP itself is written in C#, so would using C# be better just in case I like to interact directly with KSP in the future?

The choice is pretty much one of personal taste, and the pros and cons the language for your particular use case, not the client library itself. For example, if you want the maximum bare metal performance, go for the C++ client, as C++ is compiled to a native executable. If you want an interactive environment, fire up a python console and use that. If you have some existing C# math library you want to make use of, use the C# library.

Internally, the client libraries all work in the same way. The fact that KSP is written in C# doesn't affect the choice of client language. The clients all use the same approach to serialize requests and send data over a network socket.

Apart from the Lua client (which doesn't support streams) all the client libraries are feature complete. They are also all thoroughly tested (with continuous integration and unit tests).

Not sure why you say the Java client is updated late? The Java client was the most recent addition so might not be as mature as the others. All the client libraries are updated when bugs are found, and then released in lock step with the server plugin release - so that all the version numbers match to keep things simple.

Share this post


Link to post
Share on other sites

Can I control multiple vessels? Like I want to programmatically do what SpaceX does. After separation I want to use 2 threads / connections to control the landing of first stage and putting the 2nd stage in orbit at the same time. Is that possible?

Share this post


Link to post
Share on other sites
Just now, gowthamn said:

Can I control multiple vessels? Like I want to programmatically do what SpaceX does. After separation I want to use 2 threads / connections to control the landing of first stage and putting the 2nd stage in orbit at the same time. Is that possible?

Yes, you can control multiple vessels. However, they must be within physics range of the active vessel. Otherwise, KSP puts their physics simulation "on rails" and you can't control them. I think the default physics range is 22.5km. You can get hold of other vessels via the space_center.vessels list and then control them using their control object.

Share this post


Link to post
Share on other sites
2 hours ago, djungelorm said:

Yes, you can control multiple vessels. However, they must be within physics range of the active vessel. Otherwise, KSP puts their physics simulation "on rails" and you can't control them. I think the default physics range is 22.5km. You can get hold of other vessels via the space_center.vessels list and then control them using their control object.

22.5 KM is too small to do a spacex type landing and launching the satellite and the same time :(. Any other way of making this work?

Share this post


Link to post
Share on other sites
41 minutes ago, gowthamn said:

22.5 KM is too small to do a spacex type landing and launching the satellite and the same time :(. Any other way of making this work?

Launch using an ssto and land it after releasing the payload (which is done once in orbit). Your launch script could include deployment and a reentry burn (and the actual landing).

Edited by Kerbart

Share this post


Link to post
Share on other sites

Maybe this is a bug? I was trying out the orbit tutorial and the node creation always fails, here is the tl dr to reproduce

 

# Set up streams for telemetry

import krpc, time, math

conn = krpc.connect(name='Launch into orbit')
vessel = conn.space_center.active_vessel




ut = conn.add_stream(getattr, conn.space_center, 'ut')
altitude = conn.add_stream(getattr, vessel.flight(), 'mean_altitude')
apoapsis = conn.add_stream(getattr, vessel.orbit, 'apoapsis_altitude')
periapsis = conn.add_stream(getattr, vessel.orbit, 'periapsis_altitude')
eccentricity = conn.add_stream(getattr, vessel.orbit, 'eccentricity')

print('Calculating circular burn')
mu = vessel.orbit.body.gravitational_parameter
r = vessel.orbit.apoapsis
a1 = vessel.orbit.semi_major_axis
a2 = r
v1 = math.sqrt(mu*((2./r)-(1./a1)))
v2 = math.sqrt(mu*((2./r)-(1./a2)))
delta_v = v2 - v1
node = vessel.control.add_node(vessel.orbit.time_to_apoapsis, prograde=delta_v)

 

The burn is actually at the end of the script but I shortened it to reproduce the error, it fails with

 

Calculating circular burn
Traceback (most recent call last):
  File "FirstOrbit.py", line 25, in <module>
    node = vessel.control.add_node(vessel.orbit.time_to_apoapsis, prograde=delta_v)
  File "<string>", line 1, in <lambda>
  File "C:\Python35\lib\site-packages\krpc\client.py", line 88, in _invoke
    raise RPCError(response.error)
krpc.error.RPCError: Object reference not set to an instance of an object

I can't tell if its a krpc problem or a me problem.

Share this post


Link to post
Share on other sites

NEVER MIND.

I was under the impression that 0.3.6 was the 1.2 update, and it's not. It was released before that, and the experimental krpc-0.3.6-16-g7940236.zip works just fine. Thank you @djungelorm!!

 

 

I hate to be the bearer of bad news, but kRPC is not loading at all on my machine. Using the 1.2 1586 build nothing shows up when playing the game. I did find this in the log:

[ERR 10:31:46.551] AssemblyLoader: Exception loading 'KRPC': System.Reflection.ReflectionTypeLoadException: The classes in the module cannot be loaded.
  at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool)
  at System.Reflection.Assembly.GetTypes () [0x00000] in <filename unknown>:0 
  at AssemblyLoader.LoadAssemblies () [0x00000] in <filename unknown>:0 

Additional information about this exception:

 System.TypeLoadException: Could not load type 'KRPC.Addon' from assembly 'KRPC, Version=0.3.6.0, Culture=neutral, PublicKeyToken=null'.

 System.TypeLoadException: Could not load type 'KRPC.UI.MainWindow' from assembly 'KRPC, Version=0.3.6.0, Culture=neutral, PublicKeyToken=null'.

 System.TypeLoadException: Could not load type 'KRPC.Utils.DocumentationExtensions' from assembly 'KRPC, Version=0.3.6.0, Culture=neutral, PublicKeyToken=null'.

 System.TypeLoadException: Could not load type 'KRPC.Configuration' from assembly 'KRPC, Version=0.3.6.0, Culture=neutral, PublicKeyToken=null'.

 System.TypeLoadException: Could not load type 'KRPC.Utils.ConfigurationStorage' from assembly 'KRPC, Version=0.3.6.0, Culture=neutral, PublicKeyToken=null'.

 System.TypeLoadException: Could not load type 'KRPC.Utils.ConfigurationStorageNode' from assembly 'KRPC, Version=0.3.6.0, Culture=neutral, PublicKeyToken=null'.

 System.TypeLoadException: Could not load type 'KRPC.Utils.ConfigurationStorageNode' from assembly 'KRPC, Version=0.3.6.0, Culture=neutral, PublicKeyToken=null'.

And a whole bunch more of loading exceptions for kRPC classes. Removing the mod and replacing it with a fresh copy did not resolve it.

Edited by Kerbart
whoops

Share this post


Link to post
Share on other sites

That sounds a lot like the dll didn't get compiled right/all the way. You would either need to do so yourself (not always trivial) or wait for a update release :( 

Share this post


Link to post
Share on other sites
16 hours ago, sylink said:

Maybe this is a bug? I was trying out the orbit tutorial and the node creation always fails, here is the tl dr to reproduce

 


# Set up streams for telemetry

import krpc, time, math

conn = krpc.connect(name='Launch into orbit')
vessel = conn.space_center.active_vessel




ut = conn.add_stream(getattr, conn.space_center, 'ut')
altitude = conn.add_stream(getattr, vessel.flight(), 'mean_altitude')
apoapsis = conn.add_stream(getattr, vessel.orbit, 'apoapsis_altitude')
periapsis = conn.add_stream(getattr, vessel.orbit, 'periapsis_altitude')
eccentricity = conn.add_stream(getattr, vessel.orbit, 'eccentricity')

print('Calculating circular burn')
mu = vessel.orbit.body.gravitational_parameter
r = vessel.orbit.apoapsis
a1 = vessel.orbit.semi_major_axis
a2 = r
v1 = math.sqrt(mu*((2./r)-(1./a1)))
v2 = math.sqrt(mu*((2./r)-(1./a2)))
delta_v = v2 - v1
node = vessel.control.add_node(vessel.orbit.time_to_apoapsis, prograde=delta_v)

 

The burn is actually at the end of the script but I shortened it to reproduce the error, it fails with

 


Calculating circular burn
Traceback (most recent call last):
  File "FirstOrbit.py", line 25, in <module>
    node = vessel.control.add_node(vessel.orbit.time_to_apoapsis, prograde=delta_v)
  File "<string>", line 1, in <lambda>
  File "C:\Python35\lib\site-packages\krpc\client.py", line 88, in _invoke
    raise RPCError(response.error)
krpc.error.RPCError: Object reference not set to an instance of an object

I can't tell if its a krpc problem or a me problem.

Your code looks good. Although it might depend on the situation the vessel is in when you run it. Could you edit GameData/kRPC/PluginData/settings.cfg and set verboseErrors to True then run it again? Then it'll give us a full stack trace in the error message which might help track down the issue.

Is this using the pre-release version with KSP 1.2? There are some issues with maneuver node creation with that version that I'm currently working on a fix for.

Share this post


Link to post
Share on other sites
On 10/14/2016 at 0:48 AM, djungelorm said:

Your code looks good. Although it might depend on the situation the vessel is in when you run it. Could you edit GameData/kRPC/PluginData/settings.cfg and set verboseErrors to True then run it again? Then it'll give us a full stack trace in the error message which might help track down the issue.

Is this using the pre-release version with KSP 1.2? There are some issues with maneuver node creation with that version that I'm currently working on a fix for.

Yes it is the pre-release, so if thats it, then it explains a lot :) I'm trying to do all the math manually now to do the burn without nodes anyway, which is apparently hard.  Below is the trace for you. 

python FirstOrbit.py
Calculating circular burn
Traceback (most recent call last):
  File "FirstOrbit.py", line 26, in <module>
    node = vessel.control.add_node(vessel.orbit.time_to_apoapsis, prograde=delta_v)
  File "<string>", line 1, in <lambda>
  File "C:\Python35\lib\site-packages\krpc\client.py", line 88, in _invoke
    raise RPCError(response.error)
krpc.error.RPCError: 'SpaceCenter.Control_AddNode' threw an exception.
System.NullReferenceException: Object reference not set to an instance of an object
  at ManeuverNode.OnGizmoUpdated (Vector3d dV, Double ut) [0x00000] in <filename unknown>:0
  at KRPC.SpaceCenter.Services.Node..ctor (.Vessel vessel, Double ut, Single prograde, Single normal, Single radial) [0x00000] in <filename unknown>:0
  at KRPC.SpaceCenter.Services.Control.AddNode (Double ut, Single prograde, Single normal, Single radial) [0x00000] in <filename unknown>:0
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0

 

Share this post


Link to post
Share on other sites
On 16/10/2016 at 0:56 AM, djungelorm said:

That's the same stack trace I was getting. Should be fixed in the latest pre-release build :)

https://krpc.s3.amazonaws.com/deploy/feature/ksp-1.2/708.1/krpc-0.3.6-46-gc1e39ed.zip

Hi,

Awesome mod! I've been using it for a while now(when I was on 1.1.3) but I tried downloading and installing this pre-release for 1.2 and I've copied the GameData contents to the GameData folder for KSP and unzipped the python client zip file but I'm a little confused as to where I'm meant to move it to(i'm on Windows btw). I've only ever used pip.exe to install krpc before so I'm a little unfamiliar with manual installation. Once the official release is out I'll probably revert to using pip.exe but in the meantime any help would be appreciated.

Thanks

Share this post


Link to post
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.