Skip to content

Commit

Permalink
Serialize use_breaks, allow manual breaking under target speed when u…
Browse files Browse the repository at this point in the history
…se_breaks is enabled. Fixes #31.
  • Loading branch information
Boris-Barboris committed May 27, 2022
1 parent 556d5d4 commit cfc1931
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion AtmosphereAutopilot/AtmosphereAutopilot.version
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"VERSION" : {
"MAJOR" : 1,
"MINOR" : 5,
"PATCH" : 18,
"PATCH" : 19,
"BUILD" : 0
},
"KSP_VERSION" : {
Expand Down
2 changes: 2 additions & 0 deletions AtmosphereAutopilot/Global_settings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ Cruise_Flight_controller
}
Prograde_thrust_controller
{
use_breaks = True
use_pid = False
hotkey_speed_factor = 0.7
use_throttle_hotkeys = True
window_x = 335
Expand Down
27 changes: 23 additions & 4 deletions AtmosphereAutopilot/Modules/ProgradeThrustController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Atmosphere Autopilot, plugin for Kerbal Space Program.
Copyright (C) 2015-2016, Baranin Alexander aka Boris-Barboris.
Atmosphere Autopilot is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
Expand All @@ -11,7 +11,7 @@ it under the terms of the GNU General Public License as published by
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Atmosphere Autopilot. If not, see <http://www.gnu.org/licenses/>.
along with Atmosphere Autopilot. If not, see <http://www.gnu.org/licenses/>.
*/

using System;
Expand Down Expand Up @@ -151,6 +151,7 @@ protected override void OnDeactivate()
[AutoGuiAttr("break spd margin %", true, "G5")]
public double break_margin = 10.0f;

[GlobalSerializable("use_breaks")]
[AutoGuiAttr("Use breaks", true)]
public bool use_breaks = true;

Expand All @@ -173,6 +174,8 @@ protected override void OnDeactivate()

public Vector3d surfspd_dir;

private bool was_breaking_previously = true;

/// <summary>
/// Main control function
/// </summary>
Expand All @@ -190,19 +193,35 @@ public override float ApplyControl(FlightCtrlState cntrl, float target_value)
{
// we're on ground
if (current_v > desired_v)
{
vessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, true);
was_breaking_previously = true;
}
else
vessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, false);
{
if (was_breaking_previously)
vessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, false);
was_breaking_previously = false;
}
}
else
{
// we're in flight
if (current_v > (1.0 + break_margin / 100.0) * desired_v)
{
vessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, true);
was_breaking_previously = true;
}
else
vessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, false);
{
if (was_breaking_previously)
vessel.ActionGroups.SetGroup(KSPActionGroup.Brakes, false);
was_breaking_previously = false;
}
}
}
else
was_breaking_previously = true;

if (use_pid)
{
Expand Down
4 changes: 2 additions & 2 deletions AtmosphereAutopilot/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.5.18.0")]
[assembly: AssemblyFileVersion("1.5.18.0")]
[assembly: AssemblyVersion("1.5.19.0")]
[assembly: AssemblyFileVersion("1.5.19.0")]

0 comments on commit cfc1931

Please sign in to comment.