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
Fix cooked steering #1118
Conversation
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
…o fix-cooked-steering
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.
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.
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.
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.
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)); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
…ing' into fix-cooked-steering
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.
This is my first attempt at the re-write for the cooked steering. It both includes steering and vector renders to show orientation.
Todo:
[ ] [Optional] Account for engine static torque[ ] State vectors continue to update when steering is not locked[ ] Implement as FlightCtrlParameter[ ] Clean up commented debug code and unused methodsWill do with optimizations on next release