Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cooked steering #1118

Merged
merged 40 commits into from Oct 20, 2015
Merged

Fix cooked steering #1118

merged 40 commits into from Oct 20, 2015

Conversation

hvacengi
Copy link
Member

@hvacengi hvacengi commented Aug 2, 2015

This is my first attempt at the re-write for the cooked steering. It both includes steering and vector renders to show orientation.

  • Red vectors for orientation
  • Blue vectors for target orientation
  • Cyan vectors for angular velocity
  • Green vectors for target angular velocity
  • White vectors are the world coordinate X, Y, and Z.

Todo:

  • Calculate control response based on angular velocity and torque.
  • [Optional] Include PID control to improve accuracy [started, not done]
  • Reaction wheel torque
  • RCS torque
  • Gimbal torque
  • [ ] [Optional] Account for engine static torque
  • State vector renderers
  • [ ] State vectors continue to update when steering is not locked
  • Ability to toggle vector display.
  • [ ] Implement as FlightCtrlParameter
  • Updates to documentation accordingly
  • Try to fix a couple of lingering issues with torque calculations
  • [ ] Clean up commented debug code and unused methods Will do with optimizations on next release

SteeringManager.cs
* Moved steering code into a new class in the binding namespace.
* Class is an instance variable, and allows keeping track of history and
orientation individually instead of statically.
* New  implementation is based on angular velocity, and adjusts maximum
angular velocity based on available torque to minimize overshoot.
FlightControlManager.cs
* Steering FlightControlParameter now uses the SteeringManager class.
* Eventually, would like to break SteeringManager into it's own
parameter.
kOS.csproj
* Add reference for SteeringManager.cs
FlightControlManager.cs
* Hide vector renderers if steering is disabled
SteeringManager.cs
* Implement hiding of vector renderers.
* Update dtRoll1 to be more responsive.
* Roll is now controlled by a calculated maximum value rather than hard
coded value.
FlightControlManager.cs
* Call the SteeringManager's Update method on UpdateFlightControl.
SteeringManager.cs
* Add PI controls for angular velocity (rate) and torque
* Add csv logging for the PI controls
* Add new UpdatePredictionPI method for calculating based on the new
controls.  This allows the existing logic to remain for quick fallback
testing.
* Begin the work to calculate torque based on engine gimbal and rcs
thrust (using the new ThrustVector class)
SteeringManager.cs
* Updated vector renderers for engine thrust and gimbaled thrust.
* Fixed calculation for gimbaled engine torque and use it in calculating
the available torque.
* Added some PI output clamping in UpdatePredictionPI
* Update PI logic to properly mitigate integral windup.
* ErrorSum is now reset every time enabled is set to true (any time
`lock steering to ...` is called, even if already locked).
SteeringManager.cs
* Add a minimum available torque to prevent division by zero and sending
NaN into the ksp api, which causes lots of issues.  This was most
evident in realism overhaul, where the user may easily have zero
reaction wheel torque, or in stock with probe cores that don't include
wheels.
Revert changes to VectorRenderer.cs and SteeringHelper.cs accidentally
made in commit 58df5e9
SteeringManager.cs
* Added the RCS torque logic from the SteeringHelper into
SteeringManager class to re-enable RCS based calcs.  Only works for
symmetric placement, may need some tweaking for proper operation.
PIDLoop.cs
* Create new class to expos a kOS structure capable of iterating through
basic PID control schemes.
Misc.cs
* Provide constructor method for new PIDLoop structure.
kOS.csproj
* Include new PIDLoop.cs file.
FlightControlManager.cs
* Implement the new stat control methods from SteeringManager.
SteeringManager.cs
* Implement IDisposable on SteeringManagaer class.  Clear out file
access handles and vector renderers on dispose.
* Implement Structure class, including suffixes to control vector
visibility, debug printing, and direct interaction with the PID loops.
* Implement individual csv file writers for each PID using KSP.IO
classes.  Files are now stored at /Game_Data/kOS/Plugins/PluginData/kOS.
* Use new force vector struct for calculating RCS torque.  Still need to
adapt thrust torque to do the same.
* Adjust the moment of inertia by a factor of 10 if the value is below
4.5.  This is based on experimentation to determine the point where low
MoI is effected less by torque.
* Add new MovingAverage class and use it to filter the current angular
velocity, averaging the value over the last 30 samples.
* Completely rework the drawing of vector renderers so that it supports
toggling by 4 modes.
* Comment out old PI classes to be removed in the next commit for
historical purposes.
SteeringManager.cs
* CodeMaid cleanup
* Remove old commented lines no longer in uses.
BindingsUniverse.cs
* Add public getter for `STEERINGMANAGER` to access the steering manager
for the current vessel stored in the SharedObjects object.
SteeringManager.cs
* Add suffixes to get the overall errror, along with pitch, yaw, and
roll.
@hvacengi
Copy link
Member Author

I believe this fixes #122 #272 #389 #397 #490. Just wanting to get them associated with the issue so they get closed when the PR is merged.

