Jump to content

Access drag and lift data from FAR for each part of my aircraft with kOS


Kerburettor

Recommended Posts

Hi,

First of all I want to say that I'm a complete newbie when it comes to the inner workings of KSP and its mods. I've got a rudimentary knowledge of C# but I can decode scripts if geven enough time. Also, I haven't found a similar topic that already addresses this topic but if there's already one, I'll be more than glad to append my request to the existing thread and remove this one.

Using kOS, I'd like to read aero data for any part of my aircraft (or at the very least parts identified as wings). The kOS-Ferram addon developed by Giulio Dondi helped me get the overall lift and drag of the aircraft via his wrapper that interfaces kOS and FAR. For example, the following command is used to get the value of the vesselLiftCoeff variable defined in FAR:

SET lift_coeff TO ADDONS:FAR:CL.

However this variable corresponds to the total lift of the aircraft, which I do not need. Is there a means to extract the aerodynamic data for each individual part of a ship?

I would like to avoid having to recompile FAR and the kOS-Ferram addon because I simply don't know how to compile these mods (although I'd be more than glad to be walked through the process).

But if that's what I need to resort to, here is how I imagine the way forward:

  • Modify the FARAPI.cs code in FAR to extract the lift and drag for any part of the aircraft. Currently, total lift and drag coefficients are extracted thanks to the following static methods in the FAR API:

        public static double ActiveVesselLiftCoeff()
        {
            return VesselLiftCoeff(FlightGlobals.ActiveVessel);
        }

        public static double VesselLiftCoeff(Vessel v)
        {
            FlightGUI gui = VesselFlightInfo(v);
            if(gui == null)
                return 0;
            else
                return gui.InfoParameters.liftCoeff;
        }

        public static double ActiveVesselDragCoeff()
        {
            return VesselDragCoeff(FlightGlobals.ActiveVessel);
        }

        public static double VesselDragCoeff(Vessel v)
        {
            FlightGUI gui = VesselFlightInfo(v);
            if(gui == null)
                return 0;
            else
                return gui.InfoParameters.dragCoeff;
        }

I'm still not sure how this could be done but I guess I could loop over all the parts of the current vessel and provided they are a lifting surface, save the liftForce and dragForce attributes of each part in a dictionary (the keys of which correspond to each part of my aircraft) that would be fed to kOS in a lexicon.

  • In the kOS-Ferram addon, add suffixes in the Addon.cs script to extract the lift and drag of an individual part. In the following example, this is the current implementation of suffixes to extract the vessel's total lift/drag coefficients:

private void InitializeSuffixes()
{ 
    AddSuffix(new string[] { "CL", "LIFTCOEF" }, new Suffix<ScalarValue>(GetLiftCoef, "Current vessel's Lift Coefficient."));
    AddSuffix(new string[] { "CD", "DRAGCOEF" }, new Suffix<ScalarValue>(GetDragCoef, "Current vessel's Drag Coefficient."));
}

and add new entries corresponding to these suffixes, for example:

private ScalarValue GetLiftCoef()
{
    if (shared.Vessel != FlightGlobals.ActiveVessel)
        throw new KOSException("You may only call addons:FAR:LIFTCOEF from the active vessel.");
    if (Available())
    {
        double? result = FARWrapper.GetFARLiftCoef();
        if (result != null)
            return result;
    }
    throw new KOSUnavailableAddonException("LIFTCOEF", "Ferram");
}
  • Add an entry in the FARWrapper.cs wrapper like this one:

FARCD = FARAPIType.GetMethod("ActiveVesselDragCoeff");
if (FARCD == null)
{
    SafeHouse.Logger.Log("FARAPI.ActiveVesselDragCoeff method is null.");
    wrapped = false;
    return;
}

which in this example uses the ActiveVesselDragCoeff method from the FAR API.

However I'm completely clueless as to what is the best way to proceed. Any help?

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...