Skip to content
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

JSBSim can't interpolate between n dimensions #1117

Open
TrentConley opened this issue Jul 3, 2024 · 5 comments
Open

JSBSim can't interpolate between n dimensions #1117

TrentConley opened this issue Jul 3, 2024 · 5 comments

Comments

@TrentConley
Copy link

TrentConley commented Jul 3, 2024

I've read an implemented Jon's advice here, but it looks like the nester interpolation is not happening, since the GetValue() function called on the parameters provides a double value rather than calling interpolate again. See src/math/FGFunction.cpp at line 691.

For the RC craft I am working on, I'll need at least 6 dimensions to interpolate from to produce 6 distinct aerodynamic coefficients.

Below are two examples of how I was setting up the nested interpolation. Neither worked since they each only interpolated once:

      <function name="aero/coefficient/CD">
        <description>CD Coefficient</description>
        <interpolate1d>
          <p>aero/beta-rad</p>
          <v>-0.3476658503988659</v>
          <interpolate1d>
            <p>aero/alpha-rad</p>
            <v>-0.063651317007977318</v>
            <interpolate1d>
              <p>fcs/rudder-pos-rad</p>
              <v>-0.4690658503988659</v>
              <interpolate1d>
                <p>fcs/left-aileron-pos-rad</p>
                <v>-0.3490658503988659</v>
                <interpolate1d>
                  <p>fcs/right-aileron-pos-rad</p>
                  <v>-0.3490658503988659</v>
                  <v>-0.02731959022</v>
                  <v>0.3490658503988659</v>
                  <v>-0.025771052</v>
                </interpolate1d>
                <v>-0.17453292519943295</v>
                <interpolate1d>
                  <p>fcs/right-aileron-pos-rad</p>
                  <v>-0.17453292519943295</v>
                  <v>-0.01767199402</v>
                  <v>0.17453292519943295</v>
                  <v>-0.01580392049</v>
                </interpolate1d>
                <v>0</v>
                <interpolate1d>
                  <p>fcs/right-aileron-pos-rad</p>
                  <v>0</v>
                  <v>-0.01419396561</v>
                  <v>-0</v>
                  <v>-0.01419396561</v>
                </interpolate1d>
                <v>0.17453292519943295</v>
                <interpolate1d>
                  <p>fcs/right-aileron-pos-rad</p>
                  <v>0.17453292519943295</v>
                  <v>-0.01857091949</v>
                  <v>-0.17453292519943295</v>
                  <v>-0.02048905171</v>
                </interpolate1d>
                <v>0.3490658503988659</v>
                <interpolate1d>
                  <p>fcs/right-aileron-pos-rad</p>
                  <v>0.3490658503988659</v>
                  <v>-0.03070267218</v>
                  <v>-0.3490658503988659</v>
                  <v>-0.03315893703</v>
                </interpolate1d>
              </interpolate1d>
      <function name="aero/coefficient/CLalpha">
        <description>Lift_due_to_alpha</description>
        <interpolate1d>
          <property>aero/beta-rad</property>
          <value>0</value>
          <interpolate1d>
            <property>aero/alpha-rad</property>
            <value>-0.06981317007977318</value>
            <table name="aero/table/CL_aos0_aoa-4">
              <independentVar lookup="row">fcs/elevator-pos-rad</independentVar>
              <independentVar lookup="column">fcs/rudder-pos-rad</independentVar>
              <tableData>
                         0.0000000000  0.1745329252  0.3490658504
                -0.3491  0.1904237249  0.1924528268  0.1892048997
                -0.1745  0.1904237249  0.1924528268  0.1892048997
                 0.0000  0.1904237249  0.1924528268  0.1892048997
                 0.1745  0.1941832655  0.1974139496  0.1941832655
                 0.3491  0.1941832655  0.1974139496  0.1941832655
              </tableData>
            </table>
            <value>0</value>
            <table name="aero/table/CL_aos0_aoa0">
              <independentVar lookup="row">fcs/elevator-pos-rad</independentVar>
              <independentVar lookup="column">fcs/rudder-pos-rad</independentVar>
              <tableData>
                         0.0000000000  0.1745329252  0.3490658504
                -0.3491  0.0122966662  0.0113427057  0.0070011182
                -0.1745  0.0122966662  0.0113427057  0.0070011182
                 0.0000  0.0122966662  0.0113427057  0.0070011182
                 0.1745  0.0191698934  0.0140192208  0.0191698934
                 0.3491  0.0191698934  0.0140192208  0.0191698934
              </tableData>
            </table>
            <value>0.06981317007977318</value>
            <table name="aero/table/CL_aos0_aoa4">
              <independentVar lookup="row">fcs/elevator-pos-rad</independentVar>
              <independentVar lookup="column">fcs/rudder-pos-rad</independentVar>
              <tableData>
                         0.0000000000  0.1745329252  0.3490658504
                -0.3491 -0.1634988660 -0.1652509383 -0.1697671105
                -0.1745 -0.1634988660 -0.1652509383 -0.1697671105
                 0.0000 -0.1634988660 -0.1652509383 -0.1697671105
                 0.1745 -0.1599945592 -0.1642176505 -0.1599945592
                 0.3491 -0.1599945592 -0.1642176505 -0.1599945592
              </tableData>
            </table>
          </interpolate1d>
          <value>0.17453292519943295</value>
          <interpolate1d>
            <property>aero/alpha-rad</property>
            <value>-0.06981317007977318</value>
            <table name="aero/table/CL_aos10_aoa-4">
              <independentVar lookup="row">fcs/elevator-pos-rad</independentVar>
              <independentVar lookup="column">fcs/rudder-pos-rad</independentVar>
              <tableData>
                         0.0000000000  0.1745329252  0.3490658504
                -0.3491  0.1941832655  0.1974139496  0.1941832655
                -0.1745  0.1941832655  0.1974139496  0.1941832655
                 0.0000  0.1941832655  0.1974139496  0.1941832655
                 0.1745  0.1941832655  0.1974139496  0.1941832655
                 0.3491  0.1941832655  0.1974139496  0.1941832655
              </tableData>
            </table>
            <value>0</value>
            <table name="aero/table/CL_aos10_aoa0">
              <independentVar lookup="row">fcs/elevator-pos-rad</independentVar>
              <independentVar lookup="column">fcs/rudder-pos-rad</independentVar>
              <tableData>
                         0.0000000000  0.1745329252  0.3490658504
                -0.3491  0.0191698934  0.0140192208  0.0191698934
                -0.1745  0.0191698934  0.0140192208  0.0191698934
                 0.0000  0.0191698934  0.0140192208  0.0191698934
                 0.1745  0.0191698934  0.0140192208  0.0191698934
                 0.3491  0.0191698934  0.0140192208  0.0191698934
              </tableData>
            </table>
            <value>0.06981317007977318</value>
            <table name="aero/table/CL_aos10_aoa4">
              <independentVar lookup="row">fcs/elevator-pos-rad</independentVar>
              <independentVar lookup="column">fcs/rudder-pos-rad</independentVar>
              <tableData>
                         0.0000000000  0.1745329252  0.3490658504
                -0.3491 -0.1599945592 -0.1642176505 -0.1599945592
                -0.1745 -0.1599945592 -0.1642176505 -0.1599945592
                 0.0000 -0.1599945592 -0.1642176505 -0.1599945592
                 0.1745 -0.1599945592 -0.1642176505 -0.1599945592
                 0.3491 -0.1599945592 -0.1642176505 -0.1599945592
              </tableData>
            </table>
            <value>0.13962634015954636</value>
            <table name="aero/table/CL_aos10_aoa8">
              <independentVar lookup="row">fcs/elevator-pos-rad</independentVar>
              <independentVar lookup="column">fcs/rudder-pos-rad</independentVar>
              <tableData>
                         0.0000000000  0.1745329252  0.3490658504
                -0.3491 -0.3507050218 -0.3397064550 -0.3441705437
                -0.1745 -0.3507050218 -0.3397064550 -0.3441705437
                 0.0000 -0.3507050218 -0.3397064550 -0.3441705437
                 0.1745 -0.3507050218 -0.3414932873 -0.3507050218
                 0.3491 -0.3507050218 -0.3414932873 -0.3507050218
              </tableData>
            </table>
            <value>0.20943951023931956</value>
            <table name="aero/table/CL_aos10_aoa12">
              <independentVar lookup="row">fcs/elevator-pos-rad</independentVar>
              <independentVar lookup="column">fcs/rudder-pos-rad</independentVar>
              <tableData>
                         0.0000000000  0.1745329252  0.3490658504
                -0.3491 -0.5494569256 -0.5079927118 -0.4597214528
                -0.1745 -0.5494569256 -0.5079927118 -0.4597214528
                 0.0000 -0.5494569256 -0.5079927118 -0.4597214528
                 0.1745 -0.5494569256 -0.5101388931 -0.5494569256
                 0.3491 -0.5494569256 -0.5101388931 -0.5494569256
              </tableData>
            </table>
          </interpolate1d>
          <value>0.3490658503988659</value>
          <interpolate1d>
            <property>aero/alpha-rad</property>
            <value>-0.06981317007977318</value>
            <table name="aero/table/CL_aos20_aoa-4">
              <independentVar lookup="row">fcs/elevator-pos-rad</independentVar>
              <independentVar lookup="column">fcs/rudder-pos-rad</independentVar>
              <tableData>
                         0.0000000000  0.1745329252  0.3490658504
                -0.3491  0.3538699263  0.3754433011  0.4255063451
                -0.1745  0.3538699263  0.3754433011  0.4255063451
                 0.0000  0.3538699263  0.3754433011  0.4255063451
                 0.1745  0.3538699263  0.3754433011  0.4255063451
                 0.3491  0.3538699263  0.3754433011  0.4255063451
              </tableData>
            </table>
            <value>0</value>
            <table name="aero/table/CL_aos20_aoa0">
              <independentVar lookup="row">fcs/elevator-pos-rad</independentVar>
              <independentVar lookup="column">fcs/rudder-pos-rad</independentVar>
              <tableData>
                         0.0000000000  0.1745329252  0.3490658504
                -0.3491  0.1758219741  0.1924439093  0.2400010318
                -0.1745  0.1758219741  0.1924439093  0.2400010318
                 0.0000  0.1758219741  0.1924439093  0.2400010318
                 0.1745  0.1758219741  0.1924439093  0.2400010318
                 0.3491  0.1758219741  0.1924439093  0.2400010318
              </tableData>
            </table>
            <value>0.06981317007977318</value>
            <table name="aero/table/CL_aos20_aoa4">
              <independentVar lookup="row">fcs/elevator-pos-rad</independentVar>
              <independentVar lookup="column">fcs/rudder-pos-rad</independentVar>
              <tableData>
                         0.0000000000  0.1745329252  0.3490658504
                -0.3491 -0.0104985285  0.0083599241  0.0597596340
                -0.1745 -0.0104985285  0.0083599241  0.0597596340
                 0.0000 -0.0104985285  0.0083599241  0.0597596340
                 0.1745 -0.0104985285  0.0083599241  0.0597596340
                 0.3491 -0.0104985285  0.0083599241  0.0597596340
              </tableData>
            </table>
            <value>0.13962634015954636</value>
            <table name="aero/table/CL_aos20_aoa8">
              <independentVar lookup="row">fcs/elevator-pos-rad</independentVar>
              <independentVar lookup="column">fcs/rudder-pos-rad</independentVar>
              <tableData>
                         0.0000000000  0.1745329252  0.3490658504
                -0.3491 -0.2124093169 -0.1853586857 -0.1301135914
                -0.1745 -0.2124093169 -0.1853586857 -0.1301135914
                 0.0000 -0.2124093169 -0.1853586857 -0.1301135914
                 0.1745 -0.2124093169 -0.1853586857 -0.1301135914
                 0.3491 -0.2124093169 -0.1853586857 -0.1301135914
              </tableData>
            </table>
            <value>0.20943951023931956</value>
            <table name="aero/table/CL_aos20_aoa12">
              <independentVar lookup="row">fcs/elevator-pos-rad</independentVar>
              <independentVar lookup="column">fcs/rudder-pos-rad</independentVar>
              <tableData>
                         0.0000000000  0.1745329252  0.3490658504
                -0.3491 -0.4407664491 -0.3964551189 -0.3489947922
                -0.1745 -0.4407664491 -0.3964551189 -0.3489947922
                 0.0000 -0.4407664491 -0.3964551189 -0.3489947922
                 0.1745 -0.4407664491 -0.3964551189 -0.3489947922
                 0.3491 -0.4407664491 -0.3964551189 -0.3489947922
              </tableData>
            </table>
          </interpolate1d>
        </interpolate1d>
      </function>

To resolve this, I am planning on creating a nxm matrix where n is the number of dimensions I am need to interpolate from and m is the number of data points I have. This would be in place of the table. Technically, I could only store n-1 dimensions in the matrix since I am planning on having the last row be the coefficient value. Then, I'll created a new function interpolateNd that can interpolate between the vectors in the matrix.

Any thoughts on a better implementation?

@Octal450
Copy link

Maybe I am missing something, but why not use the "table" lookup and breakPoint="" to create a 3D table rather than using interpolate1d?

Kind Regards,
Josh

@TrentConley
Copy link
Author

It's fine to create a 3D table. But let's say you have aerodynamic data across 7 control surfaces, now you need at least 7 dimensional data. Currently, JSBSim can't handle that to my understanding. I made a modification to a fork of JSBSim, and I could bring that into main as well. Check out this PR that introduced it:
machindustries#2

@Octal450
Copy link

I see,
interesting.

Kind Regards,
Josh

@Octal450
Copy link

Took a quick look.

I REALLY like this. Would be awesome to see this move into JSB/FlightGear. I could definitely make use of this in my flight models.

Kind Regards,
Josh

@TrentConley
Copy link
Author

Cool! I'll work on integrating it into JSBSim then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants