Board index FlightGear Development AI Traffic

Announcing AI CargoTowing Capability

Intelligent, computer controlled vehicles that drive/fly over the planet!

Announcing AI CargoTowing Capability

Postby wlbragg » Sat Sep 06, 2014 7:45 am

Below is new AI scenario code that will allow any craft to tow AI models. This was my first attempt at nasal beyond the basics so beware it could be a lot more organized, robust and feature rich. I borrowed and modified code from existing FG ideas. Right now all I have is "hard dock". That is cargo that is simulated to be hard docked to the craft or even inside. Where you put the cargo is up to you. The example code I include allows the AirCrane to pickup unlimited cargo containers and move them. They can be dropped from altitude or sat on the deck. I included a key for manual hook, auto hook and release. You must be within an adjustable, user defined range to pick up the cargo. I used the existing submodel ballistics to simulate a drop from altitude.

Future additions and enhancements I plan to complete myself.are:
A few more models including my original concept of bundles of x-mas trees and dump truck scenario.
Suspended cargo by visible rope or cradle. (This is next, I plan to use or borrow the existing towing routines for this)
Some additional physics like simulated weight/drag/force/swing.
Cargo, cradle and rope damage.

Instructions for setting up this scenario are contained in the file CargoContainer.nas.
All the files here https://gitorious.org/ai-cargotow.
Cargo-AI-Scenario_v1.4.zip
Cargo-AI-Scenario_v1.5.zip - 5/2017
Comments for latest version:
GUI add-on appears to be broke at the moment.
I only checked Hard-dock towing.

Really the only instruction for using the scenario are as follows
After putting the files and xml code where indicated in CargoContainer.nas, choose the scenario KEQA_CargoContainer from Scenarios.
Hover as close and centered as possible to the cargo until "Cargo In Range" and Engage Hook key (Shift-0) or Auto Engage Hook key (Ctrl-0). Move then "Release Cargo" key (o).
HINT: If your not a helo pilot, use the ufo to play with it. But that's BORING!


Below, a few issues I'm hoping to get answers for.

I wanted to dynamically add all the necessary code required in existing aircraft.xml with one nasal call, but ran into a few problems.

I was able to add everything dynamically except model paths. Even though I could add them to the prop tree, they didn't work. I don't know if it is something I am doing wrong or if it is not possible. Or maybe it is a load order issue.

I was able to add things like
Code: Select all
props.Node.new({ "controls/cargo-release":0 });
props.globals.initNode("controls/cargo-release", 0, "BOOL" );
props.Node.new({ "sim/model/cargo-hook":0, "sim/model/cargo-auto-hook":0, "sim/model/cargo-on-hook":0 });
props.globals.initNode("sim/model/cargo-hook", 0, "BOOL" );
props.globals.initNode("sim/model/cargo-auto-hook", 0, "BOOL" );
props.globals.initNode("sim/model/cargo-on-hook", 0, "BOOL" );
props.Node.new({ "sim/submodels/serviceable":1 });
props.globals.initNode("sim/submodels/serviceable", 1, "BOOL" );

to replace some settings in airplane/airplane-set.xml
but not the replacement for this
Code: Select all
<submodels>
   <path>Aircraft/AirCrane/Models/CargoContainer-submodel.xml</path>
</submodels>


which was something like this
Code: Select all
props.Node.new({ "sim/submodels/path":"" });
props.globals.initNode("sim/submodels/path", "Aircraft/AirCrane/Models/CargoContainer-submodel.xml", "STRING" );
if (props.globals.getNode("sim/submodels/path") == nil )
   props.globals.getNode("sim/submodels/path", 1).setValue("Aircraft/AirCrane/Models/CargoContainer-submodel.xml");

I threw everything I could think of at it. Don't laugh, remember I am completely new to nasal. I don't know if it is syntax error or just my stupidity.

