Jump to content

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


djungelorm

Recommended Posts

On 6/4/2018 at 4:17 PM, djungelorm said:

They're all available on the github releases page: https://github.com/krpc/krpc/releases

Enabling that makes the logging more verbose in KSPs player.log file. These logs aren't viewable in game, but can been in that text log file. It can be found in the following location (which depends on your operating system):

  • Windows: KSP_win\KSP_Data\output_log.txt (32bit) or KSP_win64\KSP_x64_Data\output_log.txt (64bit) or %USERPROFILE%\AppData\LocalLow\Squad\Kerbal Space Program\output_log.txt
  • Mac OS X: Open Console, on the left side of the window there is a menu that says 'files'. Scroll down the list and find the Unity drop down, under Unity there will be Player.log ( Files>~/Library/Logs>Unity>Player.log )
  • Linux: ~/.config/unity3d/Squad/Kerbal\ Space\ Program/Player.log

More details here: https://docs.unity3d.com/Manual/LogFiles.html

The debug logging is only really useful if you are designing your own client library

Thanks! I am working on my own cross-platform (Windows, Android, iOS and macOS) client library, so this will be helpful. I'm basing my implementation on this: https://blog.grijjy.com/2017/04/25/binary-serialization-with-google-protocol-buffers/

Link to comment
Share on other sites

  • 3 weeks later...

I've been making a script that uses terminal_velocity value using vessel.flight(srf_frame).terminal_velocity (based on the Python version from the docs) and it seems that the wrong values for terminal velocity are being calculated

I had it displayed as a separate variable in the console and in the script as well and terminal velocity seems to drop from 7-10 km down to 90 m/s and then hovers around 100m/s until 12km

for kerbalx craft that's premade in the game, it went down to 70m/s at 9km and I'm not sure what's causing this

 

I'm trying to use terminal velocity / velocity ratio to calculate perfect ascent speed, but it's really bugging out all of my take offs right now

 

any suggestions?

Link to comment
Share on other sites

Update: resolved. Sudo ignored mats lib after easy install of nose and tornado.

  I'm trying to get krpc to work but keep getting an error message when I pip install krpc. I don't understand why this happening. I installed pip and have followed the required steps. Here's my specs and the message:

MacBook Pro 15" 2017, 2.8g i7, 16g RAM, macOS High Sierra 10.13.5, cKan

Gregorys-MacBook-Pro:~ gregory$ pip install krpc

Collecting krpc

  Using cached https://files.pythonhosted.org/packages/eb/75/773436079ec9cc134612d8cc5059ef214bff57f96a774f89dd34aa5eb49e/krpc-0.4.6.zip

Collecting protobuf>=3 (from krpc)

  Using cached https://files.pythonhosted.org/packages/4f/56/a21f2d077ceae7fd521c0ed31fb8bb1c7f13ffbb09bf7dd27de6cf6bad08/protobuf-3.6.0-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl

Collecting enum34>=0.9 (from krpc)

  Using cached https://files.pythonhosted.org/packages/c5/db/e56e6b4bbac7c4a06de1c50de6fe1ef3810018ae11732a50f15f62c7d050/enum34-1.1.6-py2-none-any.whl

Requirement already satisfied: setuptools in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from protobuf>=3->krpc) (18.5)

Collecting six>=1.9 (from protobuf>=3->krpc)

  Using cached https://files.pythonhosted.org/packages/67/4b/141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-py2.py3-none-any.whl

matplotlib 1.3.1 requires nose, which is not installed.

matplotlib 1.3.1 requires tornado, which is not installed.

Installing collected packages: six, protobuf, enum34, krpc

  Found existing installation: six 1.4.1

Cannot uninstall 'six'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

Edited by piggermortis
Resolved
Link to comment
Share on other sites

On 6/4/2018 at 6:35 PM, djungelorm said:

