Jump to content

[1.12.x] kRPC: Control the game using C#, C++, Java, Lua, Python, Ruby, Haskell, C (Arduino)... (v0.5.4)


djungelorm

Recommended Posts

On 9/15/2020 at 8:51 PM, CanisLupus518 said:

I installed the 0.4.8 version of the mod using CKAN after temporarily enabling 1.5 compatibility. It seems to work in KSP 1.10.1. Ihave not tested every API, but so far I am able to get orbital telemetry without an issue

yes I did it the same way. And it works. I am only scared that it is not supported any longer since I base my gaming console on it.

Link to comment
Share on other sites

Hello,

On 11/5/2020 at 11:47 AM, blueisaak said:

yes I did it the same way. And it works. I am only scared that it is not supported any longer since I base my gaming console on it.

Did you connect via Serial or via TCP?

I'm using KSP 1.10.1.2939 and trying to connect an Arduino Uno so I have to connect via a serial port.

I tried the simplest example, and it compiles great on Arduino IDE but then it doesn't connect . Something's in the mod is probably broken with this version of KSP... Which isn't surprising if it hasn't been updated since October 2018. 

#include <krpc.h>
#include <krpc/services/krpc.h>
#include <krpc/services/space_center.h>

HardwareSerial *conn;

void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);

  conn = &Serial;
  // Open the serial port connection
  krpc_open(&conn, NULL);
  
  // Set up communication with the server
  while (krpc_connect(conn, "Arduino Example") != KRPC_OK);

  // Indicate succesful connection by lighting the on-board LED
  digitalWrite(LED_BUILTIN, HIGH);
}

void loop()
{
  
}

I'll try with another version of KSP, since I really want real switches and buttons.

BTW, this is what I'm working on (yes the holes for the buttons are terribly spaced: the manufacturing process is still... in progress haha):

IMG-20201107-210547.jpg

Link to comment
Share on other sites

  • 4 weeks later...

Hello, I've been playing with kOS for several months and am wanting to branch out a bit and kRPC has been recommended by some smart guys.  I'm running on linux, but could go to windows if required (hopefully not though).  I do wonder about the lack of updates since 2018; is it being actively maintained with regards to newer versions?  I'm currently running 1.10.1 but am not glued to that. 

tl;dr questions:

  • Is linux a problem with kRPC?
  • Is kRPC being (or will be soon) actively maintained  for current versions of KSP?
  • What is the "best" KSP version for kRPC?
  • Is there Trajectories support?

Thanks

 

Link to comment
Share on other sites

  • 1 month later...
On 7/22/2020 at 10:08 AM, blueisaak said:

I saw on git that there is a build for 1.9.

May I ask where you saw that? The list of releases on GitHub only seems to list the ones CKAN has, the latest of which only mentions KSP 1.5.1:

On 8/29/2020 at 7:00 AM, darthgently said:

I, too, only see CKAN presenting an apparent old version and am not sure if this is because CKAN isn't up to speed or if CKAN hasn't deemed the later versions compatible and the git version is 'beta'.  The forum seems fairly quiet

Are you saying it's an "apparent old version" because @blueisaaksaid so, or because you found this "git version" yourself? If the latter, may I inquire as to where it is?

Link to comment
Share on other sites

  • 2 months later...
On 1/27/2021 at 10:54 AM, HebaruSan said:

May I ask where you saw that? The list of releases on GitHub only seems to list the ones CKAN has, the latest of which only mentions KSP 1.5.1:

Are you saying it's an "apparent old version" because @blueisaaksaid so, or because you found this "git version" yourself? If the latter, may I inquire as to where it is?

The KRPC discord is fairly active. I dabbled around with this fork (NOT master release): Release build for ksp 1.8.0 - 1.9.0 · haeena/krpc · GitHub but the Unity version in KSP changed with 1.9 so some of the UI stuff such as drawing vectors isn't working right now. I just saw someone just did an 11.x fork but I am in the process now of trying it so can't speak to it. 

Edit: Yahoo, the 1.11 fork I found has working UI elements! Canvases and vector lines are working again! (Maybe someone fixed them some time ago, but anyhow they work again!)

Github fork: Release 0.49-1.11 · nullprofile/krpc · GitHub

Edited by aeroeng14
Updated with 1.11 fork test results.
Link to comment
Share on other sites

14 minutes ago, aeroeng14 said:

The KRPC discord is fairly active. I dabbled around with this fork (NOT master release): Release build for ksp 1.8.0 - 1.9.0 · haeena/krpc · GitHub but the Unity version in KSP changed with 1.9 so some of the UI stuff such as drawing vectors isn't working right now. I just saw someone just did an 11.x fork but I am in the process now of trying it so can't speak to it. 

Ahh, I see, thanks. I guess this is as good a time as any to try to set some user expectations:

The CKAN bot does not subscribe to random Discords to eavesdrop on user chats about the latest recompiles that they're sharing. Unless somebody announces they're adopting the mod and sets up a forum thread or a SpaceDock page or submits an issue or a pull request to NetKAN, builds like that will not show up in CKAN.

Link to comment
Share on other sites

4 minutes ago, HebaruSan said:

Ahh, I see, thanks. I guess this is as good a time as any to try to set some user expectations:

The CKAN bot does not subscribe to random Discords to eavesdrop on user chats about the latest recompiles that they're sharing. Unless somebody announces they're adopting the mod and sets up a forum thread or a SpaceDock page or submits an issue or a pull request to NetKAN, builds like that will not show up in CKAN.

Very true. These are as far as I know not official in any way and obviously why CKAN didn't pick them up.

Link to comment
Share on other sites

  • 4 months later...

I've started on a 'final' features complete update fork.   

So far I've added support for:
stock robotics
rotating docking ports
  blinking lights
stock alarm clock
the wheel upgrades
 resource drains
and autostruts.

You can grab a preliminary version at https://github.com/artwhaley/krpc/releases/tag/experimental

Unfortunately I'm building in windows and am just recompiling the DLLs, so I'm not able to rebuild the documentation and a few of the client files, but things should be named pretty self-explanatorily so it should at least all work for folks using python.   If anyone with the full build environment working wants to help out with documentation and the client libraries that require building...   I'd really appreciate it!   I'll try to eventually get around to setting up a linux laptop and making it work myself if nobody else can, but... 

If anyone finds bugs or has questions, please let me know!   I've made pull requests to both the main repo and to Null Profile who's been doing rebuilds...   but until someone more qualified takes over, I'll do my best to get things updated and finalized!  

Link to comment
Share on other sites

  • 2 months later...

For anyone trying to use LaunchOrbit java code from tutorials, there is a problem in every while loop. Basically lots of variables aren't declared as "volatile" which causes different threads to not be synchronized, and then your while loop keeps going on forever without doing anything. The reason for that is the JVM is allowed to assume that other threads do not change some of the variables during the loop. The proper fix would be to make them all "volatile", but you can also fix it more easily by adding the following at the start of every loop:

System.out.print(".");
System.out.print("\b");

This will add a dot and then delete it every time, but what it does is force syncrhronization which makes the loop work properly.

Edited by Cannon
Link to comment
Share on other sites

  • 10 months later...

Hi,

I'm using kRPC 0.4.8 on KSP 1.5.1 and I was wondering if it was possible to modify the RPC Rate. I'm stuck at 50 RPC/s. I tried to modify the advanced settings with no luck. I'm using the Java client.

Thanks

EDIT: Works fine on 1.9.1

Edited by Azerty
Link to comment
Share on other sites

12 hours ago, Azerty said:

Hi,

I'm using kRPC 0.4.8 on KSP 1.5.1 and I was wondering if it was possible to modify the RPC Rate. I'm stuck at 50 RPC/s. I tried to modify the advanced settings with no luck. I'm using the Java client.

