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 11/18/2016 at 9:58 AM, TheKraken2000 said:

Hi, I want to thank you for this great mod.

Currently I am learning Java at school so most of the time my programming is based of trial and error.

But even after a lot of testing I don't seem to get the output for the vessel speed working: no matter when I check it, it always gives "0.0" back.

Here is the part of my code:

    public double getVerticalSpeed() throws IOException, RPCException, StreamException
    {      
        this.surfaceReferenceFrame = vessel.getSurfaceReferenceFrame();
        return flight.getVerticalSpeed();   
    }

The methods getSpeed,getVerticalSpeed and getHorizontalSpeed are not working. Any clue what my failure could be?

However the method getTrueAirSpeed() is working for me.

Thanks in advance.

According to the documentation, the surface reference frame moves with the vessel. This means that your code is measuring the velocity of the vessel relative to itself, which is 0.

Try using a reference frame that is relative to the CelestialBody instead. "vessel.getOrbit().getBody().getReferenceFrame()" should get you one that rotates with the planet allowing you to get speeds relative to the ground.

I'm not too familiar with the JavaAPI (I mostly work with the Python one) but I'm also not sure whether the line "this.surfaceReferenceFrame = vessel.getSurfaceReferenceFrame();" actually sets the reference frame for use with the functions. Try passing reference frames as parameters to the functions instead. Something like "return flight.getVerticalSpeed(refFrame);" after you've set refFrame to be whatever reference frame you want to use.

 

Link to comment
Share on other sites

Is there any way to make this work with extended action groups. I am building a simulator with a bunch of different buttons and I need more than 10. Extended action groups has 250, but it only works with kos to my knowledge. Anyone have any insight? Is it possible?

Edited by Kotagi
Link to comment
Share on other sites

  • 2 weeks later...

Maybe this would be obvious as soon as I start trying to use kRPC, but I'm curious if one can use kRPC command several vehicles at the same time.

For example, simultaneously flying an upper stage into orbit while landing a fly-back booster back at KSC. Or maybe less challenging in terms of simultaneity, running orbit-transfer burns on three or more vehicles in the same window.

Cheers.

Link to comment
Share on other sites

On 11/16/2016 at 1:45 AM, xrayfishx said:

I'm using this thing for the first time (with Python if it matters) and I'm trying to figure out this: is there a way to measure in-game time rather than real time for my scripts? Basically something similar to time.sleep except based on in-game time? What I'm trying to use so far is a custom sleep function using vessel.met, but would it work if the vessel is still on the launchpad and MET timer hasn't started?

Edit: Well I got the time measurement to work as I want it with vessel.met, so it works under time acceleration, but I'm still wondering if it works for something that's on a launchpad and if not, then whether there's a better way.

You can get the in-game time (called "Universal Time") using space_center.ut. Also, you can use space_center.warp_to to warp to a chosen universal time. Should work fine while you're on the launchpad - if I remember correctly MET is always 0 when you're on the launchpad.

On 12/15/2016 at 5:35 PM, aeroNelson said:

Maybe this would be obvious as soon as I start trying to use kRPC, but I'm curious if one can use kRPC command several vehicles at the same time.

For example, simultaneously flying an upper stage into orbit while landing a fly-back booster back at KSC. Or maybe less challenging in terms of simultaneity, running orbit-transfer burns on three or more vehicles in the same window.

Cheers.

Indeed you can! All the vessels in the game can be accessed via space_center.vessels, so you can iterate through that list to find the other vessel, then use the functionality in vessel.control as usual. There is however the restriction that, in order to control a vessel, it must be within physics range of the active vessel - I think its 22.5km by default.

On 12/16/2016 at 2:28 AM, cknowles2112 said:

This is an awesome plugin - any word on when 1.2.x support will be happening?  I'm using it in a simpit - and I miss my physical controls!

CJK

The latest pre-release for 1.2.x is available here: https://krpc.s3.amazonaws.com/deploy/master/756.1/krpc-0.3.7-122-ge9f70cf.zip

Only known issue preventing me from releasing it is a bug with the moment of inertia calculations when using RCS, so the autopilot might be a bit dodgy if you fly with RCS enabled. Other than that it should work fine!

 

Edited by djungelorm
Update link to latest 1.2.2 compatible build
Link to comment
Share on other sites

  • 2 weeks later...

Version 0.3.7 has been released! Happy Christmas!

Here's a summary of the changes:

A full changelog is available here: https://github.com/krpc/krpc/releases/tag/v0.3.7

Edited by djungelorm
Link to comment
Share on other sites

  • 3 weeks later...

I'm trying to get into kRPC but I ran into trouble installing the libraries. I'm not very experienced with Visual Studio and couldn't find much on how to install those libraries. It looks like that's just something I'm expected to know.

I've downloaded Asio 1.10.6 and Protobuf 3.1.0 for C++. Can someone maybe quickly walk me through how to install those libraries and configure VS to run scripts? Or is there a more detailed tutorial somewhere that I haven't seen?

Edited by EmbersArc
Link to comment
Share on other sites

Okay I tried it on Ubuntu 16.04 instead. Here's what I did:

Install ASIO:

sudo apt-get install libasio-dev

Install Protobuf:

(downloaded source from github)

$ sudo apt-get install autoconf automake libtool curl make g++ unzip

$ ./autogen.sh

$ ./configure
$ make
$ make check
$ sudo make install
$ sudo ldconfig # refresh shared library cache.

That all worked fine.

Install kRPC:

(downloaded krpc-cpp-3.7.0)

./configure
make

at "make" I got an error:

../include/krpc/krpc.pb.hpp:3821:90: error: no matching function for call to ‘google::protobuf::internal::ArenaStringPtr::GetNoArena(const string*) const’
 sion_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
                                                                              ^
In file included from ../include/krpc/krpc.pb.hpp:23:0,
                 from ../include/krpc/client.hpp:8,
                 from client.cpp:1:
/usr/local/include/google/protobuf/arenastring.h:225:31: note: candidate: const string& google::protobuf::internal::ArenaStringPtr::GetNoArena() const
   inline const ::std::string& GetNoArena() const { return *ptr_; }
                               ^

Is it missing some part of protobuf?

Sorry if I'm being annoying but maybe someone can help.

Link to comment
Share on other sites

@EmbersArc I tried building it following the same procedure as you, but don't get any errors at all!

I used docker to test it out using a clean install of 16.04. The Dockerfile I used is:

FROM ubuntu:16.04

RUN apt-get update && \
    apt-get install -y \
    wget \
    libasio-dev \
    autoconf automake libtool curl make g++ unzip

RUN wget https://github.com/google/protobuf/releases/download/v3.1.0/protobuf-cpp-3.1.0.tar.gz && \
    tar -xf protobuf-cpp-3.1.0.tar.gz

RUN cd protobuf-3.1.0 && \
    ./autogen.sh && \
    ./configure && \
    make -j8 && \
    make check -j8 && \
    make install && \
    ldconfig

RUN wget https://github.com/krpc/krpc/releases/download/v0.3.7/krpc-cpp-0.3.7.zip && \
    unzip krpc-cpp-0.3.7.zip

RUN cd krpc-cpp-0.3.7 && \
    ./configure && \
    make -j8

Just to check: which version of protobuf are you using? v3.1.0 is required.

Is that the only error message you get? If not, could you post the entire output from gcc?

Link to comment
Share on other sites

@djungelorm Thanks for helping. I didn't get the notification that you answered so I kept beating my head against a wall for a bit longer :D. I just noticed that I was making the stupid mistake of using protobuf version 2. I didn't realize that while compiling it from the first github link in the installation instructions. I've now used the file from the second link (version 3.1.0) and that worked perfectly.

Another problem has come up though after running the program:

g++ main.cpp -std=c++11 -lkrpc -lprotobuf

//usr/local/lib/libkrpc.so: undefined reference to `google::protobuf::io::CodedOutputStream::WriteVarint64ToArray(unsigned long, unsigned char*)'
//usr/local/lib/libkrpc.so: undefined reference to `google::protobuf::internal::GeneratedMessageReflection::NewGeneratedMessageReflection(google::protobuf::Descriptor const*, google::protobuf::Message const*, int const*, int, int, int, int, int, int)'
//usr/local/lib/libkrpc.so: undefined reference to `google::protobuf::internal::MergeFromFail(char const*, int)'
collect2: error: ld returned 1 exit status

Did I confuse it by first installing version 2 and then 3?

Link to comment
Share on other sites

56 minutes ago, djungelorm said:

@EmbersArc potentially yeh. Try compiling with -l:libprotobuf.so.11 to force it to use the correct version of the library.

Tried -l:libprotobuf.so.11 but the result was the same.

Good news though:

After reinstalling Ubuntu (at least something I have a lot of experience with) I did everything exactly like it is in the docker file and it works perfectly. Was also able to get it to work with eclipse.
Maybe it would be helpful to have exactly those steps in the tutorial for the beginners like me. Just an idea, maybe not.

Thanks again.

Link to comment
Share on other sites

Hey,

at the moment i use kOs for my automatisation. I found randomly that mod, and i like the idea of coding in a known language with the ability of writing classes and so on.
One thing i am a bit confused at, is the possibilty to have some default file. So is it possible to say this rocket default run a specific script ? And is there some physical storage on the rocket?

