]> git.mxchange.org Git - flightgear.git/blobdiff - LaRCsim/ls_interface.c
Attempting to iron out seg faults and crashes.
[flightgear.git] / LaRCsim / ls_interface.c
index 59feea8e687c43d5e9485eb6e9d141cacf43902a..4017b7c935fe5efff4397a9fa39be1f92e9628b4 100644 (file)
@@ -242,6 +242,9 @@ $Original log: LaRCsim.c,v $
 #include "ls_init.h"
 #include <Flight/flight.h>
 #include <Aircraft/aircraft.h>
+#include <Autopilot/autopilot.h>
+#include <Debug/fg_debug.h>
+
 
 /* global variable declarations */
 
@@ -529,11 +532,11 @@ int fgLaRCsimInit(double dt) {
        return 1;
     }
 
-    printf("LS pre Init pos = %.2f\n", Latitude);
+    /* printf("LS pre Init pos = %.2f\n", Latitude); */
 
     ls_init();
 
-    printf("LS post Init pos = %.2f\n", Latitude);
+    /* printf("LS post Init pos = %.2f\n", Latitude); */
 
     if (speedup > 0) {
        /* Initialize (get) cockpit (controls) settings */
@@ -545,7 +548,8 @@ int fgLaRCsimInit(double dt) {
 
 
 /* Run an iteration of the EOM (equations of motion) */
-int fgLaRCsimUpdate(int multiloop) {
+int fgLaRCsimUpdate(fgFLIGHT *f, int multiloop) {
+    double save_alt = 0.0;
     int        i;
 
     if (speedup > 0) {
@@ -553,7 +557,40 @@ int fgLaRCsimUpdate(int multiloop) {
     }
 
     for ( i = 0; i < multiloop; i++ ) {
+       //Insertion by Jeff Goeke-Smith for Autopilot.
+       
+       // run Autopilot system
+       // fgPrintf( FG_ALL, FG_BULK, "Attempting autopilot run\n");
+       fgAPRun();
+
+       /* lets try to avoid really screwing up the LaRCsim model */
+       if ( FG_Altitude < -9000 ) {
+           save_alt = FG_Altitude;
+           FG_Altitude = 0;
+       }
+
+       // translate FG to LaRCsim structure
+       fgFlight_2_LaRCsim(f);
+       // printf("FG_Altitude = %.2f\n", FG_Altitude * 0.3048);
+       // printf("Altitude = %.2f\n", Altitude * 0.3048);
+       // printf("Radius to Vehicle = %.2f\n", Radius_to_vehicle * 0.3048);
+
+       // end of insertion 
+       
        ls_loop( model_dt, 0);
+
+       // printf("%d FG_Altitude = %.2f\n", i, FG_Altitude * 0.3048);
+       // printf("%d Altitude = %.2f\n", i, Altitude * 0.3048);
+
+       // translate LaRCsim back to FG structure so that the
+       // autopilot (and the rest of the sim can use the updated
+       // values
+       fgLaRCsim_2_Flight(f);
+
+       /* but lets restore our original bogus altitude when we are done */
+       if ( save_alt < -9000 ) {
+           FG_Altitude = save_alt;
+       }
     }
 
     return(1);
@@ -911,9 +948,39 @@ int fgLaRCsim_2_Flight (fgFLIGHT *f) {
     return ( 0 );
 }
 
+
+/* Set the altitude (force) */
+int ls_ForceAltitude(double alt_feet) {
+    Altitude = alt_feet;
+    ls_geod_to_geoc( Latitude, Altitude, &Sea_level_radius, &Lat_geocentric);
+    Radius_to_vehicle = Altitude + Sea_level_radius;
+}
+
+
 /* Flight Gear Modification Log
  *
  * $Log$
+ * Revision 1.21  1998/08/22 14:49:56  curt
+ * Attempting to iron out seg faults and crashes.
+ * Did some shuffling to fix a initialization order problem between view
+ * position, scenery elevation.
+ *
+ * Revision 1.20  1998/07/12 03:11:03  curt
+ * Removed some printf()'s.
+ * Fixed the autopilot integration so it should be able to update it's control
+ *   positions every time the internal flight model loop is run, and not just
+ *   once per rendered frame.
+ * Added a routine to do the necessary stuff to force an arbitrary altitude
+ *   change.
+ * Gave the Navion engine just a tad more power.
+ *
+ * Revision 1.19  1998/05/11 18:17:28  curt
+ * Output message tweaking.
+ *
+ * Revision 1.18  1998/04/21 16:59:38  curt
+ * Integrated autopilot.
+ * Prepairing for C++ integration.
+ *
  * Revision 1.17  1998/02/23 19:07:58  curt
  * Incorporated Durk's Astro/ tweaks.  Includes unifying the sun position
  * calculation code between sun display, and other FG sections that use this