-
Notifications
You must be signed in to change notification settings - Fork 32
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
Rodhern's update 3. #5
Conversation
Change default AoA search method to one better suited for slow flight scenarios.
…atives' section (minor graphical tweak to GUI). Rename 'siteffG' (situation effective gravity) to 'siteffg' (named 'env.effg' when exported to Octave text file).
.gitignore
Outdated
@@ -4,6 +4,7 @@ obj | |||
*.mdb | |||
/GameData/FerramAerospaceResearch/Custom*.cfg | |||
/GameData/FerramAerospaceResearch/FARForceDataUpdate.cfg | |||
/note.txt |
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 need to include this in PR
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.
Just need a few minutes to figure out how to do this :-)
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.
I just pushed the 'removed' note.txt to the source branch. I hope this is the Github way that I am supposed to solve the comment.
Vector3d sideways = Vector3.Cross(velocity, liftVector).normalized; | ||
Vector3d sideways = -forward * cosAlpha * sinBeta; | ||
sideways += right * (cosPhi * cosBeta - sinPhi * sinAlpha * sinBeta); // Rodhern: The same as Vector3.Cross(velocity, liftVector) | ||
sideways += up * (cosPhi * sinAlpha * sinBeta + sinPhi * cosBeta); // but possibly with better accuracy. |
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.
It's better to leave it as it was because Vector3.cross is more concise and better for readability unless the accuracy is much worse
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.
Sure I can change that. Do you feel it is better for readability even when the remark is in the code? I feel there is sort of a nice analogous feel between 'velocity', 'liftVector' and 'sideways' this way. It is up to you though.
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.
We're computing principal axes so cross is easier and shows that explicitly, no one will ever bother computing the last component from scratch (at least on paper) when it is also perpendicular to the other two
|
||
velocity.Normalize(); | ||
velocity += right * (sinPhi * sinAlpha * cosBeta + cosPhi * sinBeta); // Rodhern: Changed velocity 'right' and 'up' components | ||
velocity += -up * (cosPhi * sinAlpha * cosBeta - sinPhi * sinBeta); // to align vector to naive forward direction. |
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.
Which order are the rotations applied in? Need to be sure the math is correct before merging
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.
The velocity
magnitude is not equal to 1. Perhaps it should be
Vector3d velocity = forward * cosAlpha * cosBeta;
velocity += right * (sinPhi * sinAlpha * cosBeta - cosBeta * sinBeta);
velocity += -up * (cosPhi * sinAlpha * cosBeta + sinPhi * sinBeta);
http://www.kostasalexis.com/frame-rotations-and-representations.html
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.
[edit: ad velocity magnitude] Are you sure you used the formulas from my code? Did you change the components back to the code from before the merge on purpose?
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.
I wrote a python script to visualize the rotations and yours looks correct. The old implementation not only did not generate unit vectors, they were also not perpendicular and induced additional rotations. I guess this bug went unfixed for so long because large rotations were never used. The simulation should be more accurate with this fix.
pertOutput.Cl *= q * area / mass; | ||
pertOutput.Cd *= q * area / mass; | ||
pertOutput.Cl *= -q * area / mass; // Rodhern: Replaced 'q' by '-q', so that formulas | ||
pertOutput.Cd *= -q * area / mass; // for Ze and Xe match those for Zu and Xu. |
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.
I'd be careful about changing signs, I'm sure ferram had a good reason to set them the way they were. If anything, the negative signs shouldn't be there, the equations follow https://courses.cit.cornell.edu/mae5070/DynamicEquations.pdf (for the most part)
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.
You can see my reason for changing signs here: Kerbal Space Program Forum. It would be great if you can point out where it is that my reasoning fails.
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.
You're probably right, at the very least the signs should be consistent for the same axes. I'm not sure about the need for
Lines 235 to 236 in d9665fb
pertOutput.Cl += nominalOutput.Cd; | |
pertOutput.Cd -= nominalOutput.Cl; |
according to the equations.
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.
I have not really paid attention to that. Let us run through some quick back of the envelope calculations and verify that it makes sense to us. Let us look at Zw (i.e. dZ/dw).
The initial state is the aircraft flying horizontally at speed u0. In fact moving at speed u = u0 (forward), w = 0 (downward) and v = 0 (rightward). The angle of attack is some alpha.
Now imagine that we manipulate the direction of travel by rotating it ever so slightly towards the ground. We are in effect increasing alpha, and this will cause two changes that we will monitor. It changes the velocity vector and it changes the downward force. Say the rotation amount is tau radians. As an example of a specific near zero numerical value of tau I will use the symbol 2°.
The velocity deltas are,
dw = sin(tau) * u0 - 0 ≈ 2° * u0,
du = cos(tau) * u0 - u0 ≈ 0,
dv = 0.
The downward force delta (or in our case actually the acceleration delta) is, for some relevant constant k,
dZ = -cos(tau) * k * u0² * CL(AoA= alpha + tau) // the new lift component
+ -sin(tau) * k * u0² * CD(AoA= alpha + tau) // the new drag component
- -cos( 0) * k * u0² * CL(AoA= alpha + 0) // the old downward force
≈ tau * d( -cos(tau) * k * u0² * CL(tau) + -sin(tau) * k * u0² * CD(tau) )
= tau * k * u0² * ((-cos * dCL) + (sin * CL) + (-sin * dCD) + (-cos * CD))
≈ 2° * k * u0² * (-dCL + -CD)
You probably guessed by now that CL(tau) is the coefficient of lift in the given circumstances at an angle of attack equal to alpha plus tau, that CD(tau) is the corresponding coefficient of drag, and that dCL and dCD are the (mathematical) derivatives of CL and CD with respect to the angle of attack parameter (in radians).
Now if q = 1/2 * density * u0² and k = 1/2 * density * area / mass we get
Zw = dZ/dw ≈ 2° * k * u0² * (-dCL + -CD) / (2° * u0)
= -k * u0² * (dCL + CD) / u0
= -(1/2 * density * area / mass) * u0² * (dCL + CD) / u0
= -q * area * (dCL + CD) / (mass * u0)
Now compare to the code:
dCL: pertOutput.Cl = (pertOutput.Cl - nominalOutput.Cl) / (2 * FARMathUtil.deg2rad);
(dCL + CD): pertOutput.Cl += nominalOutput.Cd;
-q * area * (dCL + CD) / (mass * u0): pertOutput.Cl *= -q * area / (mass * u0);
I think it makes sense. Please point out mistakes that I make so that we do not end up confusing other comment readers.
@@ -158,7 +158,7 @@ public void GetClCdCmSteady(InstantConditionSimInput input, out InstantCondition | |||
if (!(w && w.part)) | |||
continue; | |||
|
|||
w.ComputeForceEditor(velocity.normalized, input.machNumber, 2); | |||
w.ComputeForceEditor(velocity, input.machNumber, 2); |
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.
velocity
is no longer normalized here, this will affect force computations
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.
This question is not meant in a harsh way; I am just a bit clumsy writing it succinct.
Can you produce an example where velocity.normalized is (strictly) closer to normalized than the current ('not normalized') velocity vector is?
If so that may also be a good reason to use Vector3.cross for sideways, that you mentioned in an earlier comment.
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.
Looking at both velocity
calculations neither seems to be a pure rotation, the magnitudes are not equal to 1. This suggests that there's an error in the computation.
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.
Ad velocity magnitude (spin off from earlier comments): I am well aware that the 'old' formulas do not equal a magnitude of 1. It was fixed in the original code by approximating by '.Normalize()'. I was under the impression that the velocity formula in my 'ksp131' branch did create a magnitude 1 vector. Do you have a convincing set of arguments (alpha, beta, phi) that shows the discrepancy?
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.
You're right, sorry. Had a mistake in my calculations. Still, the floating point errors can accumulate so I would normalize the vector afterwards anyway.
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.
Sure. We can do that to make it easier to read the intention of the formulas.
(for what it is worth I suspect that the direct formulas use double precision floating point calculations and the Normalize method has to deal with single precision and won't improve anything).
@@ -10,7 +10,7 @@ | |||
"MAJOR" : 0, | |||
"MINOR" : 15, | |||
"PATCH" : 9, | |||
"BUILD" : 5 | |||
"BUILD" : 6 |
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 need to change the version, I will do it when I publish a new release
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.
Roger, will set it back to 5.
LblSkipRight: | ||
if (f1 > 0) return mfobj.LinearSolution(x0, f0, x1, f1); | ||
double x2 = Clamp<double>(x1 + xstepsize, 0d, rightedge); | ||
if (x2 == x1) return mfobj.BrentSolve("Reached far right edge."); |
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.
Comparison of 2 doubles should be done to a tolerance
Thanks for your PR. I just have a few questions and suggestions.
|
In my KSP 1.3.1 version only the explicit unicode spaces show up in the GUI. That is the reason they are made explicit. The ones that are removed are to show clearer that the characters will not appear.
That makes sense; thanks.
Sounds good to me, but I am not able to code that myself.
Sound good too. Again I am not sure I have the skill and/or time to make it so. Feel free to take what can be reused and create some better export functionality.
:-)
:-)
The benefit is that BrentsMethod won't (as easily) find the maximum CL, which in turns produces an inability to solve the AoA for slow flight. The SillySearchMethod did better in my examples. |
I will probably give it a try then when I have more time.
This shouldn't be too difficult to implement, once everything is done a contour plot might be a nice additional feature.
Then a switch based on Mach number could be used. |
Agreed, that would be pretty cool.
Excellent idea. So it would kind of go: First use Brent, if that fails then go Silly ? |
Simply if mach number is below, say, 0.3, use |
Sounds fine. My only concern was that the threshold speed might be quite craft dependent. |
You can then add a check for failure but a fixed Mach switch should be faster on average. |
Sounds good. I will see when I get time to look at the code again, and get it fixed, maybe next weekend, maybe later. If you feel like tinkering be my guest and go ahead before then. |
Also, the sweep should use a new |
Do you mind submitting separate PRs for each of the changes? It would make keeping track of changes easier in case ferram ever returns and some of them can be merged already. |
I guess I can do that. I will plan to probably do that some time. |
Do you mind submitting the changes without sweep/export of the stability derivatives (can be a single PR) so I can merge them in? |
That sounds like a plan to me. I will try to find some time in the new year to make an updated pull request to one of your newer branches. I will do it as a single new untested (because I do not play any of the newest KSP versions and cannot check to see if the merged source compiles) PR, once I have removed / commented out the stability derivatives export buttons in the GUI, and added (some or most of) the code readability enhancing normalizations and tweaks discussed in the comments above. |
Closing this PR; it is to be replaced by a newer PR. |
A possible merge as per #4.
I do not use KSP 1.5.1 myself, so I can't even know if this will compile.
The changes are: