Advertisement
Guest User

ksp.py

a guest
Apr 14th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.31 KB | None | 0 0
  1. import krpc
  2.  
  3. c = krpc.connect(name="KSP")
  4.  
  5.  
  6. def vesselList():  # lists all the vessels
  7.     vessels = c.space_center.vessels
  8.     for i in vessels:
  9.         print(i.name)
  10.  
  11.  
  12. def selectVessel():
  13.     currentVessel = c.space_center.active_vessel
  14.     # currentvessel.situation
  15.     return currentVessel
  16.  
  17.  
  18. def getFlightData():
  19.     print("Flight Data")
  20.     flightData = {
  21.         "orbitalVelocity": selectVessel().flight(selectVessel().orbit.body.non_rotating_reference_frame).velocity,
  22.         "orbitalSpeed": selectVessel().flight(selectVessel().orbit.body.non_rotating_reference_frame).speed,
  23.         "surfaceVelocity": selectVessel().flight().velocity,
  24.         "surfaceSpeed": selectVessel().flight().speed,
  25.         "hSpeed": selectVessel().flight().horizontal_speed,
  26.         "vSpeed": selectVessel().flight().vertical_speed,
  27.         "gForce": selectVessel().flight(selectVessel().reference_frame).g_force,
  28.         "surfaceAltitude": selectVessel().flight().surface_altitude,
  29.         "bedrockAltitude": selectVessel().flight().bedrock_altitude,
  30.         # =surfaceAlt. but if over water -> above sea ground
  31.         "aboveSealevelAltitude": selectVessel().flight().mean_altitude,
  32.         "terrainHeight": selectVessel().flight().elevation,
  33.         "latitude": selectVessel().flight().latitude,
  34.         "longitude": selectVessel().flight().longitude,
  35.         "rotation": selectVessel().flight().rotation,
  36.         "direction": selectVessel().flight().direction,
  37.         "pitch": selectVessel().flight().pitch,
  38.         "heading": selectVessel().flight().heading,
  39.         "roll": selectVessel().flight().roll,
  40.         "atmoDensity": selectVessel().flight().atmosphere_density,
  41.         "dynPressure": selectVessel().flight().dynamic_pressure,
  42.         # pressure acting on vessel (aerodyn. forces) (pascal)
  43.         "staticPressure": selectVessel().flight().static_pressure,  # static atmo pressure acting on vessel (pascal)
  44.         "aeroForce": selectVessel().flight().aerodynamic_force,  # see doc.
  45.         "aeroLift": selectVessel().flight().lift,  # lift & drag : vectors of force, magnitude : strenght
  46.         "aeroDrag": selectVessel().flight().drag,
  47.         "speedOfSound": selectVessel().flight().speed_of_sound,
  48.         "mach": selectVessel().flight().mach,
  49.         "terminalVelocity": selectVessel().flight().terminal_velocity,  # estimate, depends on current velocity
  50.         "AoA": selectVessel().flight().angle_of_attack,
  51.         "sideslipAngle": selectVessel().flight().sideslip_angle,
  52.         "airTemp_k": selectVessel().flight().static_air_temperature,
  53.     }
  54.     return flightData
  55.  
  56.  
  57. def getVesselData():
  58.     print("Vessel Data")
  59.     vesselData = {
  60.         "vName": selectVessel().name,
  61.         "vType": selectVessel().type,
  62.         "vSituation": selectVessel().situation,
  63.         "missionTime": selectVessel().met,
  64.         "COM": selectVessel().flight().center_of_mass,
  65.         "resNames": selectVessel().resources.names,
  66.         # Resources
  67.         "liquidFuel": selectVessel().resources.amount("LiquidFuel"),
  68.         "oxidizer": selectVessel().resources.amount("Oxidizer"),
  69.         "monoProp": selectVessel().resources.amount("MonoPropellant"),
  70.         "electricCharge": selectVessel().resources.amount("ElectricCharge"),
  71.         "intakeAir": selectVessel().resources.amount("IntakeAir"),
  72.         "solidFuel": selectVessel().resources.amount("SolidFuel"),
  73.         "xenonGas": selectVessel().resources.amount("XenonGas"),
  74.         "ore": selectVessel().resources.amount("Ore"),
  75.         "ablator": selectVessel().resources.amount("Ablator"),
  76.         # ResourcesMax
  77.         "liquidFuelMax": selectVessel().resources.max("LiquidFuel"),
  78.         "oxidizerMax": selectVessel().resources.max("Oxidizer"),
  79.         "monoPropMax": selectVessel().resources.max("MonoPropellant"),
  80.         "electricChargeMax": selectVessel().resources.max("ElectricCharge"),
  81.         "solidFuelMax": selectVessel().resources.max("SolidFuel"),
  82.         "xenonGasMax": selectVessel().resources.max("XenonGas"),
  83.         "oreMax": selectVessel().resources.max("Ore"),
  84.         "ablatorMax": selectVessel().resources.max("Ablator"),
  85.         # Resource Density
  86.         "liquidFuelDensity": selectVessel().resources.density("LiquidFuel"),
  87.         "oxidizerDensity": selectVessel().resources.density("Oxidizer"),
  88.         "monoPropDensity": selectVessel().resources.density("MonoPropellant"),
  89.         "solidFuelDensity": selectVessel().resources.density("SolidFuel"),
  90.         "xenonGasDensity": selectVessel().resources.density("XenonGas"),
  91.         "oreDensity": selectVessel().resources.density("Ore"),
  92.         # Parts
  93.         "partCount": len(selectVessel().parts.all),
  94.         "controlPart": selectVessel().parts.controlling.title,
  95.     }
  96.     return vesselData
  97.  
  98.  
  99. def getOrbitalData():
  100.     print("Orbital Data")
  101.     orbitaldata = {
  102.         "body": selectVessel().orbit.body.name,
  103.         "apoapsis": selectVessel().orbit.apoapsis_altitude,
  104.         "periapsis": selectVessel().orbit.periapsis_altitude,
  105.         "semi_major_axis": selectVessel().orbit.semi_major_axis,
  106.         "semi_minor_axis": selectVessel().orbit.semi_minor_axis,
  107.         "OrbitalRadius": selectVessel().orbit.radius,
  108.         "OrbitalSpeed": selectVessel().orbit.speed,
  109.         "OrbitalPeriod": selectVessel().orbit.period,
  110.         "TTA": selectVessel().orbit.time_to_apoapsis,
  111.         "TTP": selectVessel().orbit.time_to_periapsis,
  112.         "eccentricity": selectVessel().orbit.eccentricity,
  113.         "inclination": selectVessel().orbit.inclination,
  114.         "arg_of_periapsis": selectVessel().orbit.argument_of_periapsis,
  115.         "mean_anomaly_epoch": selectVessel().orbit.mean_anomaly_at_epoch,
  116.         "epoch": selectVessel().orbit.epoch,
  117.         "eccentric_anomaly": selectVessel().orbit.eccentric_anomaly,
  118.         "TTSOIchange": selectVessel().orbit.time_to_soi_change,
  119.     }
  120.     return orbitaldata
  121.  
  122.  
  123. def getNewOrbitalData():
  124.     print("New Orbital Data")
  125.     if selectVessel().orbit.next_orbit == "NoneType":
  126.         newOrbitalData = {
  127.             "new_orbit": True,
  128.             "new_body": selectVessel().orbit.next_orbit.body.name,
  129.             "new_apoapsis": selectVessel().orbit.next_orbit.apoapsis_altitude,
  130.             "new_periapsis": selectVessel().orbit.next_orbit.periapsis_altitude,
  131.             "new_semi_major_axis": selectVessel().orbit.next_orbit.semi_major_axis,
  132.             "new_semi_minor_axis": selectVessel().orbit.next_orbit.semi_minor_axis,
  133.             "new_orbitalRadius": selectVessel().orbit.next_orbit.radius,
  134.             "new_orbitalSpeed": selectVessel().orbit.next_orbit.speed,
  135.             "new_orbitalPeriod": selectVessel().orbit.next_orbit.period,
  136.             "new_TTA": selectVessel().orbit.next_orbit.time_to_apoapsis,
  137.             "new_TTP": selectVessel().orbit.next_orbit.time_to_periapsis,
  138.             "new_eccentricity": selectVessel().orbit.next_orbit.eccentricity,
  139.             "new_inclination": selectVessel().orbit.next_orbit.inclination,
  140.             "new_argOfPeriapsis": selectVessel().orbit.next_orbit.argument_of_periapsis,
  141.             "new_meanAnomalyEpoch": selectVessel().orbit.next_orbit.mean_anomaly_at_epoch,
  142.             "new_epoch": selectVessel().orbit.next_orbit.epoch,
  143.             "new_eccentricAnomaly": selectVessel().orbit.next_orbit.eccentric_anomaly,
  144.             "new_TTSOIchange": selectVessel().orbit.next_orbit.time_to_soi_change,
  145.         }
  146.         return newOrbitalData
  147.     else:
  148.         print("No change.")
  149.         new_orbit = False
  150.         return new_orbit
  151.  
  152.  
  153. def getNodeData(var):
  154.     print("Node Data")
  155.     node_list = selectVessel().control.nodes
  156.     if len(node_list) != 0:
  157.         node_exist = True
  158.         nodeData = {
  159.             "node_exist": node_exist,
  160.             "node_prograde": node_list[var].prograde,
  161.             "node_normal": node_list[var].normal,
  162.             "node_radial": node_list[var].radial,
  163.             "node_dV": node_list[var].delta_v,  # static
  164.             "node_dvRemaining": node_list[var].remaining_delta_v,  # changes, maybe loop ??
  165.             "node_unitime": node_list[var].ut,  # in seconds
  166.             "node_timeto": node_list[var].time_to,
  167.         }
  168.         return nodeData, node_list
  169.     else:
  170.         print("No node found.")
  171.         node_exist = False
  172.         return node_exist
  173.  
  174.  
  175. getVesselData()
  176.  
  177. print(getFlightData().get("surfaceAltitude"))
  178. getOrbitalData()
  179. getNewOrbitalData()
  180. getNodeData(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement