AI Scenarios: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
(Created page with "AI scenarios are very simple. Simply tie a flightplan to a model, and you have a scenario. Below, I'm going to go explain exactly how this is done. == Flightplans and Their Wa...")
 
Line 23: Line 23:
Next, you need to create the scenario XML file.  For the example, I will simply borrow an existing one, and make modifications to it.  I’ll choose aircraft_demo.xml.  As you will see, you need PropertyList and scenario tags.  A description is optional, but recommended.  Then, there’s an entry for a model.  It starts with an entry tag.  Then, it’s given a callsign.  The type is aircraft.  There are different types you can specify for different kinds of scenarios; however, we’re just going to focus on the aircraft type.  There are various classes as well.  This one is set to jet transport.  I think there’s a light class as well, but they all seem to behave the same to me.  If someone else, more knowledgeable in this area could clarify things that would be helpful.  Next is the model.  Just set the path to the aircraft of your choice.  It’s recommended that you use a low-poly aircraft from the AI directory, but a regular aircraft works fine as well.  After that is the flightplan parameter.  Simply set the path to your flightplan.  Finally, there is an option to set your scenario to either simply terminate or repeat once completed.  Enter a 1 for repeat, a 0 for no repeat.  Remember to add all your end-tags when you have finished, and save it with a name other than the one you modified (if you chose to modify an existing scenario).
Next, you need to create the scenario XML file.  For the example, I will simply borrow an existing one, and make modifications to it.  I’ll choose aircraft_demo.xml.  As you will see, you need PropertyList and scenario tags.  A description is optional, but recommended.  Then, there’s an entry for a model.  It starts with an entry tag.  Then, it’s given a callsign.  The type is aircraft.  There are different types you can specify for different kinds of scenarios; however, we’re just going to focus on the aircraft type.  There are various classes as well.  This one is set to jet transport.  I think there’s a light class as well, but they all seem to behave the same to me.  If someone else, more knowledgeable in this area could clarify things that would be helpful.  Next is the model.  Just set the path to the aircraft of your choice.  It’s recommended that you use a low-poly aircraft from the AI directory, but a regular aircraft works fine as well.  After that is the flightplan parameter.  Simply set the path to your flightplan.  Finally, there is an option to set your scenario to either simply terminate or repeat once completed.  Enter a 1 for repeat, a 0 for no repeat.  Remember to add all your end-tags when you have finished, and save it with a name other than the one you modified (if you chose to modify an existing scenario).
==Special Tools ==
==Special Tools ==
There are two great tools for making flight plans.  You can use Oscar’s Flightplan Generator or redneck’s Flightplan Generator.  They work very differently, but can be used together to further enhance your AI scenarios.  Oscar’s Flightplan Generator uses a Google Maps interface in which you simply click on the location you want to place a waypoint at, and enter the rest of the data (speed, altitude, on-ground, etc.).  redneck’s Flightplan Generator is a custom FlightGear logger.  Simply start FG with the logger, using the --generic=file,out,0.1,path/to/flightplan/file,dgrecord2 command.  This won’t work in FGRun’s interface, so just tack it on to the executable line, being sure to add a space between the executable and the command.  Then, just fly the flight you want the AI aircraft to fly.  Once finished, close FG, and check the flightplan file.  You will find your once blank file is suddenly filled with all the necessary data, plus some useless data points.  You will need to trim off the waypoints with KTAS < 10 so that your AI model can get off the ground in some reasonable amount of time. Both tools can be found at the Official FlightGear Forum.
There are two great tools for making flight plans.  You can use Oscar’s Flightplan Generator or redneck’s Flightplan Generator.  They work very differently, but can be used together to further enhance your AI scenarios.  Oscar’s Flightplan Generator uses a Google Maps interface in which you simply click on the location you want to place a waypoint at, and enter the rest of the data (speed, altitude, on-ground, etc.).  redneck’s Flightplan Generator is a custom FlightGear logger.  Simply start FG with the logger, using the --generic=file,out,0.1,path/to/flightplan/file,dgrecord2 command.  If you have named the logger something other than dgrecord2, then subsitute the actual name for dgrecord2.  This won’t work in FGRun’s interface, so just tack it on to the executable line, being sure to add a space between the executable and the command.  Then, just fly the flight you want the AI aircraft to fly.  Once finished, close FG, and check the flightplan file.  You will find your once blank file is suddenly filled with all the necessary data, plus some useless data points.  You will need to trim off the waypoints with KTAS < 10 so that your AI model can get off the ground in some reasonable amount of time. Both tools can be found at the Official FlightGear Forum.
 
==Common Issues ==
==Common Issues ==
I believe I have created the flightplan correctly, yet, when I run the scenario, the plane doesn’t follow the route as expected.
I believe I have created the flightplan correctly, yet, when I run the scenario, the plane doesn’t follow the route as expected.

Revision as of 19:03, 3 October 2011

AI scenarios are very simple. Simply tie a flightplan to a model, and you have a scenario. Below, I'm going to go explain exactly how this is done.

Flightplans and Their Waypoints

Flightplans have a basic structure that you must adhere to in order to create one successfully. They are in XML, and consist of several waypoints. So, you have the XML header at the top followed by a PropertyList tag and a flightplan tag, followed by a series of waypoints, a final waypoint with no coordinates, called EOF (end of flight), and the end tags for PropertyList and flightplan.

Each waypoint has eight parameters. They tend to be written in the following order: name, lat, lon, alt, ktas, on-ground, gear-down, flaps-down. All waypoints, except EOF, must have these, or the scenario may behave unpredictably. Furthermore, all waypoints are tagged with a wpt tag. Now, to go through the different parameters.

name: can consist of anything. If you want to use a word or a number, it doesn't matter so long as the characters in it are allowed in XML. lat: the model's latitude at the waypoint. lon: the model's longitude at the waypoint. alt: the model's altitude. ktas: Knots True AirSpeed of the model. on-ground: a boolean value expressed as an integer value of either 1 or 0. gear-down: a boolean value expressed as an integer value of either 1 or 0. flaps-down: a float value expressed a value between 0 and 1. on-ground need not necessarily be placed correctly. In the example, you will see that, for all waypoints, this value is set to zero. You may want to play around with this one. If you set it to 1 too early (for a landing), the aircraft will be thrust onto the ground sharply. If you set it late, then things should be okay. Or, it may appear to hover if you’ve set the altitude a bit high.


SFOBridges1.pngSFOBridges2.png

Once completed, be sure to save as an XML file in the AI/flightplans directory.

Tying Things Together

Next, you need to create the scenario XML file. For the example, I will simply borrow an existing one, and make modifications to it. I’ll choose aircraft_demo.xml. As you will see, you need PropertyList and scenario tags. A description is optional, but recommended. Then, there’s an entry for a model. It starts with an entry tag. Then, it’s given a callsign. The type is aircraft. There are different types you can specify for different kinds of scenarios; however, we’re just going to focus on the aircraft type. There are various classes as well. This one is set to jet transport. I think there’s a light class as well, but they all seem to behave the same to me. If someone else, more knowledgeable in this area could clarify things that would be helpful. Next is the model. Just set the path to the aircraft of your choice. It’s recommended that you use a low-poly aircraft from the AI directory, but a regular aircraft works fine as well. After that is the flightplan parameter. Simply set the path to your flightplan. Finally, there is an option to set your scenario to either simply terminate or repeat once completed. Enter a 1 for repeat, a 0 for no repeat. Remember to add all your end-tags when you have finished, and save it with a name other than the one you modified (if you chose to modify an existing scenario).

Special Tools

There are two great tools for making flight plans. You can use Oscar’s Flightplan Generator or redneck’s Flightplan Generator. They work very differently, but can be used together to further enhance your AI scenarios. Oscar’s Flightplan Generator uses a Google Maps interface in which you simply click on the location you want to place a waypoint at, and enter the rest of the data (speed, altitude, on-ground, etc.). redneck’s Flightplan Generator is a custom FlightGear logger. Simply start FG with the logger, using the --generic=file,out,0.1,path/to/flightplan/file,dgrecord2 command. If you have named the logger something other than dgrecord2, then subsitute the actual name for dgrecord2. This won’t work in FGRun’s interface, so just tack it on to the executable line, being sure to add a space between the executable and the command. Then, just fly the flight you want the AI aircraft to fly. Once finished, close FG, and check the flightplan file. You will find your once blank file is suddenly filled with all the necessary data, plus some useless data points. You will need to trim off the waypoints with KTAS < 10 so that your AI model can get off the ground in some reasonable amount of time. Both tools can be found at the Official FlightGear Forum.

Common Issues

I believe I have created the flightplan correctly, yet, when I run the scenario, the plane doesn’t follow the route as expected. There are a few possible reasons for this.

1. AI scenarios are flown with turn anticipation. Therefore, the aircraft will rarely fly all the way to the waypoint, especially if it’s at a turning point. You may want to adjust for this by setting the entry point of the turn a little late. You can do this by changing the coordinates of the problem waypoint.

2. Is your plane doing flat loops? Perhaps you have set your waypoints too close together. The AI aircraft in the scenario always goes from the first waypoint to the next nearest waypoint, regardless of what order you put your waypoints in. Therefore, it’s important that you avoid making circles or any kind of flight that starts and ends at roughly the same location.

3. Another possibility is that you are expecting the aircraft to turn tighter than the AI scenario will allow it to turn. Write your flightplans to use gentle turns to correct this, or a slower speed.