Anteworld - Outerra Game > JavaScript development

activate autopilot in new plane script

(1/2) > >>

fly77:
I am trying to add autopilot functionality to a plane (modding Levi's Heinkel) following the script of the cessna 172 but I can't get the autopilot functionality to work allthough I copied the lines of codes of the C172 associated with autopilot (see below). CTRL+W works on the C172 to do wingleveling but not on my Heinkel script mod. What I am missing ?
FDM folder structure is as follows..so there is a Autopilot.xml in Systems. should this be enough ?

aircraft
   Heinkel_He51
      Heinkel_He51.xml
      aerodynamics.xml
      flight_control.xml
      ground_reactions.xml
      propulsion.xml
      Systems
           Autopilot.xml
           GNCUtilities.xml
engine
   BMW_VI.xml
   prop.xml


--- Code: ---var ap_wing_level_switch

function initialize(reload){ 
  jsb = this.jsb();
  ......
  ap_wing_level_switch = 0;
  this.register_event("air/autopilot/wing_leveler", function(v) { ap_wing_level_switch ^= 1; });
}


function update_frame(dt){
......
 jsb['ap/autopilot-roll-on']=ap_wing_level_switch;
}

--- End code ---

andfly:
I think it's sufficient to add these two lines of code in the "Heinkel_He51.xml" file

<system file = "GNCUtilities" />
<system file = "Autopilot" />

Now Heinkel should also have an autopilot and utilities.

It should be possible to recall its features with the script.

I wish you good work  :D

fly77:
Hi andfly ! nice to hear from you and thanks for the suggestion. Unfortunately there seems to be something other missing or wrong as including these two lines in the Heinkel xml form Levi didn't resolve the problem. What I did is
copy the "Systems" folder from the cessna 172 into the corresponding location of  the Heinkel (see above) so these files are the same as for the cessna. Then added the two lines of code you mention to The Heinkel xml and include the autopilot related javascript code lines (as above) from the cessna to Levi's Heinkel...still doesn't work. Heinkel xml file from Levi with the two added lines reads as below. Autopilot winglevelling works for the cessna but not for the modded Heinkel


--- Code: ---<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="http://jsbsim.sourceforge.net/JSBSim.xsl"?>
<fdm_config name="Heinkel_He51" version="2.0" release="ALPHA"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:noNamespaceSchemaLocation="http://jsbsim.sourceforge.net/JSBSim.xsd">

 <fileheader>
  <author> Levi Cires </author>
  <filecreationdate>2014-12-15</filecreationdate>
  <version>$Revision: 1.15 $</version>
  <description> Models a Heinkel_He51. </description>
 </fileheader>

<!--
  File:     Heinkel_He51.xml
  Inputs:
    name:          Heinkel_He51
    type:          light single
    max weight:    4180 lb
    wing span:     36.08333333333334 ft
    length:        27.5591 ft
    wing area:     292.6 sq-ft
    gear type:     taildragger
    retractable?:  no
    # engines:     1
    engine type:   piston
    engine layout: forward fuselage
    yaw damper?    no

  Outputs:
    wing loading:  14.29 lb/sq-ft
    payload:       349.4 lbs
    CL-alpha:      5 per radian
    CL-0:          0.25
    CL-max:        1.4
    CD-0:          0.028
    K:             0.04

-->

 <metrics>
   <wingarea  unit="FT2">  292.60 </wingarea>
   <wingspan  unit="FT" >   36.08 </wingspan>
   <wing_incidence>          2.00 </wing_incidence>
   <chord     unit="FT" >    8.11 </chord>
   <htailarea unit="FT2">   25.00 </htailarea>
   <htailarm  unit="FT" >   14.33 </htailarm>
   <vtailarea unit="FT2">   80.00 </vtailarea>
   <vtailarm  unit="FT" >   13.78 </vtailarm>
   <location name="AERORP" unit="M">
     <x>   0.00 </x>
     <y>   0.00 </y>
     <z>   0.00 </z>
   </location>
   <location name="EYEPOINT" unit="M">
     <x>  0.00 </x>
     <y>  0.00 </y>
     <z>  0.00 </z>
   </location>
   <location name="VRP" unit="M">
     <x>0</x>
     <y>0</y>
     <z>0</z>
   </location>
 </metrics>

 <mass_balance>
   <ixx unit="SLUG*FT2">      2367 </ixx>
   <iyy unit="SLUG*FT2">      2455 </iyy>
   <izz unit="SLUG*FT2">      4454 </izz>
   <emptywt unit="LBS" >      3212 </emptywt>
   <location name="CG" unit="M">
     <x>   0.00 </x>
     <y>   0.00 </y>
     <z>   0.00 </z>
   </location>
   <pointmass name="Payload">
    <description> 349 LBS + full (619 LBS) fuel should bring model up to entered max weight</description>
    <weight unit="LBS">    174.7 </weight>
    <location name="POINTMASS" unit="M">
      <x>   0.50 </x>
      <y>   0.00 </y>
      <z>   0.00 </z>
    </location>
  </pointmass>
 </mass_balance>

<ground_reactions file="ground_reactions"/>
<propulsion file="propulsion"/>
<flight_control file="flight_control"/>
<aerodynamics file="aerodynamics"/>
<system file="GNCUtilities"/>
<system file="Autopilot"/>
</fdm_config>

--- End code ---

andfly:
Here I am denied immediately ....

I was convinced that it was all there ...

The only further advice is to insert the two new lines of code between the definitions of the propulsion and those of the flight_control because it is exactly there that they are placed in the file of the cessna (however I believe little that this is really influential)

<ground_reactions file="ground_reactions"/>
<propulsion file="propulsion"/>
<system file = "GNCUtilities" />
<system file = "Autopilot" />
<flight_control file="flight_control"/>
<aerodynamics file="aerodynamics"/>

I also noticed that at the end of the cessna script there are (disabled) lines of "log" concerning the parameters of the autopilot ...
Try enabling them to see if the autopilot is really dead or just "out of phase".

//Autopilot DEBUG
 // this.log("AP Wing Level Hold: " + ap_wing_level_switch);
 // this.log("AP Roll Cmd Norm: " + this.jsbsim['ap/roll-cmd-norm-output']);
 // this.log("AP Roll Mode: " + this.jsbsim['ap/roll-attitude-mode']);
 // this.log("AP Roll On/Off: " + this.jsbsim['ap/autopilot-roll-on']);
 // this.log("Aileron Cmd Norm: " + this.jsbsim['fcs/aileron-cmd-norm']);
(replacing this.jsbsim with jsb)

I don't know what else to tell you ...
I leave the word to the real experts of JSBSim.

Still good work and have fun!   ;)

andfly:
I discovered the mystery!

Meanwhile, I have verified that, with the added lines of code that we talked about before, the autopilot is inserted into the commands of the aircraft and works properly.
The thing that is still missing is the possibility, for Heinkel, to receive the commands of the autopilot and to implement them.

If you open the Heinkel file concerning the "flight_control" (flight_control.xlml), in particular, in the <channel name = "Roll"> you read this code:

<summer name = "Roll Trim Sum">
      <Input> FCS / aileron-cmd-norm </ input>
      <Input> FCS / roll-trim-cmd-norm </ input>
      <Clipto>
        <min> -1 </min>
        <max> 1 </max>
      </ Clipto>
   </ Summer>
               

In the corresponding Cessna file (c172r.xml), in the "flight_control" section, you will find this:

 <summer name = "Roll Trim Sum">
                <Input> ap / roll-cmd-norm-output </ input>
                <Input> FCS / aileron-cmd-norm </ input>
                <Input> FCS / roll-trim-cmd-norm </ input>
                <Clipto>
                    <Min> -1 </ min>
                    <Max> 1 </ Max>
                </ Clipto>
            </ Summer>


You will immediately notice the missing line, in the Heinkel file, which refers to the possibility of input also of the results of the autopilot calculations.
It is therefore sufficient to add this line of code and the autopilot will be able to influence the stability of the aircraft (I checked: It works!)

I no longer have much time to devote myself to Outerra, but I am happy to follow the developments of the work of the fans who publish on the forum.
I must congratulate you on the results obtained.

I wish you good work and good fun again   =D

Navigation

[0] Message Index

[#] Next page

Go to full version