Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import krpc
- c = krpc.connect(name="KSP")
- def vesselList(): # lists all the vessels
- vessels = c.space_center.vessels
- for i in vessels:
- print(i.name)
- def selectVessel():
- currentVessel = c.space_center.active_vessel
- # currentvessel.situation
- return currentVessel
- def getFlightData():
- print("Flight Data")
- flightData = {
- "orbitalVelocity": selectVessel().flight(selectVessel().orbit.body.non_rotating_reference_frame).velocity,
- "orbitalSpeed": selectVessel().flight(selectVessel().orbit.body.non_rotating_reference_frame).speed,
- "surfaceVelocity": selectVessel().flight().velocity,
- "surfaceSpeed": selectVessel().flight().speed,
- "hSpeed": selectVessel().flight().horizontal_speed,
- "vSpeed": selectVessel().flight().vertical_speed,
- "gForce": selectVessel().flight(selectVessel().reference_frame).g_force,
- "surfaceAltitude": selectVessel().flight().surface_altitude,
- "bedrockAltitude": selectVessel().flight().bedrock_altitude,
- # =surfaceAlt. but if over water -> above sea ground
- "aboveSealevelAltitude": selectVessel().flight().mean_altitude,
- "terrainHeight": selectVessel().flight().elevation,
- "latitude": selectVessel().flight().latitude,
- "longitude": selectVessel().flight().longitude,
- "rotation": selectVessel().flight().rotation,
- "direction": selectVessel().flight().direction,
- "pitch": selectVessel().flight().pitch,
- "heading": selectVessel().flight().heading,
- "roll": selectVessel().flight().roll,
- "atmoDensity": selectVessel().flight().atmosphere_density,
- "dynPressure": selectVessel().flight().dynamic_pressure,
- # pressure acting on vessel (aerodyn. forces) (pascal)
- "staticPressure": selectVessel().flight().static_pressure, # static atmo pressure acting on vessel (pascal)
- "aeroForce": selectVessel().flight().aerodynamic_force, # see doc.
- "aeroLift": selectVessel().flight().lift, # lift & drag : vectors of force, magnitude : strenght
- "aeroDrag": selectVessel().flight().drag,
- "speedOfSound": selectVessel().flight().speed_of_sound,
- "mach": selectVessel().flight().mach,
- "terminalVelocity": selectVessel().flight().terminal_velocity, # estimate, depends on current velocity
- "AoA": selectVessel().flight().angle_of_attack,
- "sideslipAngle": selectVessel().flight().sideslip_angle,
- "airTemp_k": selectVessel().flight().static_air_temperature,
- }
- return flightData
- def getVesselData():
- print("Vessel Data")
- vesselData = {
- "vName": selectVessel().name,
- "vType": selectVessel().type,
- "vSituation": selectVessel().situation,
- "missionTime": selectVessel().met,
- "COM": selectVessel().flight().center_of_mass,
- "resNames": selectVessel().resources.names,
- # Resources
- "liquidFuel": selectVessel().resources.amount("LiquidFuel"),
- "oxidizer": selectVessel().resources.amount("Oxidizer"),
- "monoProp": selectVessel().resources.amount("MonoPropellant"),
- "electricCharge": selectVessel().resources.amount("ElectricCharge"),
- "intakeAir": selectVessel().resources.amount("IntakeAir"),
- "solidFuel": selectVessel().resources.amount("SolidFuel"),
- "xenonGas": selectVessel().resources.amount("XenonGas"),
- "ore": selectVessel().resources.amount("Ore"),
- "ablator": selectVessel().resources.amount("Ablator"),
- # ResourcesMax
- "liquidFuelMax": selectVessel().resources.max("LiquidFuel"),
- "oxidizerMax": selectVessel().resources.max("Oxidizer"),
- "monoPropMax": selectVessel().resources.max("MonoPropellant"),
- "electricChargeMax": selectVessel().resources.max("ElectricCharge"),
- "solidFuelMax": selectVessel().resources.max("SolidFuel"),
- "xenonGasMax": selectVessel().resources.max("XenonGas"),
- "oreMax": selectVessel().resources.max("Ore"),
- "ablatorMax": selectVessel().resources.max("Ablator"),
- # Resource Density
- "liquidFuelDensity": selectVessel().resources.density("LiquidFuel"),
- "oxidizerDensity": selectVessel().resources.density("Oxidizer"),
- "monoPropDensity": selectVessel().resources.density("MonoPropellant"),
- "solidFuelDensity": selectVessel().resources.density("SolidFuel"),
- "xenonGasDensity": selectVessel().resources.density("XenonGas"),
- "oreDensity": selectVessel().resources.density("Ore"),
- # Parts
- "partCount": len(selectVessel().parts.all),
- "controlPart": selectVessel().parts.controlling.title,
- }
- return vesselData
- def getOrbitalData():
- print("Orbital Data")
- orbitaldata = {
- "body": selectVessel().orbit.body.name,
- "apoapsis": selectVessel().orbit.apoapsis_altitude,
- "periapsis": selectVessel().orbit.periapsis_altitude,
- "semi_major_axis": selectVessel().orbit.semi_major_axis,
- "semi_minor_axis": selectVessel().orbit.semi_minor_axis,
- "OrbitalRadius": selectVessel().orbit.radius,
- "OrbitalSpeed": selectVessel().orbit.speed,
- "OrbitalPeriod": selectVessel().orbit.period,
- "TTA": selectVessel().orbit.time_to_apoapsis,
- "TTP": selectVessel().orbit.time_to_periapsis,
- "eccentricity": selectVessel().orbit.eccentricity,
- "inclination": selectVessel().orbit.inclination,
- "arg_of_periapsis": selectVessel().orbit.argument_of_periapsis,
- "mean_anomaly_epoch": selectVessel().orbit.mean_anomaly_at_epoch,
- "epoch": selectVessel().orbit.epoch,
- "eccentric_anomaly": selectVessel().orbit.eccentric_anomaly,
- "TTSOIchange": selectVessel().orbit.time_to_soi_change,
- }
- return orbitaldata
- def getNewOrbitalData():
- print("New Orbital Data")
- if selectVessel().orbit.next_orbit == "NoneType":
- newOrbitalData = {
- "new_orbit": True,
- "new_body": selectVessel().orbit.next_orbit.body.name,
- "new_apoapsis": selectVessel().orbit.next_orbit.apoapsis_altitude,
- "new_periapsis": selectVessel().orbit.next_orbit.periapsis_altitude,
- "new_semi_major_axis": selectVessel().orbit.next_orbit.semi_major_axis,
- "new_semi_minor_axis": selectVessel().orbit.next_orbit.semi_minor_axis,
- "new_orbitalRadius": selectVessel().orbit.next_orbit.radius,
- "new_orbitalSpeed": selectVessel().orbit.next_orbit.speed,
- "new_orbitalPeriod": selectVessel().orbit.next_orbit.period,
- "new_TTA": selectVessel().orbit.next_orbit.time_to_apoapsis,
- "new_TTP": selectVessel().orbit.next_orbit.time_to_periapsis,
- "new_eccentricity": selectVessel().orbit.next_orbit.eccentricity,
- "new_inclination": selectVessel().orbit.next_orbit.inclination,
- "new_argOfPeriapsis": selectVessel().orbit.next_orbit.argument_of_periapsis,
- "new_meanAnomalyEpoch": selectVessel().orbit.next_orbit.mean_anomaly_at_epoch,
- "new_epoch": selectVessel().orbit.next_orbit.epoch,
- "new_eccentricAnomaly": selectVessel().orbit.next_orbit.eccentric_anomaly,
- "new_TTSOIchange": selectVessel().orbit.next_orbit.time_to_soi_change,
- }
- return newOrbitalData
- else:
- print("No change.")
- new_orbit = False
- return new_orbit
- def getNodeData(var):
- print("Node Data")
- node_list = selectVessel().control.nodes
- if len(node_list) != 0:
- node_exist = True
- nodeData = {
- "node_exist": node_exist,
- "node_prograde": node_list[var].prograde,
- "node_normal": node_list[var].normal,
- "node_radial": node_list[var].radial,
- "node_dV": node_list[var].delta_v, # static
- "node_dvRemaining": node_list[var].remaining_delta_v, # changes, maybe loop ??
- "node_unitime": node_list[var].ut, # in seconds
- "node_timeto": node_list[var].time_to,
- }
- return nodeData, node_list
- else:
- print("No node found.")
- node_exist = False
- return node_exist
- getVesselData()
- print(getFlightData().get("surfaceAltitude"))
- getOrbitalData()
- getNewOrbitalData()
- getNodeData(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement