Jump to content

[1.3](Jun04/17) Automate Vertical Velocity and Altitude Control


Diazo

Recommended Posts

Diazo, I just found this mod today, and coupled with the Davon Throttle Control as you suggested, it opens up so many possibilities! The hamster wheel in my brain is only just beginning to turn. You sir, are a genius! From reading the threads, I found that MechJeb has something similar, but I found it to be lacking, compared to your mod. Very well done! I have one question, and forgive me if I accidentally skipped over it, but am I correct in understanding that the "Control From Here" element must be pointing skyward, like a Munar lander, for instance? I've taken to adding probe cores on my atmospheric VTOL ships for this purpose, but that leaves me unable to control the craft from the cockpit. Is there a workaround for that? In any case, thanks for the mod! :)

At the moment, no, that is a hard limitation.

Allowing the mod to function correctly from a horizontal cockpit is on the list for the next version but it is not here yet.

The best "workaround" I can offer at the moment is to reach your desired height, cancel my Vertical Velocity control mod by click on the "Vertical Velocity" text at the bottom of my mod's window. This will disengage my mod but leave the throttle where it is so you still hover. Then do a "select from here" command on your cockpit to get the desired control reference. (And reverse order for landing.)

D.

Link to comment
Share on other sites

I guess I wasn't thinking of the same type of VTOL's. I hadn't considered the effects of wing lift because I don't think I've ever built a VTOL with wings. I normally use a lander configuration with a jet engine under a lander pod or I use a tricopter or quadcopter configuration with girders moving the engines away from a central pod.

I suppose fuel burn changing the hover point would be a bit of an issue unless you retune the hover preset periodicly and shift all the other presets by the same ammount.

As for the pitch/roll thing, that idea came from how I do short range travel on the Mun. Rather than launching in a high ballistic arc, I usually climb to a few hundred meters then pitch forward 30 degrees. I usually want 100 to 150 m/s and I pay attention to how long it takes to get to that speed. Once I reach my desired speed I pitch back to vertical. At this point I check the map to eyeball my distance from where I started. Since there's no drag you continue over the surface at that same speed.

If you pitched forward 30 degrees to accelerate then it should take the same time and distance to stop if you pitch back 30 degrees.

If you have something to target where you started and where you're going you can use the labels to know exactly when to start slowing, otherwise you need to estimate it from the map. I find it works pretty good for moving at a decent speed for shorter trips. (10 to 50km)

I also built a Munbase recently and found that I can get pretty close to vertical, but not quite exact. It will often start to slowly drift as I descend. Since your vertical control plugin makes it a lot easier I've been placing stuff pretty close together and drift is bad. I've been using the surface panel on MechJeb to keep myself completly vertical and it works pretty good but it also wants to control heading and that can be a bother.

