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

I'm trying to use the krpcmj addin on 1.4.2, i can get the .dll to compile using djungelorm 's pull request. What i cannot do is use any function of the addon in Python, I get an Object not referenced error. Can someone help point me in the right direction to fix this? I compiled using Visual Studio Community 2017 and referencing the required assemblies from my KSP install. I'm targeting .NET 4.5, could that be it? Also when I try to create the client library for C# im getting this:

c:\Python27\Scripts>krpc-clientgen.exe -o krpcmj.cs --ksp=C:/users/Administrator/Desktop/ksp csharp KRPCMJ C:/Users/Administrator/Desktop/krpcmj-master/krpcmj/bin/Release/krpcmj.dll
Error:
Unhandled Exception: KRPC.Service.ServiceException: In service SpaceCenter: Service does not exist, when loading class
   at KRPC.Service.Scanner.Scanner.HandleError(IList`1 errors, String context, Exception exn)
   at KRPC.Service.Scanner.Scanner.GetServices(IList`1 errors)
   at ServiceDefinitions.MainClass.Main(String[] args)

 

Edited by daniel.hamel
Link to comment
Share on other sites

I'm about 80% of the way through totally rewriting the krpcmj plugin to use reflection... the code as it is is a couple of years old... so I can't really hazard a guess as to all of the ways it might be broken.  That said...from that error, first question...  the mechjeb service is separate from the space center service...  and that error says it's not found in the SpaceCenter service.   Are you sending commands to the mechjeb service at conn.krpcmj?  

Link to comment
Share on other sites

1 minute ago, artwhaley said:

I'm about 80% of the way through totally rewriting the krpcmj plugin to use reflection... the code as it is is a couple of years old... so I can't really hazard a guess as to all of the ways it might be broken.  That said...from that error, first question...  the mechjeb service is separate from the space center service...  and that error says it's not found in the SpaceCenter service.   Are you sending commands to the mechjeb service at conn.krpcmj?  

Cool, the code is just trying to create a client library for C#.

The code i'm using (trying in python as I can't get the client lib compiled) is

import krpc;  # Import Library
conn=krpc.connect()  # Setup Connection
mj=conn.krpcmj  # save a lot of repetetive typing
sc=conn.space_center
mj.apvessel=sc.active_vessel #assign apvessel for krpcmj

vessel = conn.space_center.active_vessel

vessel.name = "My Vessel"

flight_info = vessel.flight()
print (sc.active_vessel.orbit.periapsis_altitude)
mj=conn.krpcmj
print (mj.ascent_ap)

 

Link to comment
Share on other sites

That sure SHOULD work.   Like I said, it's been so long since I've actually looked at it, that I'm not sure where the problem is - it could be a change in KRPC, or in MJ itself...  Or it could be the .net version as you suggested?   @djungelorm is way smarter than me, so I bet he has more useful input.   I'll poke around later to see if I see something obvious.

 

Link to comment
Share on other sites

I've only been neglecting it a couple of years!  lol.   

I'll take a look to make sure the new version still compiles, then I'll get a Github repo up in the next few days..   The core functionality works, I'm just slow at trolling my way through the whole Mechjeb API.   If memory serves, the ascent, landing, maneuver planning, node execution, docking, and rover autopilots are all essentially there.   If I get it up on the internet, maybe someone with more free time than me will jump in and do some copy / paste and find/replace to help implement the missing modules! 

Link to comment
Share on other sites

Hello all, :)

I'm having trouble getting a value from a stream.

Set up as such :

periapsis = conn.add_stream(getattr, vessel.orbit, 'periapsis_altitude')
print("periapsis stream = {}.".format(periapsis))

When I print the variable "periapsis", I get :

<krpc.stream.Stream object at 0x0000025A7F3017B8>

It is not a number, what it is actually ? an object type and a memory address I guess ? How to get the actual value ? :confused:
I might have misunderstood something, if anyone have a clue about what's going on here, will be greatly appreciated. :wink:

PS: Not sure where to ask for help regarding that issue, hope here is okay.

Link to comment
Share on other sites

Hello!

I want to use several buttons in the script, each will run its own
algorithm. How can I distinguish between them? You can sample.

Use python !!!

def button_creat(self,color=(1,0,0),txt_title="Clear interface ",pos_x=100,pos_y=100,name_obj="id_button"):
        self.name_obj = name_obj
        self.button = self.panel.add_button(txt_title)
        self.button.rect_transform.position = (pos_x,pos_y)
        self.name_obj = self.conn.add_stream(getattr,self.button,"clicked")
Edited by SKYNЕT
Link to comment
Share on other sites

I had this installed in 1.2.2, just now getting back to it with 1.4.   Installed the kRPC folder by copying contents into main director (Schema/GameData/etc, so it all got placed where specified), and re-installed the library with Command Prompt.  

Now I click on "Start Server" button but nothing happens, run a script, but of course Python throws an error that the machine refused the connection.  

Of course, I AM the Machine.   But that's another story. 

What am I doing wrong?

Link to comment
Share on other sites

9 hours ago, Bosun said:

I had this installed in 1.2.2, just now getting back to it with 1.4.   Installed the kRPC folder by copying contents into main director (Schema/GameData/etc, so it all got placed where specified), and re-installed the library with Command Prompt.  

Now I click on "Start Server" button but nothing happens, run a script, but of course Python throws an error that the machine refused the connection.  

Of course, I AM the Machine.   But that's another story. 

What am I doing wrong?

Strange... works fine for me with KSP 1.4.3. Can you post the contents of your player log to see if there are any exceptions being thrown?

On Windows, it can be found in %USERPROFILE%\AppData\LocalLow\Squad\Kerbal Space Program\output_log.txt

or on Linux in ~/.config/unity3d/Squad/Kerbal Space Program/Player.log

Link to comment
Share on other sites

I reloaded everything and now I get this error:  

Traceback (most recent call last):
  File "D:\KSP_win64\KSRPC\kRPC FIles\LaunchIntoOrbitEdited.py", line 9, in <module>
    conn = krpc.connect(name='Launch into orbit')
  File "D:\Python\lib\site-packages\krpc\__init__.py", line 36, in connect
    assert ok_message == Decoder.OK_MESSAGE
AssertionError

in Python after attempting to execute a script

 

Link to comment
Share on other sites

That error suggests that the server plugin is version 0.4.x but the client is to old to communicate with it. You need to update your python client library to version 0.4.x.

If you installed it using pip you can run "pip install --upgrade krpc" to do this

Link to comment
Share on other sites

Windows did not have Python listed as a pathway, had to go into system variables to change it back.  

I then had to delete my old client libraries and re-install from scratch. 

 

Edited by Bosun
Link to comment
Share on other sites

I'm attempting to use Krpc with Kerbal 1.4.3, but receive the following message when starting KSP " Incompatible mods detected....Incompatible with 1.4.3....KRPC".  Being a stubborn fool, I continue to march, but receive the following message when attempting to start the Krpc server... " Socket error  ACCESS DENIED  An attempt was made to access a socket in a way forbidden by it's access permissions".  Just so you know, my level of knowledge about this stuff is somewhere below sea level, but any help would be appreciated.  Thanks...

Link to comment
Share on other sites

Is there a way to directly control rocket gimbal and control surface activation on a per-part basis? I'm implementing a control system that needs to produce independent inputs to the engine and the aerodynamic controls, but can't figure out if there's an interface to do so.

Link to comment
Share on other sites

On 5/3/2018 at 12:51 PM, sking06 said:

I'm attempting to use Krpc with Kerbal 1.4.3, but receive the following message when starting KSP " Incompatible mods detected....Incompatible with 1.4.3....KRPC".  Being a stubborn fool, I continue to march, but receive the following message when attempting to start the Krpc server... " Socket error  ACCESS DENIED  An attempt was made to access a socket in a way forbidden by it's access permissions".

What operating system? On macOS 10.13.4 (High Sierra), I get the "incompatible" warning, but otherwise the mod appears to work correctly.

I think a default server starts automatically, or at least it did for me. Did you try to create an additional server, or did this error pop up on its own?

Link to comment
Share on other sites

Hi Craig...Thanks for the reply. I'm on windows 10 and I also get the incompatible warning. What confused me (and I'm easily confused) was the error message. What it was really trying to tell me was that 50001 was already in use. Once I changed that it worked perfectly.  What I'm trying to do is get the New Kepard space craft to work, but still not having any luck with that part.

Link to comment
Share on other sites

  • 3 weeks later...

I'm having trouble getting reasonable results from simulate_aerodynamic_force_at. It seems to be missing a way to specify the vessel's orientation.  The only thing I can think of is that maybe it uses a default orientation with respect to the reference frame, but I'm not sure how that would work with different reference frames.  An example would be very helpful.

Link to comment
Share on other sites

I just released version 0.4.6. Mainly bug fixes:

  • Removed that annoying incompatible warning with KSP 1.4.3 (as it works fine...)
  • Added game mode, Science, reputation and funds properties
  • LaunchVessel now correctly recovers any vessels on the pad and does all the other pre-flight checks
  • Fixed science transmission
  • Added API for removing stream/event callbacks in all client libraries

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

On 5/30/2018 at 9:26 AM, Kron said:

I'm having trouble getting reasonable results from simulate_aerodynamic_force_at. It seems to be missing a way to specify the vessel's orientation.  The only thing I can think of is that maybe it uses a default orientation with respect to the reference frame, but I'm not sure how that would work with different reference frames.  An example would be very helpful.

The orientation used is the one specified when creating the flight object that you are calling simulate_aerodynamic_force_at. And if you don't specify a reference frame when you call vessel.flight() it defaults to the vessel's surface reference frame. To simulate aero forces using using a custom reference frame your code would need to look something like:

ref_frame = ...
flight = vessel.flight(ref_frame)
return flight.simulate_aerodynamic_forces_at(...)

 

Link to comment
Share on other sites

  • 2 weeks later...
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...