I submitted a pull request on the krpcmj project a while ago (https://github.com/artwhaley/krpcmj/pull/4). It got merged, but the DLL in the repository was never updated.

In the meantime, you can download a copy of the DLL built with the patch from here: https://www.dropbox.com/s/6vbrugddsf5vknn/krpcmj.dll?dl=0

Also that log file you posted doesn't actually help. Confusingly there are two log files with KSP. The player.log probably has the illuminating error messages in it... See above for where to find it.

I've got the patch but keep getting this error when trying to use krpcmj.

 krpc.error.RPCError
  Message=Object reference not set to an instance of an object
Server stack trace:
  at krpcmj.krpcmj.Biome () [0x00000] in <filename unknown>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
  StackTrace:
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\krpc\client.py:140 in Client._invoke
<string>:1 in <lambda>

 

Got any idea what i'm doing wrong?

Link to comment
Share on other sites

  • 2 weeks later...

EDIT2: The answer is that Python essentially passes everything by reference. This is yet another reason the inventors of it should be tried for crimes against humanity.

I'm having an issue where I think setting a variable to a stream "locks" it to the stream, instead of storing the value at that time. Is this correct and intended? How does one capture the momentary value?

spd_h = conn.add_stream(getattr, vessel.flight(ref_frame), 'horizontal_speed')
spd_h_prev = spd_h()
time.sleep(tick)
delta_spd = spd_h() - spd_h_prev

delta_spd returns 0.0. spd_h() works fine and returns correct values.

This works:

spd_h_prev = vessel.flight(ref_frame).horizontal_speed
time.sleep(tick)
delta_spd = vessel.flight(ref_frame).horizontal_speed - spd_h_prev

delta_spd returns a sensible number.

KSP 1.3.1, KRPC 0.4.4.

EDIT: In Python if that wasn't obvious. I'm thinking this is a Python problem.

Edited by FleshJeb
Link to comment
Share on other sites

  • 2 weeks later...

Looking for a bit of help/direction with the last piece to this script I'm working on.  I'm attempting to use kRPC to automatically create maneuver nodes based on my current vessel's planetary target.  I believe I have it almost complete, except for calculating the final position of the maneuver node based off the ejection angle.  Here is what I have so far in python:

# used for vector math for finding ejection angle
def cross(u,v):
    return (
        u[1]*v[2] - u[2]*v[1],
        u[2]*v[0] - u[0]*v[2],
        u[0]*v[1] - u[1]*v[0])

# used for vector math for finding ejection angle
def dot(u,v):
    return u[0]*v[0]+u[1]*v[1]+u[2]*v[2]

# calculate transfer window
def planetary_transfer(target_planet):
    sas = vessel.control.sas
    mu = conn.space_center.CelestialBody(int(str((conn.space_center.bodies['Sun']))[42:-1])).gravitational_parameter                    # gravitational constant of kerbol
    r = conn.space_center.CelestialBody(int(str((conn.space_center.bodies[target_planet]))[42:-1])).orbit.semi_major_axis               # semi-major axis of the target planet
    k = conn.space_center.CelestialBody(int(str(vessel.orbit.body)[42:-1])).orbit.semi_major_axis                                       # semi-major axis of the current planet
    a = (k + r) / 2.                                                                                                                    # a = (r1 + r2)/2   
    t = (2. * math.pi * math.sqrt(a**3 / mu)) / 2.                                                                                      # Kepler's Third Law (2*PI*sqrt((a^3)/GM)) divide by 2
    phase_angle = 180 - math.sqrt(mu / r) * t / r * 180 / math.pi                                                                       # optimal angle between current planet and target planet

    soi = conn.space_center.CelestialBody(int(str(vessel.orbit.body)[42:-1])).sphere_of_influence                                       # SOI of current planet
    d = vessel.orbit.radius                                                                                                             # radius of vessel from center of mass
    v = math.sqrt(mu / (soi + k)) * (math.sqrt((2. * r) / (soi + k + r)) - 1.)                                                          # change in velocity needed for the Hohmann transfer
    kmu = conn.space_center.CelestialBody(int(str(vessel.orbit.body)[42:-1])).gravitational_parameter                                   # gravitational constant of current planet
    ejection_velocity = math.sqrt((d * (soi * v**2 - 2. * kmu) + 2. * soi * kmu) / (d * soi))                                           # velocity required to escape current planet SOI

    ejection_angle = 180 - math.degrees(math.acos(math.sqrt(kmu**2 / (kmu - ejection_velocity**2 * d)**2)))                             # angle to start ejection burn

    dtt = distance_to_target()                                                                                                          #distance from origin planet to target
    ct = conn.space_center.CelestialBody(int(str((conn.space_center.bodies[target_planet]))[42:-1])).orbit.radius                       #current target's distance from kerbol
    co = conn.space_center.CelestialBody(int(str(vessel.orbit.body)[42:-1])).orbit.radius                                               #origin planet's distance from kerbol
    current_angle = 180 - (math.degrees(math.cos((ct**2 + co**2 - dtt**2)/(2*ct*co))))                                                  #current phase angle between origin and target planet
    ut = conn.add_stream(getattr, conn.space_center, 'ut')                                                                              #universal time
    cop = conn.space_center.CelestialBody(int(str(vessel.orbit.body)[42:-1])).orbit.period                                              #origin planet's orbital period
    top = conn.space_center.CelestialBody(int(str((conn.space_center.bodies[target_planet]))[42:-1])).orbit.period                      #target planet's orbital period
    cdc = cop/360                                                                                                                       #how many seconds origin planet takes to move 1 degree
    tdc = cdc/top * 360                                                                                                                 #how many degrees does target move in relation to origin

    angle_dif = current_angle - phase_angle
    time_to_phase_angle = ((angle_dif/tdc)/360) * cop                                                                                   #how many seconds until angle equals phase angle
    delta_v = (ejection_velocity - math.sqrt(kmu/d))                                                                                    #delta_v required for burn to reach ejection velocity

    time_to_ejection_angle = 0 #TODO - figure out current angle in relation to origin planet's prograde movement

    # these vectors are all in orbital_reference_frame
    prograde = (0,1,0)
    retrograde = (0,-1,0)
    radial_out = (-1,0,0)
    radial_in = (1,0,0)
    normal = (0,0,1)
    antinormal = (0,0,-1)

    reference_frame = conn.space_center.CelestialBody(int(str(vessel.orbit.body)[42:-1])).orbital_reference_frame

    # TODO - figure out final node position and place it in relation to ejection angle
    # requires current node position compared to orbital reference frame prograde position
    # use vector math to calculate the current angle

    # calculate burn time (using Tsiolkovsky rocket equation: https://en.wikipedia.org/wiki/Tsiolkovsky_rocket_equation)
    F = vessel.available_thrust
    Isp = vessel.specific_impulse * 9.82
    m0 = vessel.mass
    m1 = m0 / math.exp(delta_v/Isp)
    flow_rate = F / Isp
    burn_time = (m0 - m1) / flow_rate

    node = vessel.control.add_node(ut() + time_to_phase_angle + time_to_ejection_angle, prograde=delta_v, radial=0)                     # create maneuver node

    ap = vessel.auto_pilot
    ap.engage()
    ap.reference_frame = node.reference_frame
    ap.target_direction = (0, 1, 0)
    ap.wait()

    burn_ut = ut() + time_to_phase_angle + time_to_ejection_angle - (burn_time/2.)
    lead_time = 10
    conn.space_center.warp_to(burn_ut - lead_time)

    time_to_node = node.time_to
    while time_to_node - (burn_time/2.) > 0:
        pass
    time.sleep(burn_time - 0.0)
    vessel.control.throttle = 0.05
    remaining_burn = conn.add_stream(node.remaining_burn_vector, node.reference_frame)
    while remaining_burn()[1] > 3.0:
        pass
    vessel.control.throttle = 0.0
    node.remove()
    if sas is True:
        vessel.control.sas = True
    ap.disengage()

 

Link to comment
Share on other sites

(C#)

Hello, I'm having a hard time with exceptions thrown when I try to Undock() a docking port, I searched for scripts on the internet which should probably solve my problem, but I couldn't find any useful examples. Maybe I'm making a silly mistake but I can't figure it out what exactly is. =(

I'm looping foreach docking port attached to my Vessel, and if it is docked to something, I want to Undock() it, but I keep getting an error message. Can you guys help me?

foreach (DockingPort dockPort in vessel.Get().Parts.DockingPorts) { if (...)...

spaceCenter.ActiveVessel = dockPort.Undock();

 }

 

Thanks for your attention.

The exceptions are as follows:

KRPC.Client.RPCException
  HResult=0x80131500
  Message=Field '.BaseEvent.guiName' not found.
Server stack trace: 
  at System.Linq.Enumerable.First[BaseEvent] (IEnumerable`1 source, System.Func`2 predicate, Fallback fallback) [0x00000] in <filename unknown>:0 
  at System.Linq.Enumerable.FirstOrDefault[BaseEvent] (IEnumerable`1 source, System.Func`2 predicate) [0x00000] in <filename unknown>:0 
  at KRPC.SpaceCenter.Services.Parts.DockingPort.InvokeEvent (.PartModule module, System.String eventName) [0x00000] in <filename unknown>:0 
  at KRPC.SpaceCenter.Services.Parts.DockingPort.Undock () [0x00000] in <filename unknown>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
  Source=KRPC.Client
  StackTrace:
   at KRPC.Client.Connection.Invoke(ProcedureCall call)
   at KRPC.Client.Connection.Invoke(String service, String procedure, IList`1 arguments)
   at KRPC.Client.Services.SpaceCenter.DockingPort.Undock()
   at Kerb_Konnect_Project.KerbKonnect.Main() in G:\Projects\Kerb Konnect Project\Kerb Konnect Project\KerbKonnect.cs:line 58
 

Edited by LuccasSantos
Link to comment
Share on other sites

On 6/23/2018 at 1:03 PM, AnTREXon said:

I've been making a script that uses terminal_velocity value using vessel.flight(srf_frame).terminal_velocity (based on the Python version from the docs) and it seems that the wrong values for terminal velocity are being calculated

I had it displayed as a separate variable in the console and in the script as well and terminal velocity seems to drop from 7-10 km down to 90 m/s and then hovers around 100m/s until 12km

for kerbalx craft that's premade in the game, it went down to 70m/s at 9km and I'm not sure what's causing this

 

I'm trying to use terminal velocity / velocity ratio to calculate perfect ascent speed, but it's really bugging out all of my take offs right now

  

any suggestions?

I had a look at the code for computing terminal velocity, and compared it to how Kerbal Engineer Redux works and they are very different. It's possible that the terminal velocity calculation in kRPC is just totally wrong - and there are no comments in the code explaining what it's doing. I might just recode it to use the same math as KER.

On 6/25/2018 at 3:11 PM, daniel.hamel said:

I've got the patch but keep getting this error when trying to use krpcmj.

 krpc.error.RPCError
  Message=Object reference not set to an instance of an object
Server stack trace:
  at krpcmj.krpcmj.Biome () [0x00000] in <filename unknown>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
  StackTrace:
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\krpc\client.py:140 in Client._invoke
<string>:1 in <lambda>

 

Got any idea what i'm doing wrong?

Must be a bug in krpcmj. It was coded for a much older version of KSP, so maybe something changed in the KSP API that breaks it.

Link to comment
Share on other sites

On 7/6/2018 at 7:39 PM, FleshJeb said:

EDIT2: The answer is that Python essentially passes everything by reference. This is yet another reason the inventors of it should be tried for crimes against humanity.

I'm having an issue where I think setting a variable to a stream "locks" it to the stream, instead of storing the value at that time. Is this correct and intended? How does one capture the momentary value?


spd_h = conn.add_stream(getattr, vessel.flight(ref_frame), 'horizontal_speed')
spd_h_prev = spd_h()
time.sleep(tick)
delta_spd = spd_h() - spd_h_prev

delta_spd returns 0.0. spd_h() works fine and returns correct values.

This works:


spd_h_prev = vessel.flight(ref_frame).horizontal_speed
time.sleep(tick)
delta_spd = vessel.flight(ref_frame).horizontal_speed - spd_h_prev

delta_spd returns a sensible number.

KSP 1.3.1, KRPC 0.4.4.

EDIT: In Python if that wasn't obvious. I'm thinking this is a Python problem.

Are you sure its not just that sph_h() is always returning zero? It depends on ref_frame. If the reference frame moves with the vessel, then the horizontal speed will always be zero, and so will delta_spd. If this is the case, try with ref_frame = vessel.orbit.body.reference_frame

sph_h() is returning floating point values, which will be passed by value in python, so I don't think that's the issue here? Python only passes objects by reference, not simple types like float and int.

On 7/18/2018 at 12:51 AM, LuccasSantos said:

(C#)

Hello, I'm having a hard time with exceptions thrown when I try to Undock() a docking port, I searched for scripts on the internet which should probably solve my problem, but I couldn't find any useful examples. Maybe I'm making a silly mistake but I can't figure it out what exactly is. =(

I'm looping foreach docking port attached to my Vessel, and if it is docked to something, I want to Undock() it, but I keep getting an error message. Can you guys help me?

foreach (DockingPort dockPort in vessel.Get().Parts.DockingPorts) { if (...)...

spaceCenter.ActiveVessel = dockPort.Undock();

 }

 

Thanks for your attention.

The exceptions are as follows:

KRPC.Client.RPCException
  HResult=0x80131500
  Message=Field '.BaseEvent.guiName' not found.
Server stack trace: 
  at System.Linq.Enumerable.First[BaseEvent] (IEnumerable`1 source, System.Func`2 predicate, Fallback fallback) [0x00000] in <filename unknown>:0 
  at System.Linq.Enumerable.FirstOrDefault[BaseEvent] (IEnumerable`1 source, System.Func`2 predicate) [0x00000] in <filename unknown>:0 
  at KRPC.SpaceCenter.Services.Parts.DockingPort.InvokeEvent (.PartModule module, System.String eventName) [0x00000] in <filename unknown>:0 
  at KRPC.SpaceCenter.Services.Parts.DockingPort.Undock () [0x00000] in <filename unknown>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
  Source=KRPC.Client
  StackTrace:
   at KRPC.Client.Connection.Invoke(ProcedureCall call)
   at KRPC.Client.Connection.Invoke(String service, String procedure, IList`1 arguments)
   at KRPC.Client.Services.SpaceCenter.DockingPort.Undock()
   at Kerb_Konnect_Project.KerbKonnect.Main() in G:\Projects\Kerb Konnect Project\Kerb Konnect Project\KerbKonnect.cs:line 58
 

I think this is a build issue with the current release of kRPC. This has affected a few other things too (including issue 481 and issue 483). Hopefully this will magically fix itself in the next release (which I plan to do sometime this week). In the meantime you could also try this pre-release to see if it fixes the build issue: https://krpc.s3.amazonaws.com/deploy/master/1196.1/krpc-0.4.7-22-g09e0c1c.zip

Link to comment
Share on other sites

  • 2 months later...

Hey, I just wanted to drop by and say I love this mod. It's enabled me to do some things I would've never been able to do otherwise

 

Edit: Woops I just realized this is the dev thread. Sorry about that :P

Edited by kendoka15
Link to comment
Share on other sites

  • 4 weeks later...

kRPC v0.4.8 has been released!

The main new addition is that a lot of functionality is now accessible not just from the flight scene, but from other game scenes too! The documentation website also includes a note by every function indicating which scene(s) it is available in.

Support for KSP 1.5.1 and Infernal Robotics NEXT is also included in this release. The "NameTag" mod that allowed name tags to be shared between kRPC and kOS has also now been merged into kRPC, so the separate mod is no longer required.

A full change log is available here

Link to comment
Share on other sites

  • 1 month later...

We've been discussing on the Discord that the autopilot appears to be having problems with roll. I think it's a PID-tuning problem in KRPC.

The behavior it exhibits is that it will try to roll hard left, and keep rotating while trying to hold the pitch and heading. If you override with manual steering and get it close, then let go, it will occasionally roll right, and when it crosses through the correct roll, it will start the hard left roll again.

This code SHOULD work for flying a plane (KSP 1.5.1, KRPC 0.4.8):

import krpc
import time
conn = krpc.connect(name='ap')
vessel = conn.space_center.active_vessel
ap = vessel.auto_pilot

ref_frame = vessel.surface_velocity_reference_frame

# I also tried this, which i think is the same as above.
#ref_frame = conn.space_center.ReferenceFrame.create_hybrid (
#    position=vessel.orbit.body.reference_frame,
#    rotation=vessel.surface_reference_frame )

ap.reference_frame = ref_frame
ap.attenuation_angle = (1.0, 1.0, 1.0)
ap.target_heading = 90.0
ap.target_pitch = 5.0
ap.target_roll = 0.0
ap.engage()
i = 0
while (True):
    ap.target_heading = 90.0
    ap.target_pitch = 5.0
    ap.target_roll = 0.0
    ap.engage()
    print("tick" + str(i))
    time.sleep(1.0)
    i += 1

 

Edited by FleshJeb
Link to comment
Share on other sites

  • 1 month later...

I am a newbie to KRPC, but I was wondering if there was a mechanism for getting server/game time stamps for the state of a variable, such as the vessel’s velocity vector. Say I registered a stream for velocity, and I query the stream at client time t0 and then slightly later at time t1. Is there a way to know the sever/simulation side elapsed time between the 2 observations?

I would think just having client side t0 and t1 and thus client side elapsed time (delta t) wouldn’t be nearly as accurate. Say for use in a client side PID algorithm, for control of some Kerbal system over KRPC.

 

Sorry if this is not the right place to be asking such a thing.

Thanks, 

Ender

Edited by Ender1618
Link to comment
Share on other sites

Hi good afternoon.
have now this krpc with the arduino mega2560
driven. I can do the control with the keypad throttle +- and stage.
this is just a test. you can move much more with the mega2560.
on the mega2560 I have serial2 usb-ttl) to the pc (python-krpc) and the data output (data_velo, 
data_alti, data_apoa) I do about the serial port of the mega2560 with what you previously 
synonymous program transmits.
the data can be later synonymous to a lcd display output, which is connected to the mega2560.

the throttle and stage control also works with one
bluetooth module hc-05 at the mega2560 and a table. I wrote program android with B4A.

greeting


Code for Python 2.7 :

import time
import krpc
import serial
	conn = krpc.connect(name='Sub-orbital flight',
       address='127.0.0.1',
       rpc_port=1000, stream_port=1001)
       
vessel = conn.space_center.active_vessel
ref_frame = conn.space_center.ReferenceFrame.create_hybrid(
    position=vessel.orbit.body.reference_frame,
    rotation=vessel.surface_reference_frame)
    
time.sleep(1)
port = "com6"
ser = serial.Serial(port, 9600, timeout=0)
	def throttle_func(par):
        vessel.control.throttle = float(par)
        return
def stage_func():
        vessel.control.activate_next_stage()    
        return        
t=0
data_alti=0
data_velo=0
data_apoa=0
while True:
    time.sleep(0.1)
    s = ser.readline()
    
    if s == '1': 
        t=t+0.1
        throttle_func(t)
    if s == '2': 
        t=t-0.1
        throttle_func(t)    
    if s == '3': 
        stage_func()    
    
    data_velo=round(vessel.flight(ref_frame).speed)    
    data_alti =round(vessel.flight().mean_altitude)        
    data_apoa =round(vessel.orbit.apoapsis_altitude)
    ser.write(str(data_velo)+':'+str(data_alti)+':'+str(data_apoa)+'\n\r')    
    
con.close()
conn.close()


Code for Arduino Mega2560 mit Keypad:

#include <Keypad.h>
 
const byte numRows= 4; 
const byte numCols= 4; 
char keymap[numRows][numCols]= 
{
  {'0', '4', '8', 'C'}, 
  {'1', '5', '9', 'D'}, 
  {'2', '6', 'A', 'E'},
  {'3', '7', 'B', 'F'}
};
 
byte rowPins[numRows] = {53,51,49,47}; //Rows 0 to 3
byte colPins[numCols]= {45,43,41,39}; //Columns 0 to 3
byte inbyte;
byte throttle_p;
byte throttle_m;
byte stage;
 
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);
 
void setup()
{
  Serial2.begin(9600);
  Serial.begin(9600); 
    
  throttle_p=1;
  throttle_m=2;
  stage=3;
}
 
void loop()
{
  char keypressed = myKeypad.getKey();
  if (Serial2.available()){
    inbyte = Serial2.read();
    Serial.write(inbyte);
  }
  
  if (keypressed =='0') {
    Serial2.print(throttle_p);
  } 
  if (keypressed =='1') {
    Serial2.print(throttle_m);
  } 
  if (keypressed =='2') {
    Serial2.print(stage);
  } 
  
}

Code for Arduino Mega2560 mit hc-05:

byte inbyte;
byte throttle_p;
byte throttle_m;
byte stage;
	void setup() 
{
    Serial1.begin(9600);  
    Serial2.begin(9600);  
        Serial.begin(9600);  
   throttle_p=1;
   throttle_m=2;
   stage=3;
}
 
void loop()
{
   if (Serial2.available())
   {
     inbyte = Serial2.read();
     Serial.write(inbyte);
   }
  
   if (Serial1.available())
    {  
        inbyte = Serial1.read();
        
        if(inbyte == 50)
        {
          Serial2.print(throttle_p);
        }  
        if(inbyte == 51)
        {
          Serial2.print(throttle_m);
        }  
        if(inbyte == 52)
        {
          Serial2.print(stage);
        }  
    }
}
Edited by funkheld
Link to comment
Share on other sites

I’m getting an exception inside SpaceCenter.LaunchVessel.  Details here: https://github.com/krpc/krpc/issues/516

It seems like this is a simple null check, so I figured I could probably fix it myself. But I’m having trouble compiling krpc on windows.  I get the following error:

bazel-out/x64_windows-fastbuild/genfiles/server/KRPC.run_shell_0.sh: line 2: mcs: command not found

I added mono/lib/mono-4.5 to the path, and I can type “mcs” at the command prompt and it is found, so I don’t know why bash can’t find it.

 

Link to comment
Share on other sites

  • 6 months later...
  • 3 weeks later...
19 hours ago, Boyanski said:

Absolutely terrible for beginners... No clear way of describing what and how to do.

The kRPC documentation is not intended to be a beginners guide to C#. I suggest you check this out first: https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/intro-to-csharp/

On 8/22/2019 at 12:15 PM, GreenDude said:

Hi guys.  Is it possible to access stage locking (Alt-L) through krpc?

Dean.

Not currently. Added a github issue to get this added here: https://github.com/krpc/krpc/issues/541

Link to comment
Share on other sites

56 minutes ago, djungelorm said:

The kRPC documentation is not intended to be a beginners guide to C#. I suggest you check this out first: https://docs.microsoft.com/en-us/dotnet/csharp/tutorials/intro-to-csharp/

Not currently. Added a github issue to get this added here: https://github.com/krpc/krpc/issues/541

Sorry for rude comment. I also tried to use an Arduino, but I only got as far as communicating with the server. I changed the library names in "Calling remote procedures" code but it doesn't work?

Link to comment
Share on other sites

10 hours ago, Boyanski said:

Sorry for rude comment. I also tried to use an Arduino, but I only got as far as communicating with the server. I changed the library names in "Calling remote procedures" code but it doesn't work?

No worries. Can you be more specific as to what doesn't work? Maybe post the code you are trying to use and what (if any) error messages you are seeing?

We also have a reasonably active discord group, might be better asking questions on there as you might get a more timely response :) https://discord.gg/bXuaTrj

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