forked from here-and-now/KRPC.MechJeb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AscentGT.cs
97 lines (86 loc) · 4.12 KB
/
AscentGT.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System;
using System.Reflection;
using KRPC.MechJeb.ExtensionMethods;
using KRPC.Service.Attributes;
namespace KRPC.MechJeb {
/// <summary>
/// This profile is similar to the gravity turn mod. It is a 3-burn to orbit style of launch that can get to orbit with about 2800 dV on stock Kerbin.
/// If you want to have fun make a rocket that is basically a nose cone, a jumbo-64 a mainsail and some fairly big fins, have the pitch program flip it over aggressively (uncheck the AoA limiter, set the values to like 0.5 / 50 / 40 / 45 / 1) and let it rip.
/// </summary>
/// <remarks>
/// It's not precisely the GT mod algorithm and it does not do any pitch-up during the intermediate burn right now, so it won't handle low TWR upper stages.
/// </remarks>
[KRPCClass(Service = "MechJeb")]
public class AscentGT : AscentBase {
internal new const string MechJebType = "MuMech.MechJebModuleAscentGT";
// Fields and methods
private static FieldInfo turnStartAltitudeField;
private static FieldInfo turnStartVelocityField;
private static FieldInfo turnStartPitchField;
private static FieldInfo intermediateAltitudeField;
private static FieldInfo holdAPTimeField;
// Instance objects
private object turnStartAltitude;
private object turnStartVelocity;
private object turnStartPitch;
private object intermediateAltitude;
private object holdAPTime;
internal static new void InitType(Type type) {
turnStartAltitudeField = type.GetCheckedField("turnStartAltitude");
turnStartVelocityField = type.GetCheckedField("turnStartVelocity");
turnStartPitchField = type.GetCheckedField("turnStartPitch");
intermediateAltitudeField = type.GetCheckedField("intermediateAltitude");
holdAPTimeField = type.GetCheckedField("holdAPTime");
}
protected internal override void InitInstance(object instance) {
base.InitInstance(instance);
this.turnStartAltitude = turnStartAltitudeField.GetInstanceValue(instance);
this.turnStartVelocity = turnStartVelocityField.GetInstanceValue(instance);
this.turnStartPitch = turnStartPitchField.GetInstanceValue(instance);
this.intermediateAltitude = intermediateAltitudeField.GetInstanceValue(instance);
this.holdAPTime = holdAPTimeField.GetInstanceValue(instance);
}
/// <summary>
/// Altitude in km to pitch over and initiate the Gravity Turn (higher values for lower-TWR rockets).
/// </summary>
[KRPCProperty]
public double TurnStartAltitude {
get => EditableDouble.Get(this.turnStartAltitude);
set => EditableDouble.Set(this.turnStartAltitude, value);
}
/// <summary>
/// Velocity in m/s which triggers pitch over and initiates the Gravity Turn (higher values for lower-TWR rockets).
/// </summary>
[KRPCProperty]
public double TurnStartVelocity {
get => EditableDouble.Get(this.turnStartVelocity);
set => EditableDouble.Set(this.turnStartVelocity, value);
}
/// <summary>
/// Pitch that the pitch program immediately applies.
/// </summary>
[KRPCProperty]
public double TurnStartPitch {
get => EditableDouble.Get(this.turnStartPitch);
set => EditableDouble.Set(this.turnStartPitch, value);
}
/// <summary>
/// Intermediate apoapsis altitude to coast to and then raise the apoapsis up to the eventual final target. May be set to equal the final target in order to skip the intermediate phase.
/// </summary>
[KRPCProperty]
public double IntermediateAltitude {
get => EditableDouble.Get(this.intermediateAltitude);
set => EditableDouble.Set(this.intermediateAltitude, value);
}
/// <summary>
/// At the intermediate altitude with this much time-to-apoapsis left the engine will start burning prograde to lift the apoapsis.
/// The engine will throttle down in order to burn closer to the apoapsis.
/// This is very similar to the lead-time of a maneuver node in concept, but with throttling down in the case where the player has initiated the burn too early (the corollary is that if you see lots of throttling down at the start, you likely need less HoldAP time).
/// </summary>
[KRPCProperty]
public double HoldAPTime {
get => EditableDouble.Get(this.holdAPTime);
set => EditableDouble.Set(this.holdAPTime, value);
}
}
}