SteeringManager.cs
* Add torque adjustment to allow adding an arbitrary torque, for when
kOS does not correctly calculate torque
* Add torque factor to scale the calculated available torque.
* Add constant value for converting between degrees and radians.
@hvacengi hvacengi added enhancement Something new (not a bug fix) is being requested documentation Change the Sphinx user documents. Not Ready Author is warning Reveiwer not to merge this PR yet. More edits are expected. labels Sep 3, 2015
@hvacengi hvacengi changed the title Fix cooked steering [not ready] Fix cooked steering Sep 4, 2015
SteeringManager.cs
* Update methods to allow swapping steering manager.  This method will
replace the steering manager depending on how a vessel staged.  It will
copy the setting values from one instance to the other.
* Add a debugging output for the average time it takes to update the
steering code.  Mostly there to benchmark as we do the switch, and to
find potential optimizations.
* Vector renderers are not initialized in the UpdateVectorRenderers
method to help streamline and guard against early disposal.
* Removed the HideVectorRenderers method as well and moved function into
UpdateVectorRenderers
FlightControlManager.cs
* Use the new SteeringManager swapping/removing methods.
@erendrake erendrake modified the milestone: Pre 1.1 Release Sep 9, 2015
hvacengi and others added 8 commits September 15, 2015 14:32
BindingsUniverse.cs
* Shift to get the instance of STEERINGMANAGER based on shared instead
of shared.Vessel
FlightControlManager.cs
* Switch the call to SteeringManager.RemoveInstance so that it is inside
the Dispose method instead of UnBind (breaking execution causes an
unbind, so ending a script or aborting a script caused a null
reference).
SteeringManager.cs
* Implement a new DeepCopy static method which copies settings and PID
information into a new instance variable.  Mostly for use when a vessel
un-docks and a new SteeringManager needs to be created.
* Fix an error where I was removing elements from a list while
enumerating the list, which throws an exception.
SteeringManager.cs
* Add new suffix MAXSTOPPINGTIME and associated C# member.  This value
is now used when calculating the maximum angular velocity, allowing
users to override the default behavior.
* Use the ForceVector struct within the ThrustVector class to streamline
the calculation of torque.  Also give quick access to the component
forces and torques of the different control directions.
SteeringManager.cs
* For some reason git stored the call to clear vEngines and vRcs on the
wrong lines in commit 43bd2e2, so this
corrects that issue.
pidloop.rst
* Document the PIDLoop structure for kOS.
steeringmanager.rst
* Document the SteeringManager structure for kOS.
PIDLoop.cs
* Add new MINOUTPUT suffix, allowing the minimum value to be controlled
separate from the maximum value.
* Revise the constructor to allow for the MinValue variant
* Update windup logic to match
* Removed the user facing suffix of EXTRAUNWIND
PIDLoop.cs
* Update class to change the order of Max and Min values
* Removed the EXTRAUNWIND suffix
Misc.cs
* update kerboscript function to support Min/Max and remove ExtraUnwind.
pidloop.rst
* Modify documentation to reflect max/min and remove extraunwind.
steeringmanager.rst
* Fix a spelling error.
SteeringManager.cs
* Implement an adaptive torque calculation.
* Implement but disable a feature which modifies the moment of inertia
based on measured torque readings.
* Implement and enable a feature which adds to the available torque
based on measured torque readings.
* Updates to the moving average class to try and improve performance.
* Cleaned up some of the double guards for max/min values.
* Updated engine thrust calculation to improve performance.
* Added a few debugging suffixes, but set to hide them when compiling
under release.
@hvacengi hvacengi removed Not Ready Author is warning Reveiwer not to merge this PR yet. More edits are expected. Pending Documentation Author is warning Reviewer not to merge this PR yet. User doc changes aren't in the PR yet. labels Sep 28, 2015
SteeringManager.cs
* Turn off writing to csv files by default.
Merge with the upstream develop branch.
Merge the most recent upstream develop branch.
FlightControlManager.cs
* Update new kos exception, but comment out to be deleted before
release.
FlightControlManager.cs
* Cleaned out commented code for use with old SteeringHelper class.
* Watch for steering manager to disable itself, and disable the
FlightControlParameter if it does.
SteeringManager.cs
* Allow locking to a node.
* Throw an exception if the steering value is not an expected type, and
disable control.
* Delete old UpdatePrediction method.
kOS.csproj
* Remove reference to SteeringHelper.cs
SteeringHelper.cs
* Deleted old file no longer in use.
SteeringManager.cs
* Increase the sample limit for torque moving averages.
* Implement a cap for swings of actuation to prevent one spike in
adjusted torque values from causing rapid inverse reactions.
SteeringManager.cs
* Torque producing parts are now cached for later use, preventing the
need to walk the entire part tree every update.  This cut execution time
in half on my local machines.
* Implement new method UpdateControlParts which will check to see if the
vessel's part count has changed, and if so it walks the part tree to
find all reaction wheels, rcs modules, and engines (with gimbals).
* Adapt the UpdateTorque method to use the cached values.  Because
individual parts may be enabled or disabled every frame, we can't really
cache the individual part torque values efficiently.
SteeringManager.cs
* Removed the ThrustVector class (the optimized code uses the
ForceVector struct instead)
* Adapt engine thrust vector renderers to use the ForceVector lists
instead of the removed ThrustVector lists.
@@ -152,6 +152,8 @@ public override void AddTo(SharedObjects shared)
}

shared.BindingMgr.AddGetter("VERSION", () => Core.VersionInfo);

shared.BindingMgr.AddGetter("STEERINGMANAGER", () => SteeringManager.GetInstance(shared));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for having this in the universe bindings rather than the flightstats?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No good reason, to be honest. It makes a lot of sense to put it in flightstats. I just hadn't honestly considered it.

erendrake and others added 9 commits October 17, 2015 22:28
SteeringManager.cs
* Because RemoveInstance is not kept in SteeringManagerProvider, deleted
it from the SteeringManager class itself.
SteeringManagerProvider.cs
* Restructure RemoveInstance to prevent continual circular references.
* Move SwapInstance to the Provider class.
SteeringManager.cs
* Move SwapInstance into the Provider class.
FlightControlManager.cs
* Update reference to SteeringManagerProvider
kOSProcessor.cs
* Add a call to UpdateVessel from FixedUpdate to prevent a rare bug
where the vessel changes after the UI tick but before the physics tick.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Something new (not a bug fix) is being requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants