Jump to content

Kramer

Members
  • Posts

    32
  • Joined

  • Last visited

Everything posted by Kramer

  1. Yes, that should be very possible. People just need to create the flight plans for approaches to the runways in question. It takes some work but is not too hard. If there are no big obstacles it is pretty easy. You just create waypoints lined up with the runway at the proper distances and altitudes and it should work. - - - Updated - - - I didn't worry about landing on RW27 since I wanted a straight in approach with no circling and was always orbiting in the normal direction. But it would be easy to add an approach to RW27 as it is just over water so no obstacles. The RW09 approach was a real pain because of those mountains. Who locates a spaceport right next to Mt. Everest (oh, a Kerbal does, dumb question)? The RW09 approach kind-of threads the needle to avoid the peaks. As long as your are more or less on course it is no problem. RW27 would be safer but require a lot more maneuvering down low. I was hoping that people would contribute approaches to other runways. I would then include them in the default flight plans. Also it organize the approaches per-planet so flight plans for other planets will not show up. This is my first release and I am sure there are bugs and such that I would hope to fix as well as adding approaches.
  2. Yes, I almost gave up on it when I discovered this bug in Unity where AddComponent<type> seems to get the string name of the type and then look that up to actually create an instance. And it always used the initial version of the class instead of the newly loaded one. But then I realized that C# allows you to generate code dynamically and wondered what would happen if I created an uniquely named class on the fly and it worked! The ability to "emit" code is a pretty cool feature of C#. There is nothing like that in C++. - - - Updated - - - Let me know if you have any problems or questions.
  3. V0.1 Download: GitHub Kramax Plugin Reload I started developing an autopilot mode (Kramax Autopilot) and I normally develop software using a very quick modify/test cycle. I quickly realized that waiting for KSP to restart every time I wanted to try out a change I had made would make it take so long to develop that I would probably give up first. I looked around for a solution that would allow a plugin developer to dynamically reload the compiled plugin without restarting KSP. I found "KSPPluginReload" by m1nd0. Unfortunately I could not get it to work properly with the way my other mod was structured. The mod used a MonoBehavior sub-class and it seems that there isa bug in Unity that made it instantiate the old version of my objects even when I loaded a new DLL. The only way I was able to get it to work was to actually dynamically change the class names of my components every time the mod was loaded. This works for a plugin that uses KSPAddon to start and stop. It will NOT work with a plugin that uses sub-classes of VesselModule to work. Your sub-classes MUST be direct sub-classes of MonoBehavior. Instructions First you need to setup your project. I setup the "Debug" build of the project to use plugin reload and the "Release" build to NOT use it. This way you can debug with the reloadable mod and release your mod to the world without it. To do this you need to first add the assembly "KramaxReloadExtensions" that is in this mod as a reference assembly.This assembly is used in your debug build to do the DLL reloading.Next you need to copy the file "ReleaseReloadableMonoBehaviour.cs" into your project. This file is used in release mode when you want to release your mod to the world. Sadly in order to make this work you will have to hand edit your "csproj" to make the use of the KramaxReloadExtensions assembly conditional based on build configuration. You need to find the line the csproj file that is like this: <Reference Include="KramaxReloadExtensions"> <HintPath>..\..\KramaxPluginReload\bin\Debug\KramaxReloadExtensions.dll</HintPath> </Reference> and change it to this: <Reference Condition="'$(Configuration)' == 'Debug'" Include="KramaxReloadExtensions"> <HintPath>..\..\KramaxPluginReload\bin\Debug\KramaxReloadExtensions.dll</HintPath> </Reference> Using ReloadableMonoBehaviour Your sub-classes which inherit from MonoBehavior need to inherit from this mods class ReloadableMonoBehaviour instead. ReloadableMonoBehaviour is a direct sub-class of MonoBehavior that adds a "type mapping" property that is used to ensure the correct class types are used for the DLL that is reloaded. Next, you need to change any calls to GameObject.AddComponent to use the method provided by ReloadableMonoBehaviour ReloadableMonoBehaviour.AddComponent(type). For example, in my autopilot, my main top-level object is a MonoBehavior. It looked like this: [KSPAddon(KSPAddon.Startup.Flight, false)] public class KramaxAutoPilot : MonoBehaviour { public void Start() { mainPilot = gameObject.AddComponent<George>(); } ... } This needed to be changed to this: [KSPAddon(KSPAddon.Startup.Flight, false)] public class KramaxAutoPilot : ReloadableMonoBehaviour /* note changed baseclass here */ { public void Start() { mainPilot = AddComponent<type(George)> as George; /* note AddComponent call and cast */ } ... } If you use any other varient of AddComponent they also need to be changed. Installation This mod needs to be installed in your KSP GameData directory as a normal mod would be installed.Normally it would go into GameData/GramaxPluginReload. The DLL files will be in GameData/GramaxPluginReload/Plugins including both KramaxPluginReload.dll and KramaxReloadExtensions.dll. The Settings.cfg file in GameData/GramaxPluginReload is used to configure where the plugin you are developing gets loaded from. You can just copy the folder https://github.com/Kramax/KramaxPluginReload/tree/master/GameData/KramaxPluginReload to your KSP GameData folder. Here is a sample entry for my autopilot mod: PluginSetting { name = KramaxAutoPilot path = C:\root\DevKSP\KramaxAutoPilot\Source\bin\Debug\KramaxAutoPilot.dll loadOnce = false methodsAllowedToFail = false } You should change the name and path to match your plugin. The other settings should be left alone.You can have multiple PluginSetting objects in the config file for more than one plugin.Note the path can be outside of your KSP install directories--in fact using the place where your compiled DLL gets put works best. Reloading The plugin reload mod will create a UI window with a title "Plugins" and one button "Reload plugins".Simply recompile your mod and press the button. It should load the new version of your DLL. If you do not actually create a new DLL the reload will not work. How It Works When it reloads (or loads the first time) your plugin DLL it does the following: First it goes through all the loaded plugins it is managing and DELETES the instances of objects created with the old DLL.It loads your (new version) DLL (assembly) by loading the file as "bytes" and then using Assembly.Load(bytes). It does not load directly from the DLL file or it would not reload properly.It then creates a "dynamic assembly" that it names using a scheme of "KramaxPIRLAsmb_#"where # is replaced by a sequential count.It scans all the class types in your mods assembly for sub-classes of MonoBehavior and creates a dynamic sub-class of each type with a unique class name such as"KramaxAutoPilot_43" (it adds the number which increments every time).The dynamic sub-class simply creates a unique name for the class and adds a default constructor.It keeps track of these unique class names in a "type mapping" dictionary. This type mapping is used to instantiate new components. It never instantiates the original class,always the unique sub-class.It looks at the KSPAddon attributes of the classes and starts them if they are supposed to be started based on the current scene.When a ReloadableMonoBehaviour sub-class is instantiated it uses the type mapping to create the write type of object and propagates that type map to any sub-components. Example I know this all sounds pretty confusing. You can look at my autopilot mod for a real-world example.The source is found at: https://github.com/Kramax/KramaxAutoPilot. Attributions This plugin is a modified version of "KSPPluginReload" by m1nd0.Many thanks for an excellent starting point for this mod. License This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. The file "ReleaseReloadableMonoBehaviour.cs" is excepted from this license and is released into the public domain. This work is a derivative of "KSPPluginReload" by m1nd0 that was distributed under the same license.The original work was found at https://github.com/m1ndst0rm/KSPPluginReload.
  4. Well, Gaalidas, its open source, so have at it! But I actually did not remove that much stuff. Curious if you tried it, what was it you were actually missing? -Kramer
  5. Thanks! No, I forgot that the runway changes length. Does the threshold of RW09 actually move? Is the midpoint always in a constant location? In any case, it would be easy to just create some alternate approaches (ILS 09 1000M RW say) that have the threshold point (RW) adjusted. You could just copy the ILS approach from the DefaultFlightPlan.cfg file into FlightPlan.cfg and adjust the longitude of the RW point. That being said, it currently tends to land most of my spaceplanes about 1/5 the way down the runway (as in, when the wheels touch). It aims for a point 30M above the runway at the threshold before starting a flare. So for some configurations the stock ILS would probably work fine. -Kramer
  6. V0.2 Download: Github/KerbalStuff V0.2 Released: Add first cut at RW27 approach to KSC to default flight plans. Change window IDs to hopefully now be unique and not collide with PA mod. Make hitting the target speed button with the auto-throttle off turn it on. Make app launcher button see the correct state of the GUI window so it should always toggle properly. Sample Flight Video Kramax Autopilot Recently I started flying spaceplanes in Kerbal and discovered I could never land them successfully. My keyboard flying skills are sub-par. This despite being an instrumented rated pilot of real planes. I found a very good autopilot mod by Crzyrndm called "Pilot Assistant" (see thread). But it did not have any course following abilities. I have taken the source code for Pilot Assistant and heavily modified it to add course guidance (both horizontal and vertical) so that it can autoland a spaceplane on the KSC runway. Many thanks to Crzyrndm--this mod would never have happened without the excellent starting point. Note that I did not keep all the capabilities of Pilot Assistant--I was very focused on auto-landing and things that were not really needed for that were omitted. Flight plans can be loaded from configuration files located in the GameData folder. There is currently no capability to create new flight plans on the fly within the game, but you can edit the GameData/KramaxAutoPilot/FlightPlans.cfg file and add flight plans that way. Look at GameData/KramaxAutoPilot/DefaultFlightPlans.cfg for the format of the flight plans. The "Refresh" button on the flight plan load/save dialog will reload from that file so you do not have to restart the game every time you change a flight plan. Basic Instructions You can use the autopilot to depart from KSC runway 09 as well as land on it. Here is a basic flight using the autopilot. You start lined up on KSC RW09. Departure Show the autopilot window by selecting the airplane icon from your toolbar Press the "Load/Store" button next to the "Flight Plan" button. This will display the flight plan loading window. Select the plan named "KSC DEP 09". This is a flight plan that takes you straight out on a heading of 090 to space. You can close the flight plan loading window now. Select the horizontal mode "NAV" and enable horizontal mode by selecting the button "Roll". The autopilot should track straight down the runway now. I normally use "pitch hold" mode for vertical control on departure. You can set this up for use after rotation by selecting the "Pitch" button and entering a desired pitch up amount (10-30 degrees, depending on your thrust to weight ratio). Start your takeoff. It should track down the runway and after you liftoff, turn the vertical mode autopilot on by pressing the "Target Pitch" button. It should pitch up to your preset pitch value. It should retract your gear at 150m of altitude. Now just control pitch angle to what works for your vehicle. When you get to high altitude where aerodynamics more or less stops, you should turn off the autopilot modes by pressing the "Roll" and "Vertical" buttons. Hopefully you get to orbit Landing You need to de-orbit. For KSC RW09, I found that when coming from an 80km orbit, a 100m/s retrograde burn just before I get to the huge impact crater seems to work well. Depending on how fast your craft decelerates you may need to burn slightly earlier or later. Setup the autopilot by loading the landing flight plan. You want to open the flight plan load/save window and select "KSC ILS 09" (ILS stands for "instrument landing system"). This flight plan has an initial point to aim for that is named "MAXKY". It is at 12000m, more or less on the equator about 75km West of KSC. Descend into the atmo and try to stay on a heading of 090. I generally enable the autopilot around 20000m altitude. I initially will enable it in Bank mode (level) and pitch hold mode (4 to 6 degrees). As you near 12000m altitude enable NAV mode and altitude hold of 12000m. When you get very close to MAXKY, enable GS mode to follow the vertical guidance. Now setup your landing speeds. Open up the "Approach Speeds" pane at the bottom. Change the speeds to match your craft. You want to land as slow as possible, so make your final speed something that is a good margin above stall speed. After passing MAXKY you can enable auto-throttle "Landing" mode to hold current speed and then decrease it to match the approach speeds as it heads for the next fixes. At 500m (above ground) it should auto-lower your landing gear. But a good pilot makes sure he has 3-green before touching down! If all goes well it will cut your throttle right over the threshold, touchdown, and turn on max braking. Attributions This plugin is a heavily modified version of "Pilot Assistant" by Crzyrndm (https://github.com/Crzyrndm/Pilot-Assistant). At least half (if not more) of the code is his. Many thanks to him, as this would never have been possible without it. In addition, I drew heavily on algorithms for calculating great circle routes from http://www.movable-type.co.uk/scripts/latlong.html. Many thanks for that information. License This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA. This work is a derivative of "Pilot Assistant" by Crzyrndm that was distributed under the same license. The original work was found at https://github.com/Crzyrndm/Pilot-Assistant.
×
×
  • Create New...