Jump to content

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


djungelorm

Recommended Posts

The big question - maybe in the wrong place:

is there any plan to build this for the new 1.8.x updates using the latest unity?

I’m building a controller that really relies on KRPC. 

seriously, this mod is so cool, I hope they include it as basic functionality in KSP2

Link to comment
Share on other sites

  • 1 year later...

How many folks are using or would be using this?    The previous version still seems to work with 1.12 though I haven't thoroughly tested everything or checked to see if there are features that KRPC can't access yet?  

I've helped a little with updating this mod for new versions in the past and wouldn't be opposed to getting it compiling against 1.12 and make a pull request...  since apparently this is going to be the final game version...  but probably won't bother if I'm the only one who writes full software suites for every rocket in python.  lol.  

 

Link to comment
Share on other sites

  • 2 weeks later...
On 7/22/2021 at 9:16 PM, Kerbart said:

I'd like to see a final 1.12 compile, @artwhaley

Well you're more qualified than me to do it!  :P

I've got things moving.   Compiling against 1.12.2 was super easy, now I'm just trolling the devnotes and release notes for features that got added to the game...   so far working I've got rotating docking ports, all robotic parts except for pistons working (there seems to be a bug in KSP's piston implementation that makes it not respond to anything but the PAW, but I'm hoping someone posts a work-around), lights blinking, new wheel adaptive steering, and fuel drain parts added.

What's left is integration with the now stock alarm clock and maneuver planners, compound part controls, autostruts, and command pods with more than one control point.   There are also a handful of issues on the issue tracker I think are worth trying to duplicate and chase down.   

Has anyone else noticed anything broken or missing that actually affects game play?   At this point in the game / mod's life cycles I'm not concerned about emulating EVERY single button a person could ever possibly click, but want to focus on things that a person might actually want to be able to control remotely/programmatically.   

Link to comment
Share on other sites

  • 3 weeks later...

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

So far I've got 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

  • 3 weeks later...
On 8/28/2021 at 8:07 AM, artwhaley said:

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

So far I've got 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!  

hi! Would it be possible for kRPC to support Gridfins from Kerbal Reusability Expansion ? It didn't work on krpc, but work well on kOS (I think it's an issue with moveable wings in general)

Link to comment
Share on other sites

Ive built a hoverslam script on python 3.9.1 and it works perfectly on my laptop. I copied all of my files over for a friend to try it. Its an exact identical game and mods. It has a while statement that passes while the altitude is below a certain number. When he runs the script he overshoots it like it is hanging, but there doesnt seem to be any loss of function its all just way too delayed. When I add a print statement in the loop to verify the altitude it works perfectly everytime. I cant find anything about a function only working with a print statement in it. He is running python 3.9.7 so maybe that could cause it? Would anyone else have any ideas?  Me and a friend of mine moved away from eachother and we learned to code(barely) by playing this but its impossible to work together online if the scripts react different on different pc's.  Kind of raining on our parade. Ive included the script. We are also playing on 1.11.1. Thank you!

import math
import time
import krpc

#shortcuts
conn = krpc.connect(name='VSpeed')
vessel = conn.space_center.active_vessel
flight = vessel.flight
control = vessel.control
celestial_body = conn.space_center.bodies
kerbin = celestial_body['Kerbin']
srf_frame = vessel.orbit.body.reference_frame
mj = conn.mech_jeb
smartass = mj.smart_ass
interface = smartass.interface_mode
autopilot = smartass.autopilot_mode
srf_frame = vessel.orbit.body.reference_frame

#constants
g = 6.67300 * 10 ** -11
radar_offset = flight().surface_altitude

#global variables
burn_prepare_flag = 0
burn_start_flag = 0
burn_complete_flag = 0


#streams
ut = conn.add_stream(getattr, conn.space_center, 'ut')
altitude = conn.add_stream(getattr, vessel.flight(), 'surface_altitude')
apoapsis = conn.add_stream(getattr, vessel.orbit, 'apoapsis')
vertical_speed = conn.add_stream(getattr, vessel.flight(srf_frame), 'vertical_speed')
gravity = g * kerbin.mass / kerbin.equatorial_radius ** 2


#main

class Vessel:
    
    def launch_autopilot(self, num):
        # Pre-launch setup
        control.sas = False
        control.rcs = False
        smartass.interface_mode = smartass.interface_mode.surface
        smartass.autopilot_mode = smartass.autopilot_mode.surface
        smartass.force_pitch = True
        smartass.force_roll = True
        smartass.surface_pitch = 90
        smartass.surface_roll = 0
        smartass.update(False)

        # Countdown...
        print('3...')
        time.sleep(1)
        print('2...')
        time.sleep(1)
        print('1...')
        time.sleep(1)
        print('Launch!')

        #Activate first stage
        control.throttle = 1.0
        control.activate_next_stage()
        control.toggle_action_group(4)

        while altitude() < num:
            pass

        vessel.control.throttle = 0
        vessel.control.rcs = True
        print('Throttle Down')

        while vertical_speed() > 50:
            pass

        print('Belly Flop Manuever')
        smartass.surface_pitch = 0
        smartass.update(False)



    
    def landing_autopilot(self):
        while True:
            global burn_prepare_flag
            global burn_start_flag
            global burn_complete_flag
            true_radar = altitude() - radar_offset + .1
            max_decel = (vessel.available_thrust/vessel.mass) - gravity
            stop_dist = vertical_speed() **2 / (2* max_decel)
            ideal_throttle = stop_dist / true_radar
            impact_time = true_radar / abs(vertical_speed())
            #print('Altitude ' + str(true_radar))
            #print('Max Decel ' + str(max_decel))
            #print('Stop Distance ' + str(stop_dist))
            #print('Impact Time ' + str(impact_time))
            #print('Vertical Speed: ' + str(vertical_speed()))
            smartass.force_pitch = True
            smartass.force_roll = True
            if burn_prepare_flag == 1:
                pass
            else:
                if vertical_speed() < -1 and true_radar < (stop_dist + 100):
                    print('Preparing for Suicide Burn')
                    control.rcs = True
                    burn_prepare_flag = 1
                else:
                    if vertical_speed() < -1 and true_radar < (stop_dist + 300):
                        smartass.autopilot_mode = smartass.autopilot_mode.surface_retrograde
                        smartass.surface_roll = 0
                        smartass.update(False)
                        control.toggle_action_group(5)
                        
            if burn_start_flag == 1 and burn_complete_flag != 1:
                control.throttle = ideal_throttle
            elif burn_start_flag == 0 and burn_prepare_flag ==1:
                if true_radar < stop_dist:
                    print('Performing Suicide Burn')
                    burn_start_flag = 1
                else:
                    pass
            if altitude() < 500 and burn_start_flag == 1:
                smartass.autopilot_mode = smartass.autopilot_mode.surface
                smartass.surface_pitch = 90
                smartass.surface_roll = 0
                smartass.update(False)

                control.toggle_action_group(6)
                
            if burn_complete_flag == 1:
                break
            else:
                if vertical_speed() > -.01 and burn_start_flag == 1 and true_radar < 2:
                    print('Burn Complete')
                    control.throttle = 0
                    smartass.autopilot_mode = smartass.autopilot_mode.kill_rot
                    smartass.update(False)
                    control.toggle_action_group(2)
                    burn_complete_flag = 1
                    time.sleep(3)
                    control.rcs = False 

            time.sleep(.01)
    def reset_flags(self):
        global burn_prepare_flag
        global burn_start_flag
        global burn_complete_flag
        burn_prepare_flag = 0
        burn_start_flag = 0
        burn_complete_flag = 0


starship = Vessel()
starship.launch_autopilot(1800)
starship.landing_autopilot()
starship.reset_flags()
starship.launch_autopilot(8000)
starship.landing_autopilot()
starship.reset_flags()
starship.launch_autopilot(15000)
starship.landing_autopilot()

 
print('Systems Shutting Down')

 

Link to comment
Share on other sites

  • 1 month 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

  • 11 months later...
1 hour ago, Anth12 said:

https://github.com/nullprofile/krpc/releases/tag/v1.0-beta-1

This is a link to a 1.12.1 version of kRPC.

I don't use the mod so I have no idea how it works compared to the 1.5.1 version

There are more updated versions available from the actions tab: https://github.com/nullprofile/krpc/actions

click the most recent one with a green check mark, then scroll down to artifacts and there should be a link to a zip file to download.

Link to comment
Share on other sites

  • 3 weeks later...
On 10/15/2022 at 2:10 AM, JonnyOThan said:

There are more updated versions available from the actions tab: https://github.com/nullprofile/krpc/actions

click the most recent one with a green check mark, then scroll down to artifacts and there should be a link to a zip file to download.

Just make sure you're logged in on Github, otherwise the "krpc" is not a clickable link. Thanks for the tip!!

UIQ3OXE.png

Edited by LukasKerman
Link to comment
Share on other sites

  • 3 weeks later...

Does anyone know if this mod works with Principia? IE, can get info from principia like their predicted apoapsis and maneuver nodes and reference frames etc.

Also is there any documentation on remote tech integration?
After some looking I did find the remote tech integration, so nvm that

But new questions raised, is there any way to make executed commands use power (ec) in game? or is this already part of it?

Edited by ComputerErika
Found RT Integration Docs, but also questions about power
Link to comment
Share on other sites

  • 2 months later...

Does anyone tried to use python client with Pycharm auto complete feature?

Currently I have to import SpaceCenter

from krpc.spacecenter import SpaceCenter

and type hint object like:

vessel : SpaceCenter.Vessel = conn.space_center.active_vessel

to make Pycharm aware what class it is. But the weird thing is the import statement make the py script crash at start, I have to comment out that line to make it able to start......

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