Trajectories

Trajectories is a mod that displays trajectory predictions, accounting for atmospheric drag, lift, etc.. See the forum thread for more details.

This addon is not associated with and not supported by the creator of Trajectories.

The Trajectories API is accessed through C# reflection, and is designed for the current version. This means that future Trajectories updates may break this addon, in which case ADDONS:TR:AVAILABLE will return false. It is also possible for future versions of Trajectories to remain fully compatible.

Note

Trajectories only predicts the trajectory of the “Active Vessel,” which is the vessel with the camera focused on it. IMPACTPOS, PLANNEDVEC, SETTARGET, and CORRECTEDVEC will throw exceptions if you try to call them from an inactive vessel or if Trajectories has not calculated an impact position. You should always check if HASIMPACT is true before accessing these suffixes.

For example:

if ADDONS:TR:AVAILABLE {
    if ADDONS:TR:HASIMPACT {
        PRINT ADDONS:TR:IMPACTPOS.
    } else {
        PRINT "Impact position is not available".
    }
} else {
    PRINT "Trajectories is not available.".
}

Trajectories does its calculation based on the vessel’s current orientation. Any tiny change in orientation will change the prediction.

Accuracy is not guaranteed.

See this repository for an example of this addon being used to land a rocket on the launch pad: https://github.com/CalebJ2/kOS-landing-script

Trajectories Version Compatibility

The Trajectories mod went through some changes between Trajectories 1.x and Trajectories 2.x. These changes alter the way that the kOS Trajectories AddOn has to communicate with the Trajectories mod, and added new suffixes that kOS could use. However, for backward compatibility kOS will try to support an older version of Trajectories if that’s what’s installed. Places where a suffix only works with newer versions of Trajectories are noted below in the suffix table.

Access structure TRAddon via ADDONS:TR.

structure TRAddon

Suffix

Type

Description

AVAILABLE

Boolean (readonly)

True if a compatible Trajectories version is installed.

GETVERSION

String (readonly)

Trajectories version string.

GETVERSIONMAJOR

ScalarValue (readonly)

Trajectories version Major.

GETVERSIONMINOR

ScalarValue (readonly)

Trajectories version Minor.

GETVERSIONPATCH

ScalarValue (readonly)

Trajectories version Patch.

ISVERTWO

Boolean (readonly)

True if Trajectories version is 2.0.0 or above.

ISVERTWOTWO

Boolean (readonly)

True if Trajectories version is 2.2.0 or above.

ISVERTWOFOUR

Boolean (readonly)

True if Trajectories version is 2.4.0 or above.

HASIMPACT

Boolean (readonly)

True if Trajectories has calculated an impact position for the current vessel.

IMPACTPOS

GeoCoordinates (readonly)

Returns a GeoCoordinates with the predicted impact position.

TIMETILLIMPACT

ScalarValue (readonly)

(only TR 2.2.0 and up) Seconds until impact.

RESETDESCENTPROFILE(AoA)

None

(only TR 2.4.0 and up) Reset all the Descent profile nodes.

DESCENTANGLES

List

(only TR 2.4.0 and up) Descent profile angles.

DESCENTGRADES

List

(only TR 2.4.0 and up) Descent profile grades (Retro or Pro).

DESCENTMODES

List

(only TR 2.4.0 and up) Descent profile modes (AoA or Horizon).

PROGRADE

Boolean

(only TR 2.2.0 and up Descent profile all prograde.

RETROGRADE

Boolean

(only TR 2.2.0 and up Descent profile all retrograde.

PLANNEDVEC

Vector (readonly)

Vector at which to point to follow predicted trajectory.

PLANNEDVECTOR

Vector (readonly)

Alias for PLANNEDVEC

SETTARGET(position)

None

Set Trajectories target.

HASTARGET

Boolean (readonly)

(only TR 2.0.0 and up) True if Trajectories target position has been set.

GETTARGET

GeoCoordinates (readonly)

(only TR 2.4.0 and up) Returns a GeoCoordinates with the Trajectories target position.

CLEARTARGET()

None

(only TR 2.4.0 and up) Clear Trajectories target.

CORRECTEDVEC

Vector (readonly)

Offset plus PLANNEDVEC to correct path for targeted impact.

CORRECTEDVECTOR

Vector (readonly)

Alias for CORRECTEDVEC

TRAddon:AVAILABLE
Type

Boolean

Access

Get

True if a compatible Trajectories version is installed. If this is not true, then none of the other suffixes listed here are safe to call (they can cause error and program crash).

TRAddon:GETVERSION
Type

String

Access

Get

Only gives the correct answer for Trajectries version >= 2.2.0

For earlier versions, it gives a hardcoded fixed answer, as follows:

  • For any Trajectories version earlier than 2.0.0, this returns the empty string “”.

  • For any Trajectories version at least 2.0.0 but below 2.2.0, this returns the ‘rounded off’ answer “2.0.0” regardless of the precise version number within that range.

  • If your Trajectories version is at least 2.2.0 or above, this returns the specific version string correctly.

For cases where you need to check for a known minimum Trajectories version, it is probably better to use the specific boolean suffix for that version (for example, TRAddon:ISVERTWO, or TRAddon:ISVERTWOTWO etc.)

TRAddon:GETVERSIONMAJOR
Type

Scalar

Access

Get

Only gives the correct answer for Trajectries version >= 2.0.0

For earlier versions, it gives a hardcoded fixed answer, as follows:

  • For any Trajectories version earlier than 2.0.0, this returns “0”.

  • If your Trajectories version is at least 2.0.0 or above, this returns the specific version major value correctly.

For cases where you need to check for a known minimum Trajectories version, it is probably better to use the specific boolean suffix for that version (for example, TRAddon:ISVERTWO, or TRAddon:ISVERTWOTWO etc.)

TRAddon:GETVERSIONMINOR
Type

Scalar

Access

Get

Only gives the correct answer for Trajectries version >= 2.2.0

For earlier versions, it gives a hardcoded fixed answer, as follows:

  • For any Trajectories version below 2.2.0, this returns “0” regardless of the precise version number within that range.

  • If your Trajectories version is at least 2.2.0 or above, this returns the specific version minor value correctly.

For cases where you need to check for a known minimum Trajectories version, it is probably better to use the specific boolean suffix for that version (for example, TRAddon:ISVERTWO, or TRAddon:ISVERTWOTWO etc.)

TRAddon:GETVERSIONPATCH
Type

Scalar

Access

Get

Only gives the correct answer for Trajectries version >= 2.2.0

For earlier versions, it gives a hardcoded fixed answer, as follows:

  • For any Trajectories version below 2.2.0, this returns “0” regardless of the precise version number within that range.

  • If your Trajectories version is at least 2.2.0 or above, this returns the specific version patch value correctly.

For cases where you need to check for a known minimum Trajectories version, it is probably better to use the specific boolean suffix for that version (for example, TRAddon:ISVERTWO, or TRAddon:ISVERTWOTWO etc.)

TRAddon:ISVERTWO
Type

Boolean

Access

Get

True if the Trajectories mod is at least version 2.0.0 or above.

TRAddon:ISVERTWOTWO
Type

Boolean

Access

Get

True if the Trajectories mod is at least version 2.2.0 or above.

TRAddon:ISVERTWOFOUR
Type

Boolean

Access

Get

True if the Trajectories mod is at least version 2.4.0 or above.

TRAddon:HASIMPACT
Type

Boolean

Access

Get

True if Trajectories has calculated an impact position for the current Vessel. You should always check this before using impactPos, plannedVect, setTarget, or correctedVect to avoid exceptions.

TRAddon:IMPACTPOS
Type

GeoCoordinates

Access

Get

Estimated impact position.

TRAddon:TIMETILLIMPACT
Type

Scalar

Access

Get

Did Not Exist in Trajectories before 2.2.0!

If :attr:`TRAddons:ISVERTWOTWO` is false, using this suffix will cause a runtime error.

Gives you Trajectories prediction of how many seconds until impact on ground or water.

TRAddon:RESETDESCENTPROFILE(AoA)
Parameters
Returns

None

Did Not Exist in Trajectories before 2.4.0!

If :attr:`TRAddons:ISVERTWOFOUR` is false, using this suffix will cause a runtime error.

Resets all the Trajectories descent profile nodes to the passed AoA value (in Degrees), also sets Retrograde if AoA value is greater than 90 degrees (PI/2 radians) otherwise sets to Prograde.

TRAddon:DESCENTANGLES
Type

List

Access

Get/Set

Did Not Exist in Trajectories before 2.4.0!

If :attr:`TRAddons:ISVERTWOFOUR` is false, using this suffix will cause a runtime error.

Returns or sets all the Trajectories descent profile AoA values (in Degrees), also sets a node to Retrograde if it’s passed AoA is greater than 90 degrees (PI/2 radians) Note. also use with TRAddons:DESCENTGRADES to set a nodes grade if needed and passing AoA values as displayed in the gui with max 90 degrees (PI/2 radians).

List<Scalar>(atmospheric entry, high altitude, low altitude, final approach).

TRAddon:DESCENTGRADES
Type

List

Access

Get/Set

Did Not Exist in Trajectories before 2.4.0!

If :attr:`TRAddons:ISVERTWOFOUR` is false, using this suffix will cause a runtime error.

Returns or sets all the Trajectories descent profile grades, True = Retrograde, False = Prograde.

List<Boolean>(atmospheric entry, high altitude, low altitude, final approach).

TRAddon:DESCENTMODES
Type

List

Access

Get/Set

Did Not Exist in Trajectories before 2.4.0!

If :attr:`TRAddons:ISVERTWOFOUR` is false, using this suffix will cause a runtime error.

Returns or sets all the Trajectories descent profile modes, True = AoA, False = Horizon.

List<Boolean>(atmospheric entry, high altitude, low altitude, final approach).

TRAddon:PROGRADE
Type

Boolean

Access

Get/Set

Did Not Exist in Trajectories before 2.2.0!

If :attr:`TRAddons:ISVERTWOTWO` is false, using this suffix will cause a runtime error.

For Trajectories 2.2.0 True if all the descent profile AoA values are 0. For Trajectories 2.4.0 True if all the descent profile nodes are ‘prograde’

You can set this to have the same effect as clicking on prograde mode in the trajectories GUI. Setting this value to true causes TRAddon:RETROGRADE to become false. (They cannot both be true at the same time.)

Setting this causes all Trajectories descent profile nodes to be set to ‘prograde’ mode if True or ‘retrograde’ mode if False. Also resets all AoA values to 0.

TRAddon:RETROGRADE
Type

Boolean

Access

Get/Set

Did Not Exist in Trajectories before 2.2.0!

If :attr:`TRAddons:ISVERTWOTWO` is false, using this suffix will cause a runtime error.

For Trajectories 2.2.0 True if all the descent profile AoA values are 180. For Trajectories 2.4.0 True if all the descent profile nodes are ‘retrograde’

You can set this to have the same effect as clicking on retrograde mode in the trajectories GUI. Setting this value to true causes TRAddon:PROGRADE to become false. (They cannot both be true at the same time.)

Setting this causes all Trajectories descent profile nodes to be set to ‘retrograde’ mode if True or ‘prograde’ mode if False. Also resets all AoA values to 0.

TRAddon:PLANNEDVEC
Type

Vector

Access

Get

Vector pointing the direction your vessel should face to follow the predicted trajectory, based on the angle of attack selected in the Trajectories descent profile.

TRAddon:PLANNEDVECTOR
Type

Vector

Access

Get

Alias for PLANNEDVEC

TRAddon:SETTARGET(position)
Parameters
Returns

None

Sets the Trajectories target landing position to the given position.

TRAddon:HASTARGET
Type

Boolean

Access

Get

Did Not Exist in Trajectories before 2.0.0!

If :attr:`TRAddons:ISVERTWO` is false, using this suffix will cause a runtime error.

The Trajectories Addon can be given a target position. This is true if such a position is set, or false if it is not.

TRAddon:GETTARGET
Type

GeoCoordinates

Access

Get

Did Not Exist in Trajectories before 2.4.0!

If :attr:`TRAddons:ISVERTWOFOUR` is false, using this suffix will cause a runtime error.

Returns the Trajectories target position if one is set.

TRAddon:CLEARTARGET()

:parameter None :return: None

Did Not Exist in Trajectories before 2.4.0!

If :attr:`TRAddons:ISVERTWOFOUR` is false, using this suffix will cause a runtime error.

Clears the Trajectories target position.

TRAddon:CORRECTEDVEC
Type

Vector

Access

Get

A vector that applies an offset to PLANNEDVEC intended to correct the predicted trajectory to impact at the selected target position. This vector does not use any aerodynamic prediction and is a very simplistic representation. It is also just a unit vector. It contains no magnitude information about how far off the selected target is from the predicted impact - just the way the offset points. Accuracy is not guaranteed, but it should at least help determine if you need to pitch the nose up or down.

TRAddon:CORRECTEDVECTOR
Type

Vector

Access

Get

Alias for CORRECTEDVEC