Jump to content

[1.8.x to 1.12.x] kRPC: Remote Procedure Call Server (v0.5.1, 2nd March 2023)


djungelorm

Recommended Posts

9 hours ago, Hardware_Autopilot said:

How do I get the distance to the target? (In python) I have checked the docs, but can't find anything. Not for docking, so the target will just be a vessel.

You could get the position of the target vessel in the current vessels reference frame (in which the current vessel is at position (0,0,0)) then take the magnitude of that vector. For example:

import krpc, math
conn = krpc.connect()

vessel = conn.space_center.active_vessel
target = conn.space_center.target_vessel

if target is None:
    print 'No target set!'
else:
    position = target.position(vessel.reference_frame)
    distance = math.sqrt (position[0]*position[0] + position[1]*position[1] + position[2]*position[2])
    print distance, 'meters'

 

Link to comment
Share on other sites

13 hours ago, djungelorm said:

You could get the position of the target vessel in the current vessels reference frame (in which the current vessel is at position (0,0,0)) then take the magnitude of that vector. For example:


import krpc, math
conn = krpc.connect()

vessel = conn.space_center.active_vessel
target = conn.space_center.target_vessel

if target is None:
    print 'No target set!'
else:
    position = target.position(vessel.reference_frame)
    distance = math.sqrt (position[0]*position[0] + position[1]*position[1] + position[2]*position[2])
    print distance, 'meters'

 

Thanks, that works brilliantly!

Link to comment
Share on other sites

I've finally gotten my head around the mathematics necessary to improve the autopilot and make it autotune itself based on the vessels MoI and available torque. No more overshoot or waiting ages for the oscillations to subside! I'm keen for people to test it out before I release it as it will replace the existing autopilot. If you're interested, there are more details and download links on this github ticket: https://github.com/krpc/krpc/issues/289

Link to comment
Share on other sites

Is there any Chance to create Pictures or to Transfer Pictures from a camera attached? I.e. from DockingCam or else.

Reason: I wonder if you can Control ships REALLY over Internet without seeing the actual Output of KSP.

that would be fun.
I could Play a remote-Mission while travelling on my PC @ home with an even more realistic touch to it.

Any chance to have a web-Scripting engine integrated? sth like php?

Link to comment
Share on other sites

Hey all who are interested in kRPC and making KSP accessible via web,

I made a little demo using the Java API which i integrated into my tomcat installation to remote my rover via a website :) ... thanks again @djungelorm your plugin rockz!

I can read live values from parts and give commands to my rover AI ...

 

 

Edited by Survius
Link to comment
Share on other sites

On 17/06/2016 at 6:18 AM, Speadge said:

Is there any Chance to create Pictures or to Transfer Pictures from a camera attached? I.e. from DockingCam or else.

Reason: I wonder if you can Control ships REALLY over Internet without seeing the actual Output of KSP.

that would be fun.
I could Play a remote-Mission while travelling on my PC @ home with an even more realistic touch to it.

Any chance to have a web-Scripting engine integrated? sth like php?

Nice idea! Should be possible to add receipt of a stream of pictures. Could potentially do it by encoding images as JPEGs and sending the raw bytes to the client program (the kRPC protocol supports sending arrays of bytes). I'm a bit busy trying to get a new version out before I disappear on holiday for two weeks, but can look into this more once I'm back.

There is a websockets server for javascript on its way, but as for php I have no plan to implement a client for that language. However, if you like you could write your own client: http://krpc.github.io/krpc/communication-protocol.html

Link to comment
Share on other sites

15 minutes ago, djungelorm said:

There is a websockets server for javascript on its way, but as for php I have no plan to implement a client for that language. However, if you like you could write your own client: http://krpc.github.io/krpc/communication-protocol.html

thanks for taking this idea into account. Dont hurry on this, just wanted to share it :wink:

I was just thinking about some kind of Remote interface like Telemachus, which sadly also dont include pictures.
Whole idea: Is it possible to control KSP just with fixed cameras attached to your vessels or with IVA - like in real live.

In addition, i wonder if you can control a vessel that is NOT your "Active Vessel". Alltogether - for really hardcore-player - you can assemble kind of a control room like in RL.
-just an idea :D

 

Link to comment
Share on other sites

6 hours ago, Speadge said:

In addition, i wonder if you can control a vessel that is NOT your "Active Vessel". Alltogether - for really hardcore-player - you can assemble kind of a control room like in RL.

-just an idea :D

 

Yep you can already do this! (As long as it's in physics range of the active vessel)

Link to comment
Share on other sites

Huge thanks for maintaining this software.

I'm really happy with the python client, and i really enjoy myself using the client. I'm using it for a custom controller, and it gives me all the controls that i need.

I'm really impressed on how you manage to maintain all the clients + the doc !

Do you use unitary test ?

How do you generate the documentation ?

I haven't seen how to activate actions groups, is it implemented ?

Thanks a lot and keep up the good work !

Link to comment
Share on other sites

19 hours ago, gbip said:

Huge thanks for maintaining this software.

I'm really happy with the python client, and i really enjoy myself using the client. I'm using it for a custom controller, and it gives me all the controls that i need.

I'm really impressed on how you manage to maintain all the clients + the doc !

Do you use unitary test ?

How do you generate the documentation ?

I haven't seen how to activate actions groups, is it implemented ?

Thanks a lot and keep up the good work !

Thanks - I really enjoy working on it :)

It is quite a handful to manage all the different languages and tools, but the bazel build system really helps a lot with that. I use it to run unit tests for all the different clients and the server code. The tests are written in a variety of ways, e.g. nunit for the C# code, googletest for C++, unittest module for python... The server dll is written in such a way that it can be linked it into a little "TestServer" executable that runs a server with a bunch of test RPCs. The client tests then run their tests against this test server. This means that you don't need to run KSP to run the tests, and they can also be run by Travis CI whenever I push code changes.

There are also tests for the services (the bit of the project that does require KSP to be running). For these I use python scripts (using unittest and the python client). For example: https://github.com/krpc/krpc/tree/master/service/SpaceCenter/test To run them, I load up KSP with kRPC installed, then run the scripts, which connect and then test all the different bits of the API. Its quite fun to run them and watch it do things in game as it works through the tests.

The API documentation is all automatically generated from the comments in the C# code. This is very useful as it means the documentation is written right next to the actual code! These generated docs are then combined with some handwritten stuff (e.g. the tutorials) and built using Sphinx into both the website and the PDF that comes in the download.

As for action groups, they're here: http://krpc.github.io/krpc/csharp/api/space-center/control.html#method-KRPC.Client.Services.SpaceCenter.Control.GetActionGroup

Link to comment
Share on other sites

kRPC v0.3.5 has been released!

The major changes are:

Full changelog available here: https://github.com/krpc/krpc/releases/tag/v0.3.5

Enjoy!

Link to comment
Share on other sites

Hello, I'm really interesting in kRPC, and I want to try make autoland of the craft. Just for the first time, I'm not going to neutrilize horizontal velocity. But i want to calclulate the best starting point for my "suicide burn".

In general, I need to calculate how much delta-v I need to stop my vehicle. After that I need to calculate time of burning this delta-v. After that I need to calculate additional velocity which my craft will get due to gravity, while I making this burn, and do it until precision of calculation not enough.

So, Now I have Delta-v amount and time, now I need to calculate mimimal altitude when I still safely land. And when my descend profile reach this altitude, my algorithm should start suiceide burn. This is general case how I see it.

My question is about delta-v equation: ln(Mstart/Mend) * Isp * 9.81 * (m/s2)

What is s2? kRPC provides gravitational parameter of current body, its GM, or (9.81 * m) from equation above, but what is s2? All other stuff I know where I can get them.

Mstart and Mend I can calculate by engine specs anf fuel flow and other variables to be more precise.

Thanks in advance!

Edited by libbkmz
Link to comment
Share on other sites

5 hours ago, libbkmz said:

So, Now I have Delta-v amount and time, now I need to calculate mimimal altitude when I still safely land. And when my descend profile reach this altitude, my algorithm should start suiceide burn. This is general case how I see it.

There's a few caveats but with some luck they'll cancel each other out. It's doubtful your script will see you reaching the "suicide" altitude, rather you'd be passing through it. In other words, kRPC will tell you, "hey, your altitude is now below suicide altitude" and that won't be good. Starting 1/10s too late with your burn is the difference between a soft landing and rapid unplanned disassembly.

On the other hand, translating DV into an altitude is tricky as you don't have constant acceleration.  Unless there's a simple trick for that I'm unaware (I'd love to learn it!). The safest is to base acceleration on the (higher) mass at the start of the burn, which means you'll accelerate faster than "required" by the DV-based calculations. That should (more than) offset the problem listed above.

I would do an automated landing in two stages: 1) Suicide burn to, say, 10m/s and 50m above the surface and 2) controlled landing at 5m/s (using something like a PID controller for your descend speed, it works very well in kRPC) until touchdown.

@djungelorm sorry if this is getting too much off topic. Perhaps room for a third kRPC thread with discussing kRPC scripts as subject?

Link to comment
Share on other sites

import krpc
import time

conn = krpc.connect(name='test')

while 1:
    vessel = conn.space_center.active_vessel

    alt = vessel.flight(vessel.reference_frame).surface_altitude
    ver_sp = vessel.flight(vessel.reference_frame).velocity
    ver_sp = map(lambda x: "%.2f" %x, ver_sp)

    print "alt: %s, ver_sp: %s" % (alt, ver_sp)

    time.sleep(0.01)

I've tried this code, but vertical_speed is always 0 for the whole vector!

It only works when I try vessel.flight(vessel.orbit.body.reference_frame).velocity But, I do not need any kind of orbital speeds, i thinks something wrong. 

Link to comment
Share on other sites

I'm looking to move from kOS to kRPC for my orbital maneuver library.  One quick question though before the rest of my post: can kRPC control ships without a Remotetech connection?

I do Python professionally anyways, so the learning curve isn't particularly high in my case (and a lot of the harder mathy stuff I've already worked out in kOS

That said, oddly enough kOS has kind of grown on me.  I'd love a bridgebetween the two mods... like a way for kOS to send a message to kRPC and get a response back -- or the reverse.  The use cases I'm thinking are:

- Mission controlled from kOS, messages to kRPC to request complicated calculations and await a response (like maneuver planning, particularly Lambert solving for transfers -- my kOS code took 15 minutes(!) to do what Alexmoon's transfer planner does in seconds).  I've actually seen this done in another kOS script using a much less elegant method: write request to a file, wait for a Java app to read that file and write a response, and check every quarter-second or so for the response file.  But that's messy, and doesn't work on a RT save with no connection.

- Mission controlled from kRPC, messages sent to kOS to handle real-time control needs (like executing a maneuver node as precisely as possible without the latency of the protocol).  Technically this could be done by telnetting to kOS, though that is also messy and again fails on a RT save with no connection.

Are there any thoughts of adding something like this in the future?

Link to comment
Share on other sites

1 hour ago, libbkmz said:

I mean, How to get current vertical speed of the vehicle, when I near the ground?

You are using the craft reference frame. That's more suitable for docking, as it's measuring everything, including velocity, relative to the craft. With that reference frame, velocity will always be zero.

I'm not sure if this would work, but you can try this out:

ref_frame = vessel.orbit.body.reference_frame
vert_speed = vessel.flight(ref_frame).vertical_speed

 

Link to comment
Share on other sites

13 hours ago, dewin said:

[KOS + KRPC etc etc.]

So I decided to take a stab at this myself.  It turns out that ... it's not really possible with currently released kOS builds (but the latest Github version has proper support for addons, and I've got a basic "Hello World!" (actually "PRINT addons:krpc:available.") example working)).  With that in mind

  • I have no idea how to properly connect the two addons as far as sending messages back and forth goes.  Namely, I don't see any sort of mechanism that would allow a list of variable types.  (i.e. the message to request planning for a lambert transfer would have -- at minimum -- two vectors, some ranges of times, etc.).  What might be feasible -- though clunky -- is something like (from the kRPC side):
    • Message.argumentTypes() returns a list of what types are encoded in the message.
    • Message.getVessel(2) retrieves the 2nd argument if it's a vessel.
    • etc.

I'm super-new to this though (I have a tiny PR for KER, but have no other real C# experience), so I have no idea and I suspect there's a far better solution.

Link to comment
Share on other sites

17 hours ago, dewin said:

So I decided to take a stab at this myself.  It turns out that ... it's not really possible with currently released kOS builds (but the latest Github version has proper support for addons, and I've got a basic "Hello World!" (actually "PRINT addons:krpc:available.") example working)).  With that in mind

  • I have no idea how to properly connect the two addons as far as sending messages back and forth goes.  Namely, I don't see any sort of mechanism that would allow a list of variable types.  (i.e. the message to request planning for a lambert transfer would have -- at minimum -- two vectors, some ranges of times, etc.).  What might be feasible -- though clunky -- is something like (from the kRPC side):
    • Message.argumentTypes() returns a list of what types are encoded in the message.
    • Message.getVessel(2) retrieves the 2nd argument if it's a vessel.
    • etc.

I'm super-new to this though (I have a tiny PR for KER, but have no other real C# experience), so I have no idea and I suspect there's a far better solution.

Honestly I don't see any reason to mess with kOS when kRPC can do everything kOS can do plus more?  I used to use kOS before I found kRPC, and I have never looked back since switching.

 

Really the only thing kOS has is an in game "terminal" which honestly was what I hated about it lol.  I can't think of anything else it does that kRPC doesn't.

Link to comment
Share on other sites

7 minutes ago, Agathorn said:

Really the only thing kOS has is an in game "terminal" which honestly was what I hated about it lol.  I can't think of anything else it does that kRPC doesn't.

Heh, I use telnet (PuTTY) instead.

From the draft documentation for my mod (spoilered for brevity):

Spoiler

Why not just use kOS?

kOS is poorly suited to certain tasks, including complex calculations.  The particular incentive to write this mod came about after attempting to make a kOS version of AlexMoon's Launch Window Planner

Additionally, someone may already have a large kRPC-using project -- or sufficient experience with mainstream programming languages -- to prefer kRPC.

Why not just use kRPC?

kRPC introduces a small amount of latency in fine control of a craft, since messages go over a TCP/IP communication channel and KSP may have additional physics frames before a message to cut throttle is received.

Additionally, someone whose first experience in programming comes from kOS may not want to have to start completely from scratch if they're inspired to start learning a mainstream programming language.

Use Cases

There's two main scenarios where I can see the bridge being useful, though others likely exist.

  • kOS As Mission Control: kOS handles the overall control of a particular vessel, with requests sent to kRPC for complex tasks like maneuver planning.
  • kRPC as Mission Control: kRPC handles the overall control of a particular vessel, with requests sent to kOS for real-time tasks like executing a planned maneuver.

 

 

Edited by dewin
Link to comment
Share on other sites

On 6/29/2016 at 7:50 AM, libbkmz said:

So, my final equation should be looked like 

ln(Mstart/Mend) * Isp * 9.81  ?

IIRC, KSP for whatever reason calculates ISP assuming g=9.82, rather than 9.81

Link to comment
Share on other sites

On 6/29/2016 at 8:32 AM, Kerbart said:

@djungelorm sorry if this is getting too much off topic. Perhaps room for a third kRPC thread with discussing kRPC scripts as subject?

No worries. It's best discussing stuff like this over on the release thread as this thread is intended for dev discussion of the mod itself. Although posts seem to just appear randomly on either of the two threads...

On 6/30/2016 at 8:59 AM, dewin said:

One quick question though before the rest of my post: can kRPC control ships without a Remotetech connection?

 

Yes you can. If RemoteTech is present kRPC will register itself as a "sanctioned" pilot so that it is unaffected by remote techs connection status.

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...