Howto:Implement a catapult

From FlightGear wiki
Jump to navigation Jump to search

Aircraft with weak engines, especially small aircraft like UAVs, are often launched with a catapult. Implementing such catapults in FlightGear is a fairly trivial job.

The examples on this page are based on the Gatewing X100.

JSBSim

Add the following code to your FDM, inside the <fdm_config> part:

    <external_reactions>
        <force name="catapult" frame="BODY">
            <location unit="M">
                    <x> 0 </x>
                    <y> 0 </y>
                    <z> 0 </z>
            </location>
            <direction>
                <x>1</x>
                <y>0</y>
                <z>0</z>
            </direction>
        </force>
    </external_reactions>
  • Location: at which the force applies. In other words, the place where the catapult is attached to the aircraft.
  • Direction: in which the force is exerted. Usually this is just forwards (positive X) and possibly slightly upwards (positive Z).

To launch the aircraft, the catapult should exert a certain force. This force should be put in the /fdm/jsbsim/external_reactions/catapult/magnitude property (depends on the name of the force, as specified in the FDM). We can use a little nasal script for this:

if (getprop("/fdm/jsbsim/gear/unit/wow")) {
	# catapult force in pounds
	var magnitude = 150;

	var launchRunning = 1;
	var launch = func {
		if (launchRunning) {
			if (magnitude == 0){
				launchRunning = 0;
			}
			setprop("/fdm/jsbsim/external_reactions/catapult/magnitude",magnitude);
			magnitude = 0;

			# time on catapult: 1/10 = 0.1 second
			settimer(launch, 0.1);
		}
	}
	launch();
}
else {
	setprop("/sim/screen/red","Unable to catapult, the aircraft is already airborn.");
}