Thanks for help :)
Regards
Moritz

Link to comment
Share on other sites

On 20/01/2017 at 10:02 AM, moritz31 said:

Hey,

at the moment i use kOs for my automatisation. I found randomly that mod, and i like the idea of coding in a known language with the ability of writing classes and so on.
One thing i am a bit confused at, is the possibilty to have some default file. So is it possible to say this rocket default run a specific script ? And is there some physical storage on the rocket?

Thanks for help :)
Regards
Moritz

Hi!

kRPCs approach is quite different to kOS - there is nothing running "on the rocket" and no concept of physical storage. kRPC just exposes large parts of KSP's API over the network so external client programs can invoke functions. The client script runs outside of the game - in whatever programming environment you like.

There is no default file - the rocket itself (and the game in general) doesn't execute the client script. You need to execute it outside the game. There is, however, nothing stopping you from writing a script that continually checks if there is a new rocket on the launch pad, and if so, runs some other 'default' script.

Link to comment
Share on other sites

  • 4 weeks later...

Okay I've been using this mod for a few weeks now and love it. It was an important part of this reddit post: https://www.reddit.com/r/KerbalSpaceProgram/comments/5td0q9/express_rocket_delivery_krpc/

Now I've run into problems while trying to tweak the code a bit. Maybe someone with C++ experience can help me out.

Here's the code: https://github.com/EmbersArc/kRPC_cpp/tree/master/src

So far the approach has been to store most variables as global variables (see Drone_AerialGrasping.cpp for example). To make it easier to fly more than one vehicle simultaneously, I've now tried to create a class (the "VesselControl" class) that has all the variables in it and can be constructed by giving it the name of the vehicle. In the current state it compiles fine but throws a segmentation fault when't it's executed.

0skMKYk.png

The problem could be the two lines to connect to the space center:

Quote

krpc::Client conn = krpc::connect("N76VZ","10.0.2.2");
krpc::services::SpaceCenter sc(&conn);

Any idea how to implement this so that all functions in the class can access the sc. thingy?

EDIT: What does krpc::services::SpaceCenter sc(&conn); return/create? Is it something I can pass to the classes when they are called?

EDIT: I now put the class and main function in the same file to make it less complicated. Still the same error though. https://github.com/EmbersArc/kRPC_cpp/blob/master/src/Allinone.cpp

EDIT: Found the problem. Made the simple mistake of calling the altitude stream before assigning it. Oops. :rolleyes:

Edited by EmbersArc
Link to comment
Share on other sites

2 hours ago, Assert said:

I am finished very usefull utility using kRPC that allows to launch any rockets to desired orbit with nearly optimum trajectory in one click. May be someone want to test it:)

https://mods.curse.com/ksp-mods/kerbal/261153-launch-control

Not sure if the link is working. What KSP version can this be used in? 

Link to comment
Share on other sites

  • 1 month later...

Version 0.3.8 has been released :)

Here's a summary of the changes:

A full changelog is available here: https://github.com/krpc/krpc/releases/tag/v0.3.8

Edited by djungelorm
Add link to wheel API
Link to comment
Share on other sites

2 hours ago, TheKraken2000 said:

1. The density() method needs not only a String, but also a Connection object.

Thanks for noticing this! The documentation is wrong - I'll need to fix the docs generator. This method is static, which could also be included in the docs, so needs to be passed the connection object as its first parameter.

2 hours ago, TheKraken2000 said:

2. The resourcesInDecoupleStage() Method is not returning the resources that are decoupled in the given stage, but the ones that decoupled in the stage-1

Could you post an example demonstrating this? E.g. a craft file and code snippet that demonstrates the precise problem? I have some fairly thorough tests for this feature, but it is possible that there is a bug.

Link to comment
Share on other sites

That would be a very simple test method:

public void printOxidizer()throws IOException, RPCException
    {
        for(int i= vessel.getControl().getCurrentStage();i>=0;i--)
        {
            System.out.println("Stage: "+i+" Oxidizer: "+vessel.resourcesInDecoupleStage(i, false).amount("Oxidizer"));
        }
    }

Using the Stock ComSat Lx Rocket I get this console log:

Stage: 4 Oxidizer: 0.0
Stage: 3 Oxidizer: 0.0
Stage: 2 Oxidizer: 550.0
Stage: 1 Oxidizer: 0.0
Stage: 0 Oxidizer: 22.0

As you can see the log is telling me that stage 2 will decouple 550 Units of Oxidizer, but in reality it is stage 1 that will do it.

Edited by TheKraken2000
Staging Image is not showing
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...