Replies: 25 comments 11 replies
-
@rishi1906 the In FGTrimAnalysis.cpp at line 335, there's a mismatch of types. you should modify |
Beta Was this translation helpful? Give feedback.
-
Thanks for the response. I anticipated the same, sure will fix the code according to the latest release of JSBSim, and yes I am comfortable with the programming environment. |
Beta Was this translation helpful? Give feedback.
-
@rishi1906 are you planning on making use of JSBSim within a Matlab/Simulink environment via the S-Function interface, or are you planning on using JSBSim stand alone outside of a Matlab/Simulink environment? |
Beta Was this translation helpful? Give feedback.
-
Sir, I have started resolving the issues, I think I will be able to update them as mostly its conversion from string to SGPath and some updated Set and Get functions in addition to updating to shared_pointers as you rightly suggested. Regarding, fmincon I suppose that's part of MATLAB environment. I am a core C++ guy. @seanmcleod I am using JSBSim with Ardupilot SITL, so its outside MATLAB as I need to attach it with Software in the loop simulation and open source Optimizer routine. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the additional context. Out of interest is the current trim implementation in JSBSim not sufficient for what you need?
Yes, it's part of Matlab. I guess since you mentioned @agodemar's paper - "A Deep Reinforcement Learning Control Approach for High-Performance Aircraft" which made use of Matlab/Simulink he possibly assumed you were also planning on using Matlab/Simulink. |
Beta Was this translation helpful? Give feedback.
-
I debugged the current trim implementation in JSBSim, which uses a pairwise (state and control) method that does down the lane bisection method to update the guess, I am not fully sure why I am getting wdot not trimmable error for a custom aircraft I want to simulate in SITL. Work done by Professor @agodemar for general trim looks more promising for that matter. I am hoping it will resolve wdot no trimmable error. The current trim solution in JSBSim, only solves for three states for example Ground Trim, but I guess all states should be trimmed according to the flight envelope as done @agodemar. I am surprised why current trim method has not been updated since 1999. |
Beta Was this translation helpful? Give feedback.
-
Sure, I will share the updated code. Yes, I have forked working with local files. I will need your help with the code you wrote. |
Beta Was this translation helpful? Give feedback.
-
That's why I was asking whether it wasn't sufficient for your needs, given it appears to have been for 90% of JSBSim users for the last 24 years 😉 If you can share your custom aircraft I could take a look and see if I can see what the trim issue is. |
Beta Was this translation helpful? Give feedback.
-
@seanmcleod that would be great! Till I get correct stability derivatives for modified Talon (referred to as custom aircraft), could you check the attached XML file of X8 RC UAV. Please find attached initial condition file. I have taken this XML file from github just to test it with JSBSim. For full trim I get following output Full Trim Trim failed I tried to trim it (in MATLAB) for level flight and got these values AoA Elevator_deflection V_inf Thrust
Note : I have been working on JSBSim since last 1 month only, kindly ignore if I don't know some obvious things. |
Beta Was this translation helpful? Give feedback.
-
You didn't supply the engine file. Propulsion:
No filename given.
In file ../aircraft/x8/x8.xml: line 79
Could not open file: electric800W.xml
Aircraft propulsion element has problems in file Path "../aircraft/x8/x8.xml" Is it identical to the existing electric engine files in JSBSim, just with the power set to 800W? In your Matlab examples above, are all of the entries valid trim points? What is Also the units for the |
Beta Was this translation helpful? Give feedback.
-
Oh yes it's a simple JSBSim electric engine file.
Yes, all are valid trim points.
|
Beta Was this translation helpful? Give feedback.
-
Ah, so you're not actually getting Matlab to come up with a trim solution, you've come up with a calculation to for a given AoA work out the elevator deflection needed to zero out the pitch moment due to You're assuming the MRP (Moment Reference Point) is coincident with the cg, which is the case for this model, although I see a lot of stuff is coincident at One minor thing you haven't taken into account in your calculation is the thrust angle. Currently JSBSim is saying |
Beta Was this translation helpful? Give feedback.
-
Yes it is, but if you're trimming for level flight gamma = 0 and say an AoA of 10 deg, then the pitch attitude, theta = 10 deg nd then the thrust line is oriented at 10 deg now relative to the ground. So some of the thrust vector is now providing a force in the lift direction, so you would need slightly less lift, but also slightly more thrust since the drag is parallel to the flight path etc. A trim solution needs to take this into account. |
Beta Was this translation helpful? Give feedback.
-
One thing I noticed is that the aircraft seems to be very overpowered with an 800W electric engine, so trim wise it's trying to trim around throttle commands on the order of 0.00001. So I dropped the power down to 4W. So now you can see that the trim solution is looking at a throttle command of around 0.23. But still failing. Full Trim
Sorry, qdot doesn't appear to be trimmable
Trim failed
Trim Results:
Angle of Attack: 2.97 wdot: -2.57e-01 Tolerance: 1e-03 Failed
Throttle: 0.23 udot: -7.11e-02 Tolerance: 1e-03 Failed
Pitch Trim: 0.00 qdot: -6.66e-05 Tolerance: 1e-04 Passed
Roll Angle: 0.00 vdot: -3.79e-19 Tolerance: 1e-03 Passed
Ailerons: 0.00 pdot: 0.00e+00 Tolerance: 1e-04 Passed
Rudder: 0.00 rdot: 0.00e+00 Tolerance: 1e-04 Passed I used the following python code to get a feel for what is happening, which is how I noticed how over-powered the aircraft is. You'll see I've used your 3 deg AoA trim point to choose an airspeed and elevator angle, and then run it for 14 time steps to see how much deviation there is. import jsbsim
fdm = jsbsim.FGFDMExec('..\\') # The path supplied to FGFDMExec is the location of the folders "aircraft", "engines" and "systems"
fdm.load_model('x8')
# Set engines running
fdm['propulsion/engine/set-running'] = 1
fdm['ic/h-sl-ft'] = 1
fdm['ic/vc-kts'] = 30.31882
fdm['ic/gamma-deg'] = 0
fdm['ic/alpha-deg'] = 3
fdm['ic/theta-deg'] = 3
fdm['fcs/throttle-cmd-norm'] = 0.225
fdm['fcs/elevator-cmd-norm'] = -0.012810666
fdm.run_ic() # Initialize the aircraft with initial conditions
#fdm['simulation/do_simple_trim'] = 1
elevator_pos = fdm['fcs/elevator-pos-rad']
cm0 = fdm['aero/coefficient/Cmo']
cm_alpha = fdm['aero/coefficient/Cmalpha']
cm_q = fdm['aero/coefficient/Cmq']
cm_de = fdm['aero/coefficient/CmDe']
alpha = fdm['aero/alpha-deg']
for i in range(14):
alpha = fdm['aero/alpha-deg']
gamma = fdm['flight-path/gamma-deg']
cm0 = fdm['aero/coefficient/Cmo']
cm_alpha = fdm['aero/coefficient/Cmalpha']
cm_q = fdm['aero/coefficient/Cmq']
cm_de = fdm['aero/coefficient/CmDe']
M = fdm['moments/m-total-lbsft']
aero_M = fdm['moments/m-aero-lbsft']
propulsion_M = fdm['moments/m-prop-lbsft']
fdm.run()
# Trim
try:
fdm['simulation/do_simple_trim'] = 1
except RuntimeError as e:
# The trim cannot succeed. Just make sure that the raised exception
# is due to the trim failure otherwise rethrow.
if e.args[0] != 'Trim Failed':
raise
print('Done') You can then also take a look at the You'll notice that there is a slight pitch up, a combination I think of slightly too much thrust giving a slight positive climb angle, which decreases AoA slightly, which means Cm-alpha decreases and so Cm_de results in a slight pitch rate etc. |
Beta Was this translation helpful? Give feedback.
-
@seanmcleod sorry for the late reply, yes what you mentioned is correct, it's indeed overpowered. I rechecked the configuration file and found some errors, CG locations, AERORP loc, locations of engine and thruster, and in controls as well some inputs were missing. JSBSim can do full trim successfully for updated configuration wrt the initial conditions provided as a solution from Matlab code.
Even upon getting trimmed, it doesn't maintain level flight in simulation (Flightgear), and altitude keeps dropping. |
Beta Was this translation helpful? Give feedback.
-
Take a look at the last column What does your script/process look like in terms of performing the trim etc.? It looks like the trim routine is figuring out how much thrust is required but then when you continue running the engine isn't running and/or the throttle has been reset to 0. |
Beta Was this translation helpful? Give feedback.
-
When I run the same script with standalone JSBSim code (without SITL) it gives a non-zero Direct Thrust value and maintains the height which indicates the trim is working correctly. But same initial conditions with same configuration file when used in SITL behaves differently, what I has shared before. Any idea regarding Arduplane SITL ? |
Beta Was this translation helpful? Give feedback.
-
Who is controlling the throttle during SITL? Log the throttle command and engine state during SITL. |
Beta Was this translation helpful? Give feedback.
-
Maybe you're getting caught out with ArduPilot's motor arming? |
Beta Was this translation helpful? Give feedback.
-
Yes, I figured it out today, it's due to arming only, as before arming Ardupilot doesn't give control command to JSBSim. It's working now (I had to tune the aircraft though using AutoTune mode in Ardupilot).
But if I change lat long (say KSFO), trim fails. Trim shouldn't fail for different lat, and long, right? |
Beta Was this translation helpful? Give feedback.
-
Welcome to the non-flat world 😉 Graph what the trim routine computes for The trim routine then fails with: rdot doesn't appear to be trimmable I haven't looked in detail, but what I'm guessing is that the increase in aileron deflection is generating a yaw moment which the trim routine can't cancel out with rudder sucessfully. So double-check the lateral and directional stability coefficients are 'correct'. |
Beta Was this translation helpful? Give feedback.
-
Ah, I just took a quick glance at the X8 FDM, and I noticed that there is no yaw channel. So as soon as a yaw moment develops, e.g. due to aileron deflection, then the trim routine can't cancel it out with rudder, because there is no rudder/yaw control! <function name="aero/coefficient/Cnda">
<description>Yaw moment due to aileron</description>
<product>
<property>aero/qbar-area</property>
<property>metrics/bw-ft</property>
<property>fcs/effective-aileron-pos</property>
<value>0.1202</value>
</product>
</function> |
Beta Was this translation helpful? Give feedback.
-
Take a look at the B-2, it uses split elevons/flaperons for yaw control. Or the B-21, comments from Rodney Robles on his LinkedIn post.
Now taking a quick look at the X-8 it looks like it only has two elevons, one on the port side and one on the starboard side. So it would be trickier to balance the pitch, roll and yaw moments required via differential movement. |
Beta Was this translation helpful? Give feedback.
-
@seanmcleod could you guide me in deciding the parameters for the initialization file for the purpose of ground trim?
It gives wdot not trimmable error
Could it be due to AERORP and CG locations ? |
Beta Was this translation helpful? Give feedback.
-
FYI in terms of the trim routine in JSBSim. jsbsim/src/initialization/FGTrim.h Lines 74 to 94 in 5c31c25 Now in terms of ground trim what is going to come into play are the ground reactions, typically between the gear and the ground. Now it looks like there is only as single ground reaction in the X8 at the moment, so maybe it can't balance, and/or the spring effect is too great etc. <ground_reactions>
<contact type="STRUCTURE" name="Belly">
<location unit="IN">
<x> 0.0 </x>
<y> 0.0 </y>
<z> 0.0 </z>
</location>
<static_friction> 1.00 </static_friction>
<dynamic_friction> 1.00 </dynamic_friction>
<spring_coeff unit="LBS/FT"> 10.00 </spring_coeff>
<damping_coeff unit="LBS/FT/SEC"> 10.00 </damping_coeff>
</contact>
</ground_reactions> |
Beta Was this translation helpful? Give feedback.
-
Greeting @agodemar ,
I am new to JSBSim, trying to use the trim solution provided by Dr Agostino De Marco as mentioned in his paper "A General Solution to the Aircraft Trim Problem". When I add the header and source files of FGTrimAnalysis and FGTrimAnalysisControl to CMakeLists.txt under /src/initialization folder to build, it throws several errors of incompatibility (missing/mismatched function).
Among several errors, one error looks like this
../../jsbsim-code/src/initialization/FGTrimAnalysis.cpp:335:20: error: cannot convert ‘std::shared_ptrJSBSim::FGInitialCondition’ to ‘JSBSim::FGInitialCondition*’ in assignment
335 | fgic=fdmex->GetIC();
| ~~~~~~~~~~~~^~
| |
| std::shared_ptrJSBSim::FGInitialCondition
@agodemar Sir, I have been reading and following your papers for quite some time. It's commendable the contribution/efforts made by your lab for the development of JSBSim and appreciate the recent work you have published titled
"A Deep Reinforcement Learning Control Approach for High-Performance Aircraft".
I request you to help me out with the FGTrimAnalysis code and mentioned error.
Beta Was this translation helpful? Give feedback.
All reactions