I also couldn't add the airplane/model/airplane.xml cargo model dynamically.
I want to replace this.
Code: Select all
<model>
        <path>Aircraft/AirCrane/Models/CargoContainer.xml</path>
        <name>CargoContainer</name>
        <condition>
          <property>sim/model/cargo-on-hook</property>
        </condition>
        <offsets>
            <x-m>-2.2</x-m>
         <y-m>0</y-m>
         <z-m>-4</z-m>
         <!--x-m>-3.95</x-m>
         <y-m>0</y-m>
         <z-m>-10.5</z-m-->
            <pitch-deg>0</pitch-deg>
        </offsets>
    </model>
   
    <animation>
      <type>noshadow</type>
      <object-name>CargoContainer</object-name>
      <condition>
        <not>
          <property>sim/model/cargo-on-hook</property>
        </not>
      </condition>
    </animation>

with this
Code: Select all
#cargocontainer model
props.Node.new({ "model/path":"Aircraft/AirCrane/Models/CargoContainer.xml" });
props.globals.initNode("model/path", "Aircraft/AirCrane/Models/CargoContainer.xml", "STRING" );
props.Node.new({ "model/name":"CargoContainer" });
props.globals.initNode("model/name", "CargoContainer", "STRING" );
props.Node.new({ "model/condition/cargo-on-hook":0 });
props.globals.initNode("model/condition/cargo-on-hook", 0, "BOOL" );
props.Node.new({ "model/offsets/x-m":-2.2, "model/offsets/y-m":0, "model/offsets/z-m":-4, "model/offsets/pitch-deg":0 });
props.globals.initNode("model/offsets/x-m", -2.2, "DOUBLE" );
props.globals.initNode("model/offsets/y-m", 0, "DOUBLE" );
props.globals.initNode("model/offsets/z-m", -4, "DOUBLE" );
props.globals.initNode("model/offsets/pitch-deg", 0, "DOUBLE" );
#cargocontainer model shadow
props.Node.new({ "animation/type/noshadow":0 });
props.globals.initNode("animation/type/noshadow", 0, "BOOL" );
props.Node.new({ "animation/object-name":"CargoContainer" });
props.globals.initNode("animation/object-name", "CargoContainer", "STRING" );
props.Node.new({ "animation/condition/not/cargo-on-hook":0 });
props.globals.initNode("animation/condition/not/cargo-on-hook", 0, "BOOL" );

Again I couldn't get these to work.

The key handling was another thing I really want to add dynamically so as not to have users having to add it. But wasn't sure if something like
Code: Select all
keyHandler = func {
   #Ctrl-O = Auto Attach CargoContainer
   if ( getprop( "devices/status/keyboard/ctrl") ){
      if( getprop("devices/status/keyboard/event/key") == 15 ){
         setprop("sim/model/cargo-auto-hook", 1);
      }
   }
   #Shift-O = Attach CargoContainer
   if ( getprop( "devices/status/keyboard/shift") ){
      if( getprop("devices/status/keyboard/event/key") == 79 ){
         setprop("sim/model/cargo-hook", 1);
      }
   }
   #o = Release CargoContainer
   if( getprop("devices/status/keyboard/event/key") == 111 ){
      setprop("controls/cargo-release", 1);
   }
   settimer( func { timer() } , .5 );
}
keyHandler();

is appropriate.


EDIT: 9/6/14 3:39 CST - Version 1.a - Commented out URL's in KEQA_CargoContainer.xml, URL's were causing errors.
EDIT: 9/7/14 13:50 CST - Version 1.1 - Complete restructure of CargoContainer.nas, modified value in CargoContainer-submodel.xml.
EDIT: 9/8/14 13:20 CST - Version 1.2 - Organizational changes including renamed functions and files, replaced cargo model and added additional, better quality cargo models. Changed files: almost all of them.
EDIT: 9/21/14 Version 1.2 moved to git as Version 1.0
EDIT: 10/11/14 Version 1.3 rope tow capability git
EDIT: 1/18/15 Version 1.3 correct keyboard events git
Last edited by wlbragg on Thu May 18, 2017 8:25 pm, edited 10 times in total.
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7588
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: Announcing AI CargoTowing Capability

Postby wlbragg » Sat Sep 06, 2014 3:49 pm

Something else I forgot to mention. As it is written now, I am creating a new node and copying the ai model positions into the new node. I hide the hooked ai model at -999 alt when simulating carrying it, then bring it back to ground level using the impact coords from submodel ballistics from the release.
I manipulate the new node in the main loops and update the ai models position after every completed move and release. There is another model created (part of the code I'm trying to get rid of by dynamically creating it in nasal) that is the visible simulated cargo as it is being moved.
I did it this way because that is the way the example I used did it (Dragonfly).

It makes more sense to me to actually manipulate the ai model in real time and apply any force or effects to it, never hiding it, actually binding its movement to the craft when moving it instead of after the impact. Anyone see any reason manipulate the ai model in the existing prop tree in real time?
For one it would eliminate another big chunk of code that the user has to edit into their craft. Also it eliminates two additional nodes.
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7588
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: Announcing AI CargoTowing Capability

Postby wlbragg » Sun Sep 07, 2014 5:07 am

Well, I guess I just found out why you create a new modelNode and use model instead of AI/modelNode. Trying to update the AI model in real time creates far to much teleporting.
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7588
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: Announcing AI CargoTowing Capability

Postby wlbragg » Sun Sep 07, 2014 6:59 am

OK, I'm tracking versions on first post in this thread.
Newest version 1.1 was complete restructure and optimize CargoContainer.nas.
Also, offset value change in CargoContainer-submodel.xml.
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7588
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: Announcing AI CargoTowing Capability

Postby wlbragg » Mon Sep 08, 2014 9:20 am

Version 1.2
Organizational changes including renamed functions and files.
Replaced cargo model and added additional, better quality cargo models.
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7588
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: Announcing AI CargoTowing Capability

Postby wlbragg » Mon Sep 15, 2014 7:41 pm

Help!

I need to get the name of a parent node and I'm not quit sure how to do it.

Code: Select all
foreach( var cargoN; props.globals.getNode( "/ai/models", 1).getChildren( "aircraft" ) ) {

   #just to give you an idea of what I'm looking for, which in this case turns out to be
   #Aircraft[2] ie: Aircraft, Aircraft[1], Aircraft[2]

   if ( thisLoop = the3rd-AI-aircraft ) { 
 
      #this returnes only Aircraft and not which one
      print("node.parent.name=" ~ cargoN.getNode( "callsign" ).getParent().getName()));

      #this returns 0 no matter which one it is.
      #So I'm not understanding what getIndex is returning.
      #I thought it would be 2 or 3 depending on if 0 was counted
      print("parent.index=" ~ cargoN.getParent( "callsign" ).getIndex());   

     #in which case I could use
     print("parent is=" ~ cargoN.getNode( "callsign" ).getParent().getName() ~ "[" ~ cargoN.getParent( "callsign" ).getIndex() ~ "]");
     #but no matter which craft is the loops if choice, it's always Aircraft[0].
  }
}


I can't find the obvious. Or my feeble brain is to dense to see it.
I'm looking for a return of Aircraft[2], using this for loop.
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7588
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: Announcing AI CargoTowing Capability

Postby wlbragg » Mon Sep 15, 2014 8:31 pm

I got it

Code: Select all
print("node.parent.name=" ~ cargoN.getNode( "callsign" ).getParent().getName() ~ "[" ~ cargoN.getNode( "callsign" ).getParent().getIndex() ~ "]");
                  


Thanks anyway.
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7588
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: Announcing AI CargoTowing Capability

Postby wlbragg » Sun Sep 21, 2014 8:32 pm

This is now on git at
https://gitorious.org/ai-cargotow
Initial commit is 9/8/14 13:20 CST - Version 1.2 renamed version 1.0

You can follow any progress there.


Cargo-AI-Scenario_v1.4.zip
Last edited by wlbragg on Mon Jul 25, 2016 6:01 am, edited 1 time in total.
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7588
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: Announcing AI CargoTowing Capability

Postby rastafioul » Fri Jul 22, 2016 9:08 pm

Hello,
This is an old thread but the videos you proposed on viewtopic.php?f=23&t=23925 gave me the hope to do the same on flightgear, just like you! :)
As I cannot find a way to see the container in load_demo scenario, is your ai-cargotow still available somewhere as, at this time (2016) the link is broken.


Rastafioul,
Debian 8, aspire5750G (nvidia GT520M - which probably does not work, 6G0), Flightgear 2016.2.1
rastafioul
 
Posts: 18
Joined: Tue Feb 16, 2016 6:55 pm
Version: 2016.2.1
OS: debian

Re: Announcing AI CargoTowing Capability

Postby wlbragg » Sat Jul 23, 2016 4:01 am

I would be very interested in any improvements or development you might make in this area. I kind of put it on the back burner but intend to pick it back up in the future.

Cargo-AI-Senario_v1.3.rar
Cargo-AI-Scenario_v1.4.zip
Last edited by wlbragg on Mon Jul 25, 2016 6:00 am, edited 1 time in total.
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7588
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: Announcing AI CargoTowing Capability

Postby rastafioul » Sun Jul 24, 2016 11:00 pm

Well, I am really a newbie on flightgear and as the aircrane had no panel and I could not see the containers, I managed to put your code on the ec130. (I hope I have the right to do that as I did not read the licence)

I finally could see and spot the containers but could not get one of them hooked. I put one closer to me because it took time to turn the chopper on and to go to the containers.

I retry with the crane as the container are now visible but could not either get them hooked.
Is this normal according to your developpement?

Here is what I get when I run flightgear:

Code: Select all
Enabling ATI viewport hack
Starting automatic scenery download/synchronization. Using built-in SVN support. Directory: '/home/me/.fgfs/TerraSync'.
Nasal runtime error: non-objects have no members
  at /input/joysticks/js/nasal, line 4
Cargo Created:Cargo1
37.768839/-96.81596899999999
Elev-ft:1368.697496193673
Head:307.8873949590628

Cargo Created:Cargo2
37.768839/-96.81476899999999
Elev-ft:1367.962015133364
Head:307.8873227083629

Cargo Created:Cargo3
37.77835499999999/-96.813149
Elev-ft:1376.482001727755
Head:307.8967491584969

unknown vasi/papi configuration, count = 1
unknown vasi/papi configuration, count = 1



For the container,
KEQA_cargo1.xml :

I changed the altitude, put END instead of EOF as with EOF I had a flight error (FGAIFlightPlan::Flightplan missing END node) and according to https://sourceforge.net/p/flightgear/fl ... htPlan.cxx it returns false on line 256
The code that works for the container is

Code: Select all
<?xml version="1.0"?>
<PropertyList>
   <flightplan>
      <wpt>
         <name>END</name>
         <lat>37.768839</lat>
         <lon>-96.815969</lon>
         <alt>1378</alt>
         <ktas>0</ktas>
         <on-ground>1</on-ground>
      </wpt>
      <wpt>
         <name>END</name>
      </wpt>
   </flightplan>
</PropertyList>


I have no idea what to do so it works at least with one helicopter.
Maybe... i need to read the whole post... :S :oops:
Thanks to every single person who helped and/or still helping to have such a great simulator.
For those who would find any complain to do: help or shut up and buy one!
rastafioul
 
Posts: 18
Joined: Tue Feb 16, 2016 6:55 pm
Version: 2016.2.1
OS: debian

Re: Announcing AI CargoTowing Capability

Postby wlbragg » Mon Jul 25, 2016 1:22 am

I changed the altitude, put END instead of EOF

That is a change that happened a while back in the AI code, I already fixed it but only in my local copy. I never added it to the zip file.

After testing this I don't see the AI ballistics part of it working. Also the "Auto Hook Engaged" (ctrl+o) doesn't report the GUI popup that is suppose to tell you Auto Hook Engaged meaning if you get close enough to the cargo it will attach automatically. I remember the tolerance was really close to get it to hook but i can't get a visual or GUI dialog conformation of it hooking. However I do get a release animation (only once though, then it acts like you can't grab a 2nd container, which you used to be able to do). So I am not sure what all is broke on it. It's going to take some digging to find out what has changed at the FG core to break it.

Maybe this will spark my interest again to start back up on it.
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7588
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: Announcing AI CargoTowing Capability

Postby wlbragg » Mon Jul 25, 2016 3:19 am

