space_ex v0.3.0 SpaceEx.SpaceCenter

Provides functionality to interact with Kerbal Space Program.

This includes controlling the active vessel, managing its resources, planning maneuver nodes and auto-piloting.

Link to this section Summary

Functions

The currently active vessel

A dictionary of all celestial bodies (planets, moons, etc.) in the game, keyed by the name of the body

An object that can be used to control the camera

Returns true if regular "on-rails" time warp can be used, at the specified warp factor

Clears the current target

The contract manager

The value of the gravitational constant G in \(N(m/kg)^2\)

Launch a new vessel from the SPH onto the runway

Launch a new vessel from the VAB onto the launchpad

Returns a list of vessels from the given craftDirectory that can be launched

Load the game with the given name

The current maximum regular "on-rails" warp factor that can be set

Whether the navball is visible

The physical time warp rate

Load a quicksave

Save a quicksave

The time warp rate, using regular "on-rails" time warp

Cast a ray from a given position in a given direction, and return the distance to the hit point

Cast a ray from a given position in a given direction, and return the part that it hits

Save the game with a given name

The currently active vessel

Whether the navball is visible

The physical time warp rate

The time warp rate, using regular "on-rails" time warp

The currently targeted celestial body

The currently targeted docking port

The currently targeted vessel

Whether the UI is visible

The currently targeted celestial body

The currently targeted docking port

The currently targeted vessel

Converts a direction from one reference frame to another

Converts a position from one reference frame to another

Converts a rotation from one reference frame to another

Converts a velocity (acting at the specified position) from one reference frame to another

Whether the UI is visible

The current universal time in seconds

A list of all the vessels in the game

The current warp factor

The current time warp mode

The current warp rate

Uses time acceleration to warp forward to a time in the future, specified by universal time ut

The waypoint manager

Link to this section Functions

Link to this function active_vessel(conn)

The currently active vessel.

A dictionary of all celestial bodies (planets, moons, etc.) in the game, keyed by the name of the body.

An object that can be used to control the camera.

Link to this function can_rails_warp_at(conn, factor)

Returns true if regular "on-rails" time warp can be used, at the specified warp factor.

The maximum time warp rate is limited by various things, including how close the active vessel is to a planet. See the KSP wiki for details.

  • factor — The warp factor to check.
Link to this function clear_target(conn)

Clears the current target.

Link to this function contract_manager(conn)

The contract manager.

Link to this function far_available(conn)

Whether Ferram Aerospace Research is installed.

The value of the gravitational constant G in \(N(m/kg)^2\).

Link to this function launch_vessel(conn, craftDirectory, name, launchSite)

Launch a vessel.

  • craftDirectory — Name of the directory in the current saves "Ships" directory, that contains the craft file. For example "VAB" or "SPH".

  • name — Name of the vessel to launch. This is the name of the ".craft" file in the save directory, without the ".craft" file extension.

  • launchSite — Name of the launch site. For example "LaunchPad" or "Runway".

Link to this function launch_vessel_from_sph(conn, name)

Launch a new vessel from the SPH onto the runway.

  • name — Name of the vessel to launch.

This is equivalent to calling SpaceEx.SpaceCenter.launch_vessel/4 with the craft directory set to "SPH" and the launch site set to "Runway".

Link to this function launch_vessel_from_vab(conn, name)

Launch a new vessel from the VAB onto the launchpad.

  • name — Name of the vessel to launch.

This is equivalent to calling SpaceEx.SpaceCenter.launch_vessel/4 with the craft directory set to "VAB" and the launch site set to "LaunchPad".

Link to this function launchable_vessels(conn, craftDirectory)

Returns a list of vessels from the given craftDirectory that can be launched.

  • craftDirectory — Name of the directory in the current saves "Ships" directory. For example "VAB" or "SPH".
Link to this function load(conn, name)

Load the game with the given name.

This will create a load a save file called name.sfs from the folder of the current save game.

Link to this function maximum_rails_warp_factor(conn)

The current maximum regular "on-rails" warp factor that can be set.

A value between 0 and 7 inclusive. See the KSP wiki for details.

Link to this function physics_warp_factor(conn)

The physical time warp rate.

A value between 0 and 3 inclusive. 0 means no time warp. Returns 0 if regular "on-rails" time warp is active.

Link to this function quickload(conn)

Load a quicksave.

This is the same as calling SpaceEx.SpaceCenter.load/2 with the name "quicksave".

Link to this function quicksave(conn)

Save a quicksave.

This is the same as calling SpaceEx.SpaceCenter.save/2 with the name "quicksave".

Link to this function rails_warp_factor(conn)

The time warp rate, using regular "on-rails" time warp.

A value between 0 and 7 inclusive. 0 means no time warp. Returns 0 if physical time warp is active.

If requested time warp factor cannot be set, it will be set to the next lowest possible value. For example, if the vessel is too close to a planet. See the KSP wiki for details.

Link to this function raycast_distance(conn, position, direction, referenceFrame)

Cast a ray from a given position in a given direction, and return the distance to the hit point.

If no hit occurs, returns infinity.

  • position — Position, as a vector, of the origin of the ray.

  • direction — Direction of the ray, as a unit vector.

  • referenceFrame — The reference frame that the position and direction are in.

Returns: The distance to the hit, in meters, or infinity if there was no hit.

Link to this function raycast_part(conn, position, direction, referenceFrame)

Cast a ray from a given position in a given direction, and return the part that it hits.

If no hit occurs, returns nil.

  • position — Position, as a vector, of the origin of the ray.

  • direction — Direction of the ray, as a unit vector.

  • referenceFrame — The reference frame that the position and direction are in.

Returns: The part that was hit or nil if there was no hit.

Link to this function save(conn, name)

Save the game with a given name.

This will create a save file called name.sfs in the folder of the current save game.

Link to this function set_active_vessel(conn, value)

The currently active vessel.

Link to this function set_navball(conn, value)

Whether the navball is visible.

Link to this function set_physics_warp_factor(conn, value)

The physical time warp rate.

A value between 0 and 3 inclusive. 0 means no time warp. Returns 0 if regular "on-rails" time warp is active.

Link to this function set_rails_warp_factor(conn, value)

The time warp rate, using regular "on-rails" time warp.

A value between 0 and 7 inclusive. 0 means no time warp. Returns 0 if physical time warp is active.

If requested time warp factor cannot be set, it will be set to the next lowest possible value. For example, if the vessel is too close to a planet. See the KSP wiki for details.

Link to this function set_target_body(conn, value)

The currently targeted celestial body.

Link to this function set_target_docking_port(conn, value)

The currently targeted docking port.

Link to this function set_target_vessel(conn, value)

The currently targeted vessel.

Link to this function set_ui_visible(conn, value)

Whether the UI is visible.

Link to this function target_body(conn)

The currently targeted celestial body.

Link to this function target_docking_port(conn)

The currently targeted docking port.

Link to this function target_vessel(conn)

The currently targeted vessel.

Link to this function transform_direction(conn, direction, from, to)

Converts a direction from one reference frame to another.

  • direction — Direction, as a vector, in reference frame from.

  • from — The reference frame that the direction is in.

  • to — The reference frame to covert the direction to.

Returns: The corresponding direction, as a vector, in reference frame to.

Link to this function transform_position(conn, position, from, to)

Converts a position from one reference frame to another.

  • position — Position, as a vector, in reference frame from.

  • from — The reference frame that the position is in.

  • to — The reference frame to covert the position to.

Returns: The corresponding position, as a vector, in reference frame to.

Link to this function transform_rotation(conn, rotation, from, to)

Converts a rotation from one reference frame to another.

  • rotation — Rotation, as a quaternion of the form \((x, y, z, w)\), in reference frame from.

  • from — The reference frame that the rotation is in.

  • to — The reference frame to covert the rotation to.

Returns: The corresponding rotation, as a quaternion of the form \((x, y, z, w)\), in reference frame to.

Link to this function transform_velocity(conn, position, velocity, from, to)

Converts a velocity (acting at the specified position) from one reference frame to another.

The position is required to take the relative angular velocity of the reference frames into account.

  • position — Position, as a vector, in reference frame from.

  • velocity — Velocity, as a vector that points in the direction of travel and whose magnitude is the speed in meters per second, in reference frame from.

  • from — The reference frame that the position and velocity are in.

  • to — The reference frame to covert the velocity to.

Returns: The corresponding velocity, as a vector, in reference frame to.

Link to this function ui_visible(conn)

Whether the UI is visible.

The current universal time in seconds.

A list of all the vessels in the game.

Link to this function warp_factor(conn)

The current warp factor.

This is the index of the rate at which time is passing for either regular "on-rails" or physical time warp. Returns 0 if time warp is not active. When in on-rails time warp, this is equal to SpaceEx.SpaceCenter.rails_warp_factor/1, and in physics time warp, this is equal to SpaceEx.SpaceCenter.physics_warp_factor/1.

Link to this function warp_mode(conn)

The current time warp mode.

Returns :none if time warp is not active, :rails if regular "on-rails" time warp is active, or :physics if physical time warp is active.

Link to this function warp_rate(conn)

The current warp rate.

This is the rate at which time is passing for either on-rails or physical time warp. For example, a value of 10 means time is passing 10x faster than normal. Returns 1 if time warp is not active.

Link to this function warp_to(conn, ut, maxRailsRate, maxPhysicsRate)

Uses time acceleration to warp forward to a time in the future, specified by universal time ut.

This call blocks until the desired time is reached. Uses regular "on-rails" or physical time warp as appropriate. For example, physical time warp is used when the active vessel is traveling through an atmosphere. When using regular "on-rails" time warp, the warp rate is limited by maxRailsRate, and when using physical time warp, the warp rate is limited by maxPhysicsRate.

  • ut — The universal time to warp to, in seconds.

  • maxRailsRate — The maximum warp rate in regular "on-rails" time warp.

  • maxPhysicsRate — The maximum warp rate in physical time warp.

Returns: When the time warp is complete.

Link to this function waypoint_manager(conn)

The waypoint manager.