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 Simulink Function #1010

Open
kvgkrish opened this issue Jan 8, 2024 · 36 comments
Open

JSBSim Simulink Function #1010

kvgkrish opened this issue Jan 8, 2024 · 36 comments
Labels
MATLAB Topics linked to the MATLAB S-Function

Comments

@kvgkrish
Copy link

kvgkrish commented Jan 8, 2024

Hi all,
This is Gokul doing a Master of Aerospace Engineering at TUM Germany. Currently working on master thesis at Chalmers University of Technology.
I am working on a Bio-Inspired UAV dynamics system. I am new to JSBSIM and I have set up all the files and worked fine with available flights and scripts. If I use a new flight configuration I have simulated the model. It shows trim failure and sometimes flight scripts are not used.
Can you help me to resolve this issue?

Skärmbild 2024-01-08 114801

Skärmbild 2024-01-08 114659

@seanmcleod
Copy link
Member

Are you sure the aircraft should be trimmable at the initial conditions you're specifying for the trim? Or there could be an issue with the FDM file you've created.

If you share the FDM file and the conditions you're using for trim others could potentially take a look and help.

@kvgkrish
Copy link
Author

kvgkrish commented Jan 8, 2024

I have attached the flight data, script, and initial conditon for your reference.

aircraft is StratoSurfer, Scipts/Test_StratoSurfer_Cruise, and the Initial condition is initCruise.

https://github.com/UASLab/OpenFlightSim/blob/master/Simulation/aircraft/StratoSurfer/StratoSurfer.xml

@seanmcleod
Copy link
Member

Just had a very quick glance. Is the engine definitely on and running? I see the throttle being advanced, but it's not 100% clear that the engine is running.

What is the output in terms of thrust and power and h-agl-ft below?

    <event name="Trim">
      <condition> simulation/frame gt 1 </condition>
      <set name="simulation/do_simple_trim" value="1"/>
      <notify>
        <property>velocities/vtrue-kts</property>
        <property>position/h-agl-ft</property>
        <property>aero/alpha-deg </property>
        <property>aero/beta-deg </property>
        <property>propulsion/engine[0]/thrust-lbs</property>
        <property>propulsion/engine[0]/power-hp</property>
        <property>attitude/phi-rad</property>
        <property>attitude/theta-rad</property>
        <property>attitude/psi-rad</property>
      </notify>
    </event>

@kvgkrish
Copy link
Author

kvgkrish commented Jan 9, 2024

image
image
image

I have attached the engine power and new script for your review.
Even after this modification, model has failed du to trim error.

@seanmcleod
Copy link
Member

The trim routine will adjust the throttle while trying to calculate a trim solution. So it doesn't matter what you set the throttle position to.

But as I mentioned, I'm not sure that the engine is on/running, in which case it doesn't matter what the trim routine does in terms of setting the throttle command, if the engine isn't on it will produce 0 thrust.

Look at the output you produced just above, it shows the thrust as being 0.

@kvgkrish
Copy link
Author

kvgkrish commented Jan 9, 2024

Thanks for the response. How do you make sure the engine is on or not?
I faced this issue while editing the aircraft file and getting this error.

@seanmcleod
Copy link
Member

Take a look at this example of using the <running> element.

<running> -1 </running>

The -1 means all engines that the aircraft has.

@kvgkrish
Copy link
Author

kvgkrish commented Jan 9, 2024

image
Now I am getting Very high thrust and again trim failure.

@seanmcleod
Copy link
Member

Well then there is something wrong with your engine, thruster model etc. With that sort of maximum thrust and a vehicle with a mass of only 3lbf, the trim routine probably can't find a small enough throttle command like 0.000001 to us to get a trim solution.

@kvgkrish
Copy link
Author

kvgkrish commented Jan 9, 2024

image
image

I have reduced the command, but it is still getting very high value.

@seanmcleod
Copy link
Member

No, no, no.... As I mentioned, the trim routine will try different throttle commands when trying to calculate a trim solution, so it doesn't matter what you set the throttle command to in the Motor Start event!

The point is it appears the engine power is way too high for this sort of vehicle. And the trim routine has probably some minimum throttle increment that it tries when trying to find a solution which is way too much in terms of thrust.

Think about it in terms of a rough sanity check, should a 3lbf vehicle have a motor of 350W, producing some enormous amount of thrust?

@kvgkrish
Copy link
Author

kvgkrish commented Jan 9, 2024

image
It is a very small motor. I have attached the details of it.

@seanmcleod
Copy link
Member

Compare the amount of thrust you're seeing to the thrust measured for this engine for different propellers etc.

https://www.innov8tivedesigns.com/images/specs/Cobra_2217-8_Specs.htm

@kvgkrish
Copy link
Author

kvgkrish commented Jan 9, 2024

Yes, it is very high compared to the tabulated value.
How to resolve this issue.

@seanmcleod
Copy link
Member

Step through the JSBSim code where it calculates the thrust and see if you spot what input is making it so large.

@kvgkrish
Copy link
Author

kvgkrish commented Jan 9, 2024

But the 737 and c172x are working fine with the Simulink.

@kvgkrish
Copy link
Author

kvgkrish commented Jan 9, 2024

The aircraft file, script, and initial condition we use are created for the FlightGear module. Is there any problem with Simulink? Can we please tell me how to run JSBSim standalone and visualize the results in FG.

@seanmcleod
Copy link
Member

So run JSBSim stand-alone with your script, look at the command line arguments for JSBSim and see if there is any difference with the trim stand-alone versus with Simulink.

@kvgkrish
Copy link
Author

How to run JSBSim stand-alone I tried but the application now opening. Can you please send me some documentation for that?

@seanmcleod
Copy link
Member

Did you look at the Quick Start section of the README? https://github.com/JSBSim-Team/jsbsim?tab=readme-ov-file#quick-start

@kvgkrish
Copy link
Author

image
I am getting this error.

@seanmcleod
Copy link
Member

@seanmcleod
Copy link
Member

Did you download JSBSim.exe from the web, or did you clone the repo and build it yourself? If downloaded from the web take a look at the Properties and check the Unblock checkbox if it's there, it is by default for any files downloaded from the internet.

image

@kvgkrish
Copy link
Author

image
I have downloaded from the web

@kvgkrish
Copy link
Author

I have corrected the model. Working on the controls, here I want to change the control based on the altitude to demonstrate the dynamic soring "S" patter.
Can you help me write control logic for dynamic soaring?

@kvgkrish
Copy link
Author

@seanmcleod
Hi,
I want to input the altitude setpoint as input to the S function. But the S function won't take it when its fed through input. I have modified the input output XML file.
It only considers when I fed through script files. Can you please help me resolve this issue.
image
image

@seanmcleod
Copy link
Member

Do you see any error message when the input properties are processed?

// Add input properties JSBSim should take in.
int i;
std::string prop;
Element* inputElement = document->FindElement("input");
Element* propElement = inputElement->FindElement("property");
for (i = 0; i < inputSize; i++) {
prop = propElement->GetDataLine();
if (!JII->AddInputPropertyNode(prop)) {
ssSetErrorStatus(S, "Could not add property from XML file to input port.\n"
"HINT: You can only use properties that exist and that are WRITE-only for this port.\n");
return;
}
propElement = inputElement->FindNextElement("property");
}

@kvgkrish
Copy link
Author

Hi,
I haven´t get any errors but I cant use that as a input.

@seanmcleod
Copy link
Member

So in what way can't you use it?

@kvgkrish
Copy link
Author

The figure below is for the desired altitude and headings function.
image

I want to feed the autopilot to follow the desired trajectory. I have created a function for the desired altitude and desired heading angle with respect to time. I want to feed as an input to the autopilot. If sending this comment through input, the model doesnt't follow the desired altitude.
If I write this desired altitude and heading in the script file as a piecewise input, the model won't take it as an input.
The figure below is a script with a piecewise function. If I go with the below script, it crashes the model.
image

@seanmcleod
Copy link
Member