I think I figured out part of what may be wrong. It is blowing out of the Cargo code due to a check for the Cargo1 model to have been loaded. But It is only checking the first ai model at /ai/models/aircraft/callsign. In my setup it is in the 3rd or 4th ai aircraft position. So I guess I need to refactor that part of the code to make sure it catches the ai cargo no matter where it is assigned. Maybe if you make sure you have no other AI scenarios loaded it will fall in the correct position?
Code: Select all
if ( props.globals.getNode("/ai/models/aircraft/callsign", 1).getValue() != "Cargo1") {
      print("No AI Cargo, exiting Cargo.nas!");
      return;
   }


EDIT:

You can make the Cargo scenario the first in the scenario load order and now it's in the correct order and is not blowing out. But I think I now have another error I need to chase down.
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7588
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: Announcing AI CargoTowing Capability

Postby wlbragg » Mon Jul 25, 2016 5:41 am

OK, here are the current issues and what you can do to fix them.

1) The EOF in the flight plans needs to be changed to END
2) The Cargo scenario needs to be the first scenario to load or change the code to account for the order and amount of cargo's you use.
3) Another issue is if there are more than just the AI "cargo's" it will count them and try to use them as cargo and cause problems. So you need to limit the foreach loop to only load the AI Cargo's and no others. By default there are 2 cargo containers so for now I simply added a counter to the foreach loop and a break; when it reached 2. It was the quickest thing I could think of. I need to refactor this part of the code and make it bullet proof.
4) The zip I gave you is defaulting to the"rope tow" instead of "hard docked". Hard docked is the one you should use, rope tow isn't finished and has many issues with the rope and physics. There are instructions on how to switch between the two (commenting out lines of code). Eventually I need to have a GUI choice to do this.

Once these issues are taken care of you should have something that works reasonably well. Good enough for a base to improve upon anyway.

You'll know that you have it working when you see the Cargo GUI entry created in the sim (means you got to the end of the init phase in the code). Also ctrl+o will give you a popup that says Auto Hook Engaged and you will automatically hook the cargo when you are centered right on top of it.

Here is a link to the AirCrane setup with all the fixes, just be sure to make Cargo the first AI scenario to load and it should work and be in the "hard dock" mode.

I also updated the original Cargo Scenario zip file.
Kansas and Ohio/Midwest scenery development.
KEQA, 3AU, KRCP Airport Layout
Intel i7/GeForce RTX 2070/Max-Q
User avatar
wlbragg
 
Posts: 7588
Joined: Sun Aug 26, 2012 12:31 am
Location: Kansas (Tornado Alley), USA
Callsign: WC2020
Version: next
OS: Win10/Linux/RTX 2070

Re: Announcing AI CargoTowing Capability

Postby rastafioul » Mon Jul 25, 2016 9:59 am

Just gave a try! Looks cool! thanks for the work!

Can you give me precisions on thoses points:
- When you drop the container, does the aircraft react according to this? (haven't had the time to test yet)
- Have you had a look at the hooking when landing the awesome F-14 on a carrier and if yes, could it be useful to inspire (is this word understandable the way I mean it in english) from this?
- Now the scenarios can be loaded "on the flight" just by checking a box. Wasn't it the case when you developed and therefore would it be good to check how it's done?
- Would it be possible with your code to make the container "land" on the ground (and setting the weight to 0), even if it is still hooked?
- Would it be a good idea to make multiple "container-like-and-much-smaller" objects that would, towed together, make the rope?

Well, I guess i also will have to have a look at "aerotow".

As I ran
Code: Select all
./fgfs --aircraft=aircrane  --geometry=900x700  --fg-root=../fgdata --airport=keqa --ai-scenario=KEQA_crane_Cargo

The scenario starts well.

Man!... You got my interest with that thing.
Thanks to every single person who helped and/or still helping to have such a great simulator.
For those who would find any complain to do: help or shut up and buy one!
rastafioul
 
Posts: 18
Joined: Tue Feb 16, 2016 6:55 pm
Version: 2016.2.1
OS: debian

Next

Return to AI Traffic

Who is online

Users browsing this forum: No registered users and 3 guests