I also thought the pitch/roll plugin would act as sort of an easy mode for regular planes. After a turn as soon as you let go of the controls it returns to straight level flight. (assuming you set it that way before turning.

I know just what you mean about hot summer weather. We get lots of that here in Vancouver too. Best investment I ever made was a $100 air conditioner. (too bad my worst investment was also to beat the summer heat. A sailboat)

Link to comment
Share on other sites

Okay, can you drop this TWR1.dll file into the KSP-Install\GameData\Diazo\TWR1 directory and see if that smooths out control of jet engines?

Note that I will not be able to get rid of the bounce entirely, but the file I just linked to should significantly reduce it.

I will not be able to get rid of the bounce because jet engines simply take a long time to spool up. I timed it during one of my tests, it was 35 seconds from 0 to 100% thrust.

On the pitch/roll thing, the RCS mod I'm thinking off will be the final 30-40m/s of sideways velocity that you have to get rid of, the cancellation of the majority of your sideways velocity will still be from your main engines during the drop phase as you angle in.

I do more drops from orbit then suborbital hops as you just described, but I find that since I angle retrograde most of the way down, my sideways speed naturally slows itself as I am angled in my direction of horizontal travel and I only have that little bit of speed left to kill that can easily be handled by RCS.

@Using mod on a cockpit: I actually had a brain wave on this, I think I can slap something together tomorrow night after work for this. If the jet engine tweak works out I'll make these two things the next official release.

D.

Edited by Diazo
Link to comment
Share on other sites

Diazo, I tried the new DLL file, and it failed to control the jets at all, once it got airborne. I clicked the +1 velocity button, and the computer slowly advanced the throttle to about a 1.2 TWR, but trying to kill the speed, reduce the altitude, or lower it, did nothing after that point. The VTOL just continued to climb. I did make sure to have a probe core installed, so that the navball showed me pointing straight up.

By the way, if you manage to find a way to make this work from the cockpit, I will have your babies! :sticktongue: For me, being able to control motion front to rear and side to side like a helicopter, is far easier than trying to kill speed by finding the retrograde marker in an atmospheric VTOL. Keeping my fingers crossed!

navBall.jpg <---That's the stuff!

Link to comment
Share on other sites

OK, Just tried it again with a brand new craft, and it works excellent. The first VTOL I tried had the engines mounted on Infernal Robotics Docking washers, although they were pointed straight up. I wonder if that was throwing it off.

EDIT: I was fooling about, and managed to destroy one of my three jet engines. The SAS kept the vessel upright, and your mod automatically and instantly responded to the sudden loss of mass and thrust. I can't tell you how impressed I am! :)

Edited by Voculus
Link to comment
Share on other sites

PID, Proportional Integral Derivative is what might be able to tame those sluggish jet engines for hovering. https://en.wikipedia.org/wiki/PID_controller

The plugin would have to read the engine part CFG data to calculate the thrust/time curves then add those for all the engines on the craft (and as the people doing MechJeb found out, calculating thrust for off-axis pointing engines is a PITA). Combine that with the ever changing mass of the craft as fuel is burned and it should be possible to get the correct throttle adjustment to achieve the desired altitude change with little or no overshoot or bouncing.

Some interesting info on real jet engines. http://boards.straightdope.com/sdmb/showthread.php?t=696218

http://www.airliners.net/aviation-forums/tech_ops/read.main/99094/

Current FAA regulations (linked in the straightdope one) require commercial turbofan jet engines to be able to spool up from "flight idle" (which is higher than "ground idle") to 95% power in no more than five seconds. Turbojet engines (without that big fan that's basically a multi-blade, shrouded propeller) can have a considerably faster throttle response.

Link to comment
Share on other sites

@Galane: I did consider a PID controller way back when I started, but the rocket engines on my skycranes I was working with at the time have effectively instantaneous response so I did not need it and while I am familiar with them because the company I work for uses them all the time, I don't personally work with them and would have had to learn PID and programming at the same time. (This mod was effectively my first programming project ever when I started.)

@Voculus: About an hour after I signed off for the night I realized I'd screwed the math up on that .dll I linked to you. It might have a little better throttle control but it will probably be about the same as the official release.

It is a two second fix, but it will have to wait until I get home from work tonight before I can correct it.

@Control from the cockpit: I also know how to make this work, but I will have to modify the UI to fit a couple more buttons it will require as the player needs to be able to control the switch between Rocket and Plane mode.

D.

Link to comment
Share on other sites

Isn't working for a company that uses PID technology an excellent reason to learn the deep down stuff on how they work? ;) Might gain yourself a pay increase or other perks...

Adjusting the throttle response of the jet engines in KSP could be a useful method of simulation testing of PID algorithms. Tweak the throttle response to act like something that needs PID controlled, then write the code to work with it. Then the code can be tried on the real application the KSP engine was adjusted to mimic. Certainly cheap enough it won't break any budgets.

Edited by Galane
Link to comment
Share on other sites

@Jet engine throttle: I've tweaked the compensation again and I think I have the bounce as low as it can go. It is still pretty bad but one of the fundamental assumptions my mod makes is that it will have instant (or close enough) throttle control. It would be a rewrite from the ground up at this point to fix that issue. (And so will almost certainly not happen.)

@Control from cockpit: This is about half done. I've not really worked with rotations before and so I'm learning as I go here. I will offer control from all 6 directions however if for some reason you wanted to use a backwards cockpit or an upside down control module on a rocket.

@Galane: Heh, I would like that. Not my job though, I'm the draftsman, I just sit next to the programmers.....

D.

Link to comment
Share on other sites

Version 1.11 Alpha release, not linked in first post.

Alright, for those interested, the alpha version of 1.11 is available here.

This is not final, I have 2 things to fix.

For those that download this, it has yet another version of the Jet Engine spooling compensation code and the ability to change the Up direction to allow flying from a cockpit.

To change the Up direction, open the settings window.

Click the 'Direction' button to display a red arrow in the current upwards direction. Click the Up, Down, Forward, Back, Left, Right (U D F B L R) buttons to change the direction until the red arrow points up.

People launching rockets should be able to leave it at default, people launching planes will probably want Back.

Reason this version is still alpha:

The up direction does not save, it will reset to default (for rockets) every time you switch vessels. I want to get this saving on a per ship basis.

I need to change the directions, planes should use Forward, not Back as they currently do.

I want to go over the Jet Spooling compensation again. I know I won't get rid of the bounce but I think it could be better.

If you try it out, let me know what you think.

D.

Link to comment
Share on other sites

First off, a thousand thanks, Diazo! I gave the new DLL a whirl, and found that while using jet engines, if I set a height of something like 1000 meters, it has a hard time settling in on that altitude, as it bobs up and down several hundred meters at a time. No doubt a limitation of the way jet engines spool up and down at different rates. I don't fault your mod for that at all. However, for my jet VTOLs, I prefer stepping up the climb rate in small increments, and it works flawlessly. The throttle is smooth and accurate, and compensates for changes in pitch and lift quite nicely. :) I did notice an odd quirk, however. If I'm climbing, and click the zero vel. button, it smoothly stops the climb and levels out. If I use the keyboard, by pressing Z+X, the engines cut out briefly, the ship will drop a couple meters, and then it will enter a hover.

Secondly, being able to control from the cockpit is so frakkin' cool, I can't even tell you! Looking out the cockpit glass, or using the chase view from the aft, while being able to use the stick and rudder pedals like a conventional aircraft is incredibly fun.:cool: Also, showing the red direction indicator was brilliant!

Right-click and "view image", because it's so ridiculously large!

screenshot189.png?psid=1

This is a little light duty lifter VTOL I've been trying to perfect these past few days. So far, it's shaping up very nicely, and thanks to your Vertical Speed mod, along with Davion's throttle mod, this ship one of my most favorite craft ever. You can see it carrying the "New DLL Test Ship" below. That was the craft I used to test your new file. I hauled through the space center from the runway to the launch pad, killed the rear engines and forward velocity, hovered over the ship, and picked it up with the KAS magnets. I had planned to drop i t off at the island runway, to see how the ship would handle a swinging load, but as I was mashing away at the keyboard, the Windows Sticky Keys popped up! When I closed it and returned to the game, the ship spun out of control, and crashed, so then I decided to write this. Thanks again!

Link to comment
Share on other sites

Ok, with a bit more testing, the X+Z key combo is behaving nicely. Not sure what the deal was. Maybe just a quirk of the Gladius VTOL engines, which are awesome, by the way. The keyboard commands are a lifesaver, since I have one hand on the flight stick, and it's hard to let go to click with a mouse!

Edited by Voculus
Link to comment
Share on other sites

Glad to hear it's working out for you!

The Z+X dropping thing is cause by the fact that I don't actually stop the keyboard command so when you hit X KSP gets the "cut throttle" command and for an instant your throttle drops to 0%. The mod bring it back up almost instantly, but only almost.

Now that I'm more familiar with how key bindings work, I'll go ahead and add an intercept so that when the Z key is held down, throttle commands are no longer passed to KSP. (The same thing happened to up and down throttle also but is unoticable due to how small an effect those have.)

D.

Link to comment
Share on other sites

Version 1.11 Release

-Tweaked Jet Engine spooling compensation to reduce the bounce experienced when Jet Engines are the primary source of lift.

Note that due to how the mod performs calculations this bounce can not be totally removed and so Height Control is not recommended when using Jet Engines.

-Add the ability to select which axis is up.

Now VTOL's with cockpits can use this mod to take off and land without having to put a secondary probe core on the vessel that is rotated as the mod expects.

If modulemanager is installed, this setting will be remembered on a per craft basis.

The mod will still work without modulemanager installed, but the up direction will reset each time a craft loads.

As always, feedback is appreciated, especially for those using this with the Davon Throttle Control. Would having the ability to select which throttle(s) are controlled by my mod be beneficial?

D.

Link to comment
Share on other sites

Alright, I've been doing a lot more stress testing, and there's just one odd quirk that seems to be mostly related to mod part landing gear. For instance, the Firespitter tailwheel, when attached anywhere to the vehicle breaks the velocity and height modes. I can enter a height of 10m as an example, and the craft will throttle up enough to gain altitude at a pretty good speed, but the radar altimeter reads zero, and the ship keeps shooting straight up. I discovered by accident, when I broke off those wheels from a hard landing, that the plugin began working normally again, without having to reload the craft. Anyway, it's not a huge deal, since most of the B9 and TT wheels I tend to use work great with your mod.

Now here's my other question: Is it possible to switch between two separate engine profiles? One for long-spooling engines like the jets and KAX props, and another, much more aggressive profile for near-instant engines like helicopter rotors and rockets? I ask this, because when I'm using height control mode, the ships have a hard time compensating for somewhat medium variations in the terrain, even with plenty of reserve power to pull it off. I'm going to try and whip up a video to show exactly what's happening.

Edited by Voculus
Link to comment
Share on other sites

For those who are interested in the sideways velocity cancelling mod I've talked about, I have the initial release of it here.

@Firespitter tailwheel: Odd, that is really strange behavior. I'll look into it and see what is going on as I am now curious, I can think of anything that would make a part cause the behavior you describe.

@Height control: It sounds like I need to take another look at the control math for this. I've gone through a few different versions and what is in there now was the best I found at the time but I have yet to find the math that feels right for this, I've only been able to get it close enough.

I should have some time this afternoon to look into both of those.

D.

edit: Fix is in for the tailwheel breaking everything. It has its part collider defined in a non-standard way so my mod could not find it and as this had not come up before I did not have my error trap setup correctly.

Looking at the height control now.

Edited by Diazo
Link to comment
Share on other sites

OK, it takes Youtube ages to render the vid in HD, so you may need to rewind to see the throttle and mod window, but you can see it applying a bit of lift, but not enough to clear the deck without having to maneuver manually. Not that I'm looking for a magical autopilot, but the idea of a kind of low and fast ground following radar type of flight control is just awesome! I'm going to check out your newest mod. Your hard work is much appreciated. :)

Link to comment
Share on other sites

Version 1.12 Release

-Fix parts with non-standard colliders so they no longer lock the engines at max. (The firespitter tail wheel.)

-Redo height control code from scratch to clean it up.

Let me know how the height control now works. Once I started looking into it, I realized I'd left it in quite a mess and so I just ripped it all out and redid everything.

Note that due to the limitations I'm working under, there is still overshoot present, but we are talking kilometers of vertical travel before you see more then a few meters of overshoot. This still means however that if you want to try landing on height control rather then velocity control, you need to pause and stabilize at 100 or 200 meters and then go down from there. It was reasonably reliable in my tests, but most of my tests use small, high TWR vessels so I will not guarantee a safe landing. :)

D>

Link to comment
Share on other sites

It seems as if there's no change in behavior. For the last round of testing, I set the height to 20m, and approached a 30° hill at about 30m/s. The throttle was at about 50% to maintain the height, but as the ground rose up, the throttle refused to move more than a hair, even though there was plenty of power for it to use. It seemed the rate at which the altitude above ground varied, was much higher than the throttle was allowed to change. Maybe I'm just trying to make it do something other than what it was intended for. I feel bad about making you redo all of your work just on account of me.

I'm going to try some lighter ships, with a much higher TWR.

EDIT: The higher TWR isn't doing the trick, either. The ship simply hovers with less throttle required, but will not change altitude above a certain rate.

Edited by Voculus
Link to comment
Share on other sites

Heh, no worries.

When I looked back at it again, the code was a mess of if conditions and conditional statements that was just ugly and begging to be ripped out.

It calculated your desired velocity in 6 different ways depending on what the state of your vessel was, and then double that to 12 ways because I had to flip to a negative setpoint if the vessel was above your target altitude. I ripped all that out and replaced it with just 2 ways, one for above and one for below the height setpoint, with an exception if the vessel is really close to target altitude to mitigate bouncing.

The fact that it behaves the same after I've gutted and rewritten everything is actually very good news as it means I got the rewrite correct.

Anyways, wall of text time. Here's what's happening in the background that's making this so iffy.

First, the way the mod works is that the actual control of the engines is done by velocity setpoint, even when in height control mode. When in height control mode I mask this by calculating a velocity setpoint based on how far you are from your target altitude, but I'm still passing a velocity setpoint to the engines.

Also, this setpoint is done to the terrain straight down, I have no method for checking forward to see what terrain is coming up, just the terrain directly below the vessel. The mod does check each part's distance to ground so it should be using a part at the front of the vessel for distance, not center of mass, so it should start climbing as soon as the nose hits the hill.

Then I have to contend with the acceleration delay, the mod is reactive, not predictive, so it can not start increasing the throttle until it sees the hill.

Then there seems to be a fudge factor in KSP itself, I never see acceleration or velocity changes as fast as the math implies I should be seeing them.

What this all means, is that if you are within the force of gravity as distance (so 9.8 meters on Kerbin), I've put a limit on your velocity, otherwise the acceleration delay would cause you to bounce as the mod was effectively ahead of your vessel's situation and the engines were trying to catch up.

I got around this by putting a hard limit on what your velocity can be near your target altitude, but it sounds like it is too restrictive for what you are trying to do. What your post has made me realize is I took the restriction for descending (that I made very restrictive to make sure skycranes were not overshooting and crashing) and copy-pasted it for the ascending limit when it does not need to be as restrictive since there is no danger to overshooting your target while ascending.

So, let's do some math on your example of 30° at 30m/s. With that, the terrain rises 9m a second, so my mod has 2 seconds to avoid a crash if you start at 20m. (Technically 18m, but close enough).

With the current limits in place that's... ouch

Never mind the time, the ground is climbing at 9 m/s, but for a height difference of 20m, the mod will only try to move upwards at 4.9 m/s.

I can certainly relax that restriction when moving upwards, I'll have to test and see by how much though.

The ground climbing at 9m/s is fast though, I'm not sure that can be compensated for without looking forward to predict the future terrain.

I'll see what I can do.

D.

Link to comment
Share on other sites

I didn't realize how taxing the flight regime was, that I was asking for. Putting math to it makes it a lot clearer. Thanks for shedding some light on your work. As always, it's very appreciated. :)

Link to comment
Share on other sites

Alright, here's a version of the .dll with tweaked height control.

It is much more aggressive going up which means there is now some over shoot, but there should not be anything more then 5 meters in any flight profile I can imagine people using. (If I assumed wrong, make a comment with your flight profile and I'll look into it.

On the 30° at 30 m/s example for 9m/s terrain height change, the mod will now try to rise at 9.8m/s (Kerbin's gravity) at 20m below target. This will be true until 14m below target at which point the mod will try to set the upwards velocity at 70% of the distance to go. (So an upwards velocity of 1.4m/s if you are 2m below target.)

I'm not sure this could handle the 9m/s example mind you, but it will come an awful lot closer now.

I also tweaked the going down code and almost eliminated the overshoot going that way. Using Hyperedit I threw a ship at the moon from 200km up and 400m/s downwards. The new code stopped the ship at 1000m with only 5-6 meters of overshoot so I'm going to call that acceptable.

As always, any comments are good comments.

D.

Edited by Diazo
Link to comment
Share on other sites

A terrain following radar part that aims a 'radar beam' out would be a useful addition. Reading the angle the part is mounted at, relative to the straight down vector the mod uses for height control... I suspect would not be trivial. Perhaps a modification of a quantum strut?

But it would be cool. Could also open up the door to things like station or distance keeping in space, or triggering actions when a set distance from another object is reached.

Hmmm, instead of a single beam, how about an inline stack part that has several beams down at a fixed angle? For planes it could be a part that has a half circle of beams. Could end up with several parts for different ways of mounting and required to be attached upright to avoid calculations due to user placement at arbitrary angles.

Link to comment
Share on other sites

@Galane: I don't think any of those things is going to happen with this mod.

The reason being that this mod is to land skycranes safely and for that all that is needed is the distance to terrain straight down.

I enjoy tweaking features to help people out (this is a learning experience in programming for me), but I'm not going to be adding new features that double (or triple) the size of the mod in terms of code.

What you are talking about is a true autopilot really, that is well beyond the scope of what I want to attempt with this mod.

@Dll I linked in the last post: I'm going to give it a few more days for feedback (and tweaks if needed) before pushing that .dll as an official release.

D.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...