Thanks

EDIT: Works fine on 1.9.1

Probably not as that looks like the physics tick rate in the game engine and all mods code functions by squeezing into that schedule.

I believe that physics engine heartbeat, whatever its limits are on your platform, is a hard limit, but could be wrong in some way

Edited by darthgently
Link to comment
Share on other sites

You are probably right because I think I read somewhere the physics simulation runs at 50Hz in KSP.

I assume something has changed regarding this matter between 1.5.1 and 1.9.1 because I'm not limited anymore. I can have spikes at 3000 RPC/s no problem.

Edited by Azerty
Link to comment
Share on other sites

4 hours ago, Azerty said:

You are probably right because I think I read somewhere the physics simulation runs at 50Hz in KSP.

I assume something has changed regarding this matter between 1.5.1 and 1.9.1 because I'm not limited anymore. I can have spikes at 3000 RPC/s no problem.

If it like kOS then it will fit as many things as it can in the 50hz slice it can.  If your RPC is low enough overhead I could see it s squeezing in more in a later version. 

Beware of reading data in one physics tick, but not acting on it until the next as this can introduce error.  I know about nothing concerning kRPC but look for a mechanism that allows you wait until the next tick so all data gathering and actions occur in the same tick. In kOS we look for the in game time to change. Someone more knowledgeable will chime in hopefully

Edited by darthgently
Link to comment
Share on other sites

  • 1 month later...

So for anyone wondering, there seems to be an active community still around this mod. AFAICT the current effort is best accessed here: https://github.com/nullprofile/krpc

In the releases you can find krpc recompiles for current versions of KSP, and under actions you can grab the CI builds of the current development which will also include new features found in stock, including those added by @artwhaley and mentioned by them in the post above.

I'm a bit allergic to hanging out on discord and apparently this is where people are so I don't know why no one officially adopted krpc or at least posts here from time to time, and I hope I don't step on anyone's toes by posting, but I'm very happy that krpc lives on and thought I'd share.

Link to comment
Share on other sites

  • 2 months later...

Does anyone know where the proto file defines all the data structures? I'm trying to create a client for Swift and all I'm getting out protoc is some request and response types that don't have anything to do with "space center" or "active vessel" or any of the other stuff that's in the example code.

Link to comment
Share on other sites

  • 1 month later...

The proto file defines the messaging format that a client should use to communicate with the server.  You would need to generate Swift code from the krpc.proto file, using a protobuf compiler. Quick google found this which should generate what you need: https://github.com/apple/swift-protobuf

There is also documentation on how client/server communication works in the kRPC documentation at these links:

https://krpc.github.io/krpc/communication-protocols/tcpip.html

https://krpc.github.io/krpc/communication-protocols/messages.html

Edit: To get the available RPCs (i.e the spacecenter/active vessel stuff) you could either look in GameData/kRPC for the files named e.g. KRPC.SpaceCenter.json. These files contain details of all the RPCs. Or you can get the RPCs that a server provides by invoking the KRPC.GetServices RPC call.

Edited by djungelorm
Link to comment
Share on other sites

5 hours ago, djungelorm said:

kRPC v0.5.0 has been released :)

This release includes all the changes from nullprofile's fork, and lots more. Full details over on the github release page. Thanks for all the great contributions!

https://github.com/krpc/krpc/releases/tag/v0.5.0

Thanks for your hard working!

Congratulations! Reborn in five years.

Edited by sumghai
Merged successive posts for the same content by the same user
Link to comment
Share on other sites

On 2/26/2023 at 7:31 PM, djungelorm said:

There is also documentation on how client/server communication works in the kRPC documentation at these links:

https://krpc.github.io/krpc/communication-protocols/tcpip.html

https://krpc.github.io/krpc/communication-protocols/messages.html

Is there anyway to get the full documentation, as a downloadable file, for offline reading?

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