djungelorm Posted March 13 Share Posted March 13 (edited) kRPC2 allows you to control Kerbal Space Program 2 from scripts running outside of the game, and comes with client libraries for many popular languages. This is a continuation of the kRPC mod for Kerbal Space Program 1 The mod is a very early work in progress, so don't expect much! Source code: https://github.com/krpc/krpc2 SpaceDock: https://spacedock.info/mod/3322/kRPC2 Documentation for kRPC1 (which is also relevant to this): https://krpc.github.io/krpc ---- In this first proof-of-concept release v0.1.0, there is a single "service", called SpaceCenter2, with a few properties for basic telemetry. It works with the existing kRPC client libraries (as it speaks the same protocol). However we don't yet provide generated stubs for clients like C++, C# and Java. It has only been tested using the python client, which does not require generated stubs (it can auto-generate them on connection). When the game starts, a server is created with RPC port 50000 and Stream port 50001. There is no configuration for this yet - it is hard coded in. Here's an example in Python, with all the currently available telemetry: import krpc conn = krpc.connect() print(conn.space_center2.horizontal_surface_speed) print(conn.space_center2.vertical_surface_speed) print(conn.space_center2.terrain_altitude) print(conn.space_center2.sealevel_altitude) Edited March 13 by djungelorm Fix formatting Quote Link to comment Share on other sites More sharing options...
Computerizer Posted Wednesday at 03:50 AM Share Posted Wednesday at 03:50 AM Awesome! I was going make a request for this because it would be great to migrate my kRPC stuff to KSP2. Glad you're working on this. Keep it up! Quote Link to comment Share on other sites More sharing options...
LeroyJenkins Posted Saturday at 03:02 PM Share Posted Saturday at 03:02 PM how does this compare/relate to KSPSerialIO? Quote Link to comment Share on other sites More sharing options...
Kerbart Posted Saturday at 04:05 PM Share Posted Saturday at 04:05 PM 1 hour ago, LeroyJenkins said: how does this compare/relate to KSPSerialIO? The API is object oriented and there are interfaces for many popular languages including C#, Python and Java. Quote Link to comment Share on other sites More sharing options...
djungelorm Posted Saturday at 06:18 PM Author Share Posted Saturday at 06:18 PM 3 hours ago, LeroyJenkins said: how does this compare/relate to KSPSerialIO? KSPSerialIO does two things: sends you a telemetry stream over serial (using a custom serialisation format) and can receive a similar stream of control data. It's very light weight (so great for things like Arduino). It's also very low level - providing you no abstraction over the interface. And the interface is fixed. kRPC is a more complex ecosystem of servers and clients, allowing you to interact with the game from many different languages (including Arduino using the Cnano client). It runs a server in game that can speak various protocols (including protobuf over TCP/IP, websockets and serial io). Clients call "remote procedures" using these protocols. The various client libraries provide abstractions over this so, as Kerbart points out, you get an object orientated view. These libraries also provide high level abstractions like events, and streams. The server is also extensible. Other mods can add RPCs to the server to extend the functionality. Quote Link to comment Share on other sites More sharing options...
LeroyJenkins Posted Saturday at 06:44 PM Share Posted Saturday at 06:44 PM @djungelorm and @Kerbart, Thank you both for that info. I am looking to build a control panel to replace most of the keyboard mappings and trying to figure out the best way to get telemetry from KSP2 and Command into KSP2. This helps. Quote Link to comment Share on other sites More sharing options...
LeroyJenkins Posted 22 hours ago Share Posted 22 hours ago (edited) @djungelorm - Been reading up on the kRPC documentation (krpc.github.io/krpc/index.html), specifically the SpaceCenter APIs. Before i get into the full control console hardware design, I want to make a GUI interface representation first to be a stepping stone as I learn this stuff. I'll start with receiving telemetry from KSP2 and displaying it before creating buttons to send commands to KSP2. Kind of like the Telemetry Health and Status Displays we use in Satellite Mission Control Centers (See image at bottom of post). I have a few questions about the APIs capabilities. I'll be referencing C++, since that is what I know 1) I see how I can get the orbital parameters of a vessel by calling Vessel::orbit() and its sub functions. Does this return the parameter values for the active_vessel() only? I ask, cause I'd like to be able to display all the current vessels (in flight) orbital parameters at once. Would I have to cycle through all the vessels in std::vector<Vessel>vessels(), by setting each one in the list as the active vessel (using set_active_vessel(Vessel Value)), getting its orbit parameter and then repeating for each vessel in the array? 2) Are Vessel::Orbit() telemetry only available while KSP2 is in Flight View? Or can I continue to poll the data while in VAB, Map and Tracking Station Views? If there are current missions flying, while I am building a new rocket, I'd like the external Telemetry GUI to keep updating. 3) Under Alarms API. The current alarms are based on time, time offsets, or time to Pe, Ap or Planned Maneuver Node Points. I'd like to see if I can create Alarms for other things. For example: If a spacecraft (s/c 1) is on a long flight mission, and I am working on another spacecraft (s/c 2), I'd like to be alerted if s/c 1's EC goes below 10% of capacity. That way I don't have to keep swapping active views and checking on s/c 1's health and status, while working on s/c 2. If this not in the scope of kRPC2, I could make alarms as part of the external GUI, but then I'd have to make a DB and inference engine to track the each new current value to the set alarm limits. When we fly spacecraft we usually have four limits the system tracks for telemetry. Red High, Yellow High, Yellow Low and Red Low. Also I'd have to create a persistence and hysteresis check to ensure that if the the value is toggling back and forth over a limit, it doesn't consistently repeat the alarm every sample. Thanks for the help. This information well help me plan the architecture. This is a very basic Telemetry screen (old school style). The newer ones are more graphic and color coded. Edited 21 hours ago by LeroyJenkins Quote Link to comment Share on other sites More sharing options...
djungelorm Posted 20 hours ago Author Share Posted 20 hours ago (edited) Cool project! Here's my feedback, hope it helps: Quote I'll start with receiving telemetry from KSP2 and displaying it before creating buttons to send commands to KSP2. Note that we haven't implemented the SpaceCenter API for KSP2 yet. What we have released so far for KSP2 (called kRPC2) is just a proof-of-concept to see if the server communication works (which it does!) We are actively working on implementing this part, and will likely start with the basic telemetry stuff you'll need. The SpaceCenter API for KSP1 and KSP2 is planned to be (almost) identical. So if you want to get coding, you could prototype your interface using kRPC1+KSP1. It should work with minor modification in kRPC2+KSP2 once we've implemented the required APIs. Quote 1) I see how I can get the orbital parameters of a vessel by calling Vessel::orbit() and its sub functions. Does this return the parameter values for the active_vessel() only? I ask, cause I'd like to be able to display all the current vessels (in flight) orbital parameters at once. Would I have to cycle through all the vessels in std::vector<Vessel>vessels(), by setting each one in the list as the active vessel (using set_active_vessel(Vessel Value)), getting its orbit parameter and then repeating for each vessel in the array? You can do this, and no you don't need to keep switching active vessel. The API is object oriented (instances of objects in the client refer to objects in the game via a unique id number). You can obtain a Vessel object for whatever vessel you like, and then an Orbit object for that vessel, and call the various methods to get orbital parameters for that specific vessel. (it's abstracted like this, as Orbit objects can also refer to things like planets). The SpaceCenter::vessels() function gives you an std::vector of Vessel objects for all the vessels in the game, and SpaceCenter::active_vessel() gives you a Vessel object for just the active vessel. You can treat these Vessel objects just like a normal C++ object, and call the orbit methods they contain. Quote 2) Are Vessel::Orbit() telemetry only available while KSP2 is in Flight View? Or can I continue to poll the data while in VAB, Map and Tracking Station Views? If there are current missions flying, while I am building a new rocket, I'd like the external Telemetry GUI to keep updating. You can do this (in KSP1). I can't really comment on this regarding KSP2 as it's not implemented yet, but in KSP1 this telemetry is available in any view (and we aim to do the same for KSP2). In the documentation, it says which game scenes you can use the class/method/function in (and if none are specified you can assume it's always available). For example SpaceCenter::vessels() and all the orbit methods are available in all game scenes. SpaceCenter::active_vessel() is only available from the flight scene. Quote 3) Under Alarms API. The current alarms are based on time, time offsets, or time to Pe, Ap or Planned Maneuver Node Points. I'd like to see if I can create Alarms for other things. For example: If a spacecraft (s/c 1) is on a long flight mission, and I am working on another spacecraft (s/c 2), I'd like to be alerted if s/c 1's EC goes below 10% of capacity. That way I don't have to keep swapping active views and checking on s/c 1's health and status, while working on s/c 2. If this not in the scope of kRPC2, I could make alarms as part of the external GUI, but then I'd have to make a DB and inference engine to track the each new current value to the set alarm limits. When we fly spacecraft we usually have four limits the system tracks for telemetry. Red High, Yellow High, Yellow Low and Red Low. Also I'd have to create a persistence and hysteresis check to ensure that if the the value is toggling back and forth over a limit, it doesn't consistently repeat the alarm every sample. The alarm API is for creating/managing KSP1 alarms, just like you would do manually using the KSP1 in-game UI. I don't know enough about KSP2 yet to know if these same alarms exist in KSP2. As for the kind of alarm you describe, this is the sort of thing we want to support and is in scope for the mod. One approach that could work for you are events. In kRPC, you could create a server-side expression for "EC < 10%", create a stream that wraps it, and then wrap an event around it. In the C++ client this would give you an std::condition_variable that gets notified when the EC drops below the threshold. There is an example in the docs that does something very similar. It triggers an event when the altitude of the vessel exceeds 1km: https://krpc.github.io/krpc/cpp/client.html#custom-events One thing that could cause problems for this, is whether the game is actually running the EC simulation for s/c1 in the background while you are working on s/c 2. I don't know enough about KSP2 yet to know if that's the case. Edit: you can also set the rate for a stream. So you could configure it to only check "EC < 10%" once per minute to save on game performance. Edited 20 hours ago by djungelorm Add comment on stream rate control Quote Link to comment Share on other sites More sharing options...
LeroyJenkins Posted 18 hours ago Share Posted 18 hours ago (edited) @djungelorm That was a HUGE help. I understand that how this works in KSP2 is TBD as IG devs evolve it. Understanding how it works in KSP1 and your Vision for kRPC2 helps me map out my plan. 1) Got it. Create a Vessel::object for each item in SpaceCenter::Vessels(), then access the methods I want. Perfect. 2) Understood 3) I'll have to investigate how to do stream wrapped expressions events. But thanks for pointing me in that direction. I'll look into it. Awesome that we can set the rate for the stream. No need to poll something every cycle if it doesn't change much. We do this a lot for S/C telemetry. Somethings that are binary and don't change often, we'll only transmit its data 1-10sec (1-0.1Hz) , where others that are floats and change rapidly we would send up to 60 Hz rates. No sense sending everything at 60Hz and taking up bandwidth. Edited 18 hours ago by LeroyJenkins Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.