Skip to content

Commit

Permalink
WIP - restructure code into separate classes, working towards getting…
Browse files Browse the repository at this point in the history
… full astrogator view data
  • Loading branch information
markjfisher committed Oct 1, 2022
1 parent 1617ad5 commit eac28f7
Show file tree
Hide file tree
Showing 12 changed files with 245 additions and 197 deletions.
28 changes: 20 additions & 8 deletions GameData/kOS-Astrogator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
addons:astrogator:help.
```

## Creating and calculating Transfer Burns
## Transfers

### Creating burn maneuver nodes to a target
### `create(body, [shouldCreatePlanarChangeNode = true])` - Creating burn maneuver nodes to a target

```
addons:astrogator:create(Mun).
Expand All @@ -20,17 +20,29 @@ This will create the main transfer and a plane change node, unless a second arg
which will then only create the primary burn node.


### Calculating burn data (no nodes)
### `calculateBurns(body)` - Calculating burn data (no nodes)

It is possible to get the burn data for a transfer without creating the nodes with:
This will calculate the burn data for a transfer without creating the , and return a list of BurnModel structures (up to 2)

```
set nodeList to addons:astrogator:calculateBurns(Mun).
print nodeList.
set bms to addons:astrogator:calculateBurns(Mun).
print bms.
print bms[0]:prograde.
```

This will produce a list of `BurnModel` objects (up to 2). The first is the starting burn,
the second (if present) is the plane change burn.
This will produce a list of `BurnModel` objects (up to 2). The first (if present) is the starting burn,
the second (if present) is the plane change burn. See below for more information about BurnModel.

## Physics

The following functions are exposed from Astrogator's PhysicsTools

- `deltaVToOrbit(body)` Calculate deltav to get a sensible orbit around body.
- `speedAtPeriapsis(body, apo, peri)` Generically calculate the speed at periapsis around given body with this apo/peri values in its orbit.
- `speedAtApoapsis(body, apo, peri)` Generically calculate the speed at apoapsis around given body with this apo/peri values in its orbit.
- `shipSpeedAtPeriapsis()` Ship speed at periapsis around current body.
- `shipSpeedAtApoapsis()` Ship speed at apoapsis around current body.


## Structures

Expand Down
11 changes: 11 additions & 0 deletions GameData/kOS-Astrogator/kOS-Astrogator-Changelog.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@ KERBALCHANGELOG
author = markjfisher
license = GPL-3.0
website = forum.kerbalspaceprogram.com/index.php?/topic/209940-kos-astrogator
VERSION
showChangelog = True
{
version = 0.1.2
versionName = Homely Tungsten Firth
versionKSP = 1.12
CHANGE
{
change = Expose Astrogator View
type = Add
}
}
VERSION
{
version = 0.1.1
Expand Down
2 changes: 1 addition & 1 deletion GameData/kOS-Astrogator/kOS-Astrogator.version
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"VERSION": {
"MAJOR": 0,
"MINOR": 1,
"PATCH": 1
"PATCH": 2
},
"KSP_VERSION_MIN": {
"MAJOR": 1,
Expand Down
65 changes: 65 additions & 0 deletions Source/Addon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using kOS.Safe.Utilities;
using kOS.Safe.Encapsulation;
using kOS.Safe.Encapsulation.Suffixes;
using kOS.Suffixed;
using Astrogator;

namespace kOS.AddOns.kOSAstrogator
{
using transfer;
using info;
/// <summary>
/// kOS integration for Astrogator
/// </summary>
[kOSAddon("ASTROGATOR")]
[KOSNomenclature("AstrogatorAddon")]
public class KOSAstrogatorAddon : Addon
{

/// <summary>
/// The class initializer
/// </summary>
/// <param name="shared">The shared objects</param>
public KOSAstrogatorAddon(SharedObjects shared) : base(shared)
{
InitializeSuffixes();
}

/// <inheritdoc/>
public override BooleanValue Available() => Util.IsModInstalled("Astrogator");

private void InitializeSuffixes()
{
// info
AddSuffix("help", new NoArgsVoidSuffix(() => Help.PrintHelp(shared)));
AddSuffix("version", new NoArgsSuffix<StringValue>(() => Version.GetVersion()));

// creating transfers and info
AddSuffix("create", new OptionalArgsSuffix<Node>(CreateTransfer, new Safe.Encapsulation.Structure[] { null, BooleanValue.True }));
AddSuffix("calculateBurns", new OneArgsSuffix<ListValue, BodyTarget>(CalculateBurns));

// physics
AddSuffix("deltaVToOrbit", new OneArgsSuffix<ScalarDoubleValue, BodyTarget>(DeltaVToOrbit));
AddSuffix("speedAtPeriapsis", new ThreeArgsSuffix<ScalarDoubleValue, BodyTarget, ScalarValue, ScalarValue>(SpeedAtPeriapsis));
AddSuffix("speedAtApoapsis", new ThreeArgsSuffix<ScalarDoubleValue, BodyTarget, ScalarValue, ScalarValue>(SpeedAtApoapsis));
AddSuffix("shipSpeedAtPeriapsis", new NoArgsSuffix<ScalarDoubleValue>(ShipSpeedAtPeriapsis));
AddSuffix("shipSpeedAtApoapsis", new NoArgsSuffix<ScalarDoubleValue>(ShipSpeedAtApoapsis));

}

#region suffix_functions
// I don't know how to move these directly into the above, or make the above call different classes. Haven't learned enough about delegates yet.

private Node CreateTransfer(params Safe.Encapsulation.Structure[] args) => Transfers.CreateManeuverNodes(shared, args);
private ListValue CalculateBurns(BodyTarget dest) => Transfers.CalculateBurns(shared, dest);
private ScalarDoubleValue DeltaVToOrbit(BodyTarget body) => PhysicsTools.DeltaVToOrbit(body.Body);
private ScalarDoubleValue SpeedAtPeriapsis(BodyTarget body, ScalarValue apopapsis, ScalarValue periapsis) => PhysicsTools.SpeedAtPeriapsis(body.Body, apopapsis.GetDoubleValue(), periapsis.GetDoubleValue());
private ScalarDoubleValue SpeedAtApoapsis(BodyTarget body, ScalarValue apopapsis, ScalarValue periapsis) => PhysicsTools.SpeedAtApoapsis(body.Body, apopapsis.GetDoubleValue(), periapsis.GetDoubleValue());
private ScalarDoubleValue ShipSpeedAtPeriapsis() => PhysicsTools.SpeedAtPeriapsis(shared.Vessel.mainBody, shared.Vessel.orbit.ApR, shared.Vessel.orbit.PeR);
private ScalarDoubleValue ShipSpeedAtApoapsis() => PhysicsTools.SpeedAtApoapsis(shared.Vessel.mainBody, shared.Vessel.orbit.ApR, shared.Vessel.orbit.PeR);
#endregion

#region internal_function
#endregion
}
}
183 changes: 0 additions & 183 deletions Source/KoS.cs

This file was deleted.

4 changes: 2 additions & 2 deletions Source/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("0.1.1.0")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyVersion("0.1.2.0")]
[assembly: AssemblyFileVersion("0.1.2.0")]

[assembly: KSPAssembly("kOS-Astrogator", 0, 1)]
[assembly: KSPAssemblyDependency("kOS", 1, 3)]
Expand Down
26 changes: 26 additions & 0 deletions Source/Util.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace kOS.AddOns.kOSAstrogator
{
/// <summary>
/// Everyone needs a util class
/// </summary>
public class Util
{
///<summary>
/// checks if the mod with "assemblyName" is loaded into KSP. Taken from KOS-Scansat
///</summary>
public static bool IsModInstalled(string assemblyName)
{
Assembly assembly = (from a in AssemblyLoader.loadedAssemblies
where a.name.ToLower().Equals(assemblyName.ToLower())
select a).FirstOrDefault().assembly;
return assembly != null;
}
}
}
22 changes: 22 additions & 0 deletions Source/info/Help.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace kOS.AddOns.kOSAstrogator.info
{
/// <summary>
/// Help command
/// </summary>
public static class Help
{
/// <summary>
/// The help command
/// </summary>
/// <param name="shared">The shared data</param>
public static void PrintHelp(SharedObjects shared)
{
shared.Screen.Print("--------------------------------------------");
shared.Screen.Print("kOS-Astrogator");
shared.Screen.Print("Usage: addons:astrogator:<cmd>");
shared.Screen.Print("See https://github.com/markjfisher/kOS-Astrogator/blob/master/GameData/kOS-Astrogator/README.md");
shared.Screen.Print("for full command details.");
shared.Screen.Print("--------------------------------------------");
}
}
}
Loading

0 comments on commit eac28f7

Please sign in to comment.