Rather than posting screenshots of your XML etc. rather put them in a triple back tick ` block with xml as the type. Means they're easier for other users to find via a search in future etc.

In terms of running this in Simulink, are you sure you have enabled the auto-pilot? Most auto-pilot implementations have a separate property that you have to set to enable them. So maybe you're updating the altitude and heading setpoints, but if the autopilot isn't enabled then the autopilot will ignore the setpoints.

For your script example, it looks to me like you haven't set the Desired Flight Path event to be executed more than once. Also the same comment applies to the script case, make sure the autopilot is enabled.

@kvgkrish
Copy link
Author

  <use aircraft="GBSv02" initialize="ini03"/>
	<run start="0.0" end="1000" dt="0.008333333333333333333">



		<event name="Wind aloft">
			<condition>simulation/sim-time-sec  ge  0.01</condition>
			<set name="atmosphere/psiw-rad" value="1.57" />

			<set name="atmosphere/wind-mag-fps">
				<description>Change_of_wind_magnitute_wrt_altitute</description>
				<function>
					<table>
						<independentVar lookup="row">position/h-agl-ft</independentVar>
						<tableData>
							5		16.93490625
							10		18.40375301
							15		19.32134464
							20		20
							25		20.54277915
							30		20.99717881
							35		21.38920099
							40		21.73469725
							45		22.04407591
							50		22.32455428
							55		22.58135087
							60		22.81836623
							65		23.03859546
							70		23.2443904
							75		23.43763291
							80		23.61985323
							85		23.79231315
							90		23.9560658
							95		24.11199966
							100		24.26087142
							1000.0  20.9000
							2000.0  19.8000
							2500.0  18.9000
							3000.0  20.0000
							3500.0  20.0000
						</tableData>
					</table>
				</function>
			</set>
			<!--set name="atmosphere/psiw-rad" value="0" /-->
			<!--set name="atmosphere/wind-mag-fps" value="0" /-->
			<!--set name="atmosphere/wind-down-fps" action="FG_RAMP" value="1" tc="10.0"/-->
		</event>


		<event name="Desired Flight Path">
			<!-->condition> position/h-agl-ft ge 600 </condition-->
			<condition> simulation/sim-time-sec ge 0.1 </condition>

			<set name="ap/altitude_hold" value="1.0" />
			<set name="ap/heading_hold" value="1.0" />
			</event>

		
  </run>

</runscript>

I have enabled the autopilot for altitude hold and heading hold.

<s_function_config>
    <input>
        <property> fcs/throttle-cmd-norm[0] </property>
        <property> fcs/aileron-cmd-norm </property>
        <property> fcs/elevator-cmd-norm </property>
        <property> fcs/rudder-cmd-norm </property>
		<property>ap/altitude_setpoint</property>
		<property>ap/heading_setpoint</property>
		
    </input> 

I have included the autopilot setpoint as an input for the S-Function.
image
The model works well for altitude hold, but if I enable the heading, it oscillates around the x-axis.

@seanmcleod
Copy link
Member

The model works well for altitude hold, but if I enable the heading, it oscillates around the x-axis.

Then you'll need to look at improving the heading controller.

@kvgkrish
Copy link
Author

kvgkrish commented Feb 1, 2024

In the initial stages of the simulation, a predefined crosswind, characterized by a specified magnitude and direction, is introduced to the model. The simulation accurately captures the model's initial response, manifesting in dynamic changes to its trajectory and behavior. However, as the simulation progresses, a noticeable reduction in the visual impact of the crosswind becomes evident. This observation indicates a diminishing influence over time.
To address this, I am looking to incorporate a windshear model into the simulation. I have already introduced values representing wind velocity with respect to altitude. However, the current model generates same responses for all directions. I am seeking guidance on how to effectively implement the windshear phenomenon into the atmospheric conditions of the simulation.

<?xml version="1.0"?>
<initialize name="reset03">

  <vc unit="KTS"> 38.87689112646 </vc>
  <longitude unit="DEG"> 0  </longitude>
  <latitude unit="DEG">   0  </latitude>
  <phi unit="DEG">         0.0  </phi> <!-- Roll -->
  <theta unit="DEG">       0.0  </theta> <!-- Pitch -->
  <psi unit="DEG">       0.0  </psi> <!-- Yaw -->
  <altitude unit="FT">     100  </altitude>
	<winddir unit="DEG">   90.0  </winddir> 
  <hwind unit="FT/SEC"> 20 </hwind>
	
</initialize>
<event name="Wind aloft">
	<condition>simulation/sim-time-sec  ge  0.01</condition>
	<set name="atmosphere/psiw-rad" value="1.57" />

	<set name="atmosphere/wind-mag-fps">
		<description>Change_of_wind_magnitute_wrt_altitute</description>
		<function>
			<table>
				<independentVar lookup="row">position/h-agl-ft</independentVar>
				<tableData>
					5		16.93490625
					10		18.40375301
					15		19.32134464
					20		20
					25		20.54277915
					30		20.99717881
					35		21.38920099
					40		21.73469725
					45		22.04407591
					50		22.32455428
					55		22.58135087
					60		22.81836623
					65		23.03859546
					70		23.2443904
					75		23.43763291
					80		23.61985323
					85		23.79231315
					90		23.9560658
					95		24.11199966
					100		24.26087142
					1000.0  20.9000
					2000.0  19.8000
					2500.0  18.9000
					3000.0  20.0000
					3500.0  20.0000
				</tableData>
			</table>
		</function>
	</set>
	<!--set name="atmosphere/psiw-rad" value="0" /-->
	<!--set name="atmosphere/wind-mag-fps" value="0" /-->
	<!--set name="atmosphere/wind-down-fps" action="FG_RAMP" value="1" tc="10.0"/-->
</event>

@bcoconni bcoconni added the MATLAB Topics linked to the MATLAB S-Function label Feb 10, 2024
@agodemar
Copy link
Contributor

agodemar commented Feb 19, 2024

@kvgkrish did you progress in your study on this topic?
Updates to the community are welcomed

@kvgkrish
Copy link
Author

@agodemar yes, still working on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MATLAB Topics linked to the MATLAB S-Function
Projects
None yet
Development

No branches or pull requests

4 participants