Afsim沿高程运动

发布于:2025-09-15 ⋅ 阅读:(16) ⋅ 点赞:(0)

目录

前言

一、数据格式转换

二、Afsim加载

1.拷贝数据

2.编写脚本

3.运行效果


前言

将tif数据转为dted格式数据,通过terrain加载到afsim中,使得平台沿着高程运动。


一、数据格式转换

使用Arcgis Pro在工具箱搜索栅格转数字地形高程(DTED),如图:

设置好参数,等待运行结束,如图:

成果,如图:

二、Afsim加载

1.拷贝数据

2.编写脚本

代码如下(示例):

# File generated by Wizard 2.9.0 on Sep 14, 2025.

route Route-1

   label Waypoint-0
   position 23:27:59.080n 121:08:24.867e altitude 0.00 ft
      speed 50 m/s
      linear_acceleration 10 g
      radial_acceleration 10 g
   label Waypoint-1
   position 23:25:13.442n 120:57:46.577e altitude 0.00 ft
   label Waypoint-2
   position 23:26:56.039n 120:51:34.674e altitude 0.00 ft
   label Waypoint-3
   position 23:31:01.476n 120:46:42.788e altitude 0.00 ft
   label Waypoint-4
   position 23:44:48.837n 120:36:49.525e altitude 0.00 ft
   label Waypoint-5
   position 23:55:02.124n 120:33:57.843e altitude 0.00 ft
   label Waypoint-6
   position 23:56:00.586n 120:25:57.363e altitude 0.00 ft
end_route

processor TERRAIN_FOLLOWING WSF_SCRIPT_PROCESSOR
   script_variables
      double COMMANDED_HEIGHT_ABOVE_TERRAIN = 10; # This is the default - must be changed
                                                    # by either the platform_type or platform
      double HEIGHT_TOLERANCE               = 0;   # +/- tolerance for hysteresis
   end_script_variables
   update_interval 0.1 sec
   on_update
      WsfGeoPoint FutureLocation  = PLATFORM.Location();
      double CurrentAltAGL  = PLATFORM.HeightAboveTerrain();
      double CurrentSpeed   = PLATFORM.Speed();
      double CurrentAltMSL  = PLATFORM.Altitude();
      double MaxRate        = 100;
      double Rate           =  50;
      FutureLocation.Extrapolate(0, CurrentSpeed*2); #heading, speed*script_update_rate
      double FutureAltAGL = FutureLocation.HeightAboveTerrain();
      // Valley coming...
      if (FutureAltAGL > (COMMANDED_HEIGHT_ABOVE_TERRAIN + HEIGHT_TOLERANCE))
         {
         #double NewAlt = CurrentAltMSL - COMMANDED_HEIGHT_ABOVE_TERRAIN;
         double NewAlt = CurrentAltMSL - FutureAltAGL;
         if (CurrentAltMSL - NewAlt > 100) Rate = MaxRate;
         PLATFORM.GoToAltitude(NewAlt, Rate, 1); # Alt, Rate, stay on route
         writeln(TIME_NOW, " Commanding to go down to the new alt of ", NewAlt);
         }
      // Hill coming up..
      if (FutureAltAGL < (COMMANDED_HEIGHT_ABOVE_TERRAIN - HEIGHT_TOLERANCE))
         {
         #double NewAlt = CurrentAltMSL + COMMANDED_HEIGHT_ABOVE_TERRAIN;
         double NewAlt = CurrentAltMSL + FutureAltAGL ;
         if (NewAlt - CurrentAltMSL > 100) Rate = MaxRate;
         PLATFORM.GoToAltitude(NewAlt, Rate, 1); # Alt, Rate, stay on route
         writeln(TIME_NOW, " Commanding to go up to the new alt of ", NewAlt);
         }
   end_on_update
end_processor

platform_type A WSF_PLATFORM 
   mover WSF_GROUND_MOVER 
     body_g_limit 4 g
     maximum_climb_rate 200 ft/s
   end_mover
   
   processor TERRAIN_DOLLOWING TERRAIN_FOLLOWING
   end_processor
   
end_platform_type

platform B A
   icon 2s6
   side red
   position 23:27:59.080n 121:08:24.867e altitude 3000 m

   on_initialize2 
      FollowRoute(WsfRoute.CopyGlobal("Route-1"));
   end_on_initialize2

end_platform

terrain
   raw_dted 2 dted 21 119 26 125
end_terrain

on_initialize
   WsfTerrain terrain = WsfTerrain();
   if (terrain.TerrainElevApprox(22.4, 121.38) == 0)
   {
      writeln("***** WARNING: You must provide your own terrain data in 'terrain_demo.txt', line 71, near column 1");
   }
end_on_initialize

end_time 1 h


3.运行效果