AirControl  1.3.0
Open Source, Modular, and Extensible Flight Simulator For Deep Learning Research
AirplaneProperties.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using System.Globalization;
4 using System.IO;
5 using System.IO.Enumeration;
6 using System.Runtime.InteropServices.WindowsRuntime;
7 using Commons;
8 using Communicator;
9 using Newtonsoft.Json;
10 using Newtonsoft.Json.Linq;
11 using UnityEditor;
12 using UnityEngine;
13 
14 namespace Commons
15 {
16  public static class AirplaneProperties
17  {
24  public static int getInt(string airplaneName, string property)
25  {
26  string key = airplaneName + "/" + property;
27  bool ifKeyPresent = CommonFunctions.airplanePreset.ContainsKey(key);
28 
29  if (ifKeyPresent)
30  {
31  return (int)CommonFunctions.airplanePreset[key];
32  }
33  else
34  {
35  Debug.Log("Key Not present - " + key);
36  return -1;
37  }
38  }
45  public static float getFloat(string airplaneName, string property)
46  {
47  string key = airplaneName + "/" + property;
48  bool ifKeyPresent = CommonFunctions.airplanePreset.ContainsKey(key);
49 
50  if (ifKeyPresent)
51  {
52  return (float)CommonFunctions.airplanePreset[key];
53  }
54  else
55  {
56  Debug.Log("Key Not present - " + key);
57  return -1f;
58  }
59  }
66  public static string getString(string airplaneName, string property)
67  {
68  string key = airplaneName + "/" + property;
69  bool ifKeyPresent = CommonFunctions.airplanePreset.ContainsKey(key);
70 
71  if (ifKeyPresent)
72  {
73  return (string)CommonFunctions.airplanePreset[key];
74  }
75  else
76  {
77  Debug.unityLogger.Log("Key Not present : {0} ", key);
78  return "None";
79  }
80  }
86  public static bool readJson(string filepath)
87  {
88 
89  // read JSON directly from a file
90  StreamReader file = File.OpenText(filepath);
91  JsonTextReader reader = new JsonTextReader(file);
92  JObject jsonContent = new JObject();
93 
94  try
95  {
96  CommonFunctions.jsonPreset = (JObject)JToken.ReadFrom(reader);
97  return true;
98  }
99  catch (JsonException ioExp)
100  {
101  Debug.Log(ioExp.Message);
102  return false;
103  }
104 
105  }
106 
111  public static void saveJson(string filepath)
112  {
113  // write JSON directly to a file
114  using (FileStream fs = File.Create(filepath))
115  using (StreamWriter jsonStream = new StreamWriter(fs))
116  {
117  var jsonSerializer = new Newtonsoft.Json.JsonSerializer();
118  jsonSerializer.Formatting = Formatting.Indented;
119  //reset the priority to 1
120  CommonFunctions.airplanePreset["General/priority"] = 1;
121  jsonSerializer.Serialize(jsonStream, CommonFunctions.airplanePreset);
122  }
123  }
124 
128  public static void initAirplaneJsonObject()
129  {
130  CommonFunctions.airplanePreset["General/docversion"] = CommonFunctions.GET_VERSION();
131  CommonFunctions.airplanePreset["General/priority"] = 5; // if priority of json is higher json will override default setting
132  CommonFunctions.airplanePreset["General/activeAirplane"] = "Cessna152"; // if priority of json is higher json will override default setting
133  CommonFunctions.airplanePreset["Cessna152/cameraHeight"] = 6;// Height of camera
134  CommonFunctions.airplanePreset["Cessna152/cameraDistance"] = 12;// Camera distance
135  CommonFunctions.airplanePreset["Cessna152/minHeaightFromGround"] = 4;// Min height of camera from ground when aiplane lands
136  //characteristics
137  CommonFunctions.airplanePreset["Cessna152/maxMPH"] = 150;// Max speed of the airplane
138  CommonFunctions.airplanePreset["Cessna152/rbLerpSpeed"] = 0.1; // Controls accelearation
139  CommonFunctions.airplanePreset["Cessna152/maxLiftPower"] = 100;// Control takeoff power of the airplane
140  CommonFunctions.airplanePreset["Cessna152/flapLiftPower"] = 500;// Lift force by flap
141  CommonFunctions.airplanePreset["Cessna152/dragFactor"] = 0.01;// Drag by air pressure
142  CommonFunctions.airplanePreset["Cessna152/flapDragFactor"] = 0.001;// Drag when flap is used
143  CommonFunctions.airplanePreset["Cessna152/pitchSpeed"] = 5000;// Elevator sufarce effectivness
144  CommonFunctions.airplanePreset["Cessna152/rollSpeed"] = 4000;// Aleron surface effectivness
145  CommonFunctions.airplanePreset["Cessna152/yawSpeed"] = 5000; // Rudder lever effectivness
146  // Airplane Controller
147  CommonFunctions.airplanePreset["Cessna152/airplaneWeight"] = 900; // Mass of the Airplane in pounds
148  //control surface
149  CommonFunctions.airplanePreset["Cessna152/smoothSpeed"] = 4; // Control surface speed
150  CommonFunctions.airplanePreset["Cessna152/maxAngle"] = 30; // Max angle of the control surface
151  //engine
152  CommonFunctions.airplanePreset["Cessna152/maxRPM"] = 4500; // RPM of the engine force will be calculated by equarion $F_i = C_t\rho\omega^2_{max}D^4$
153  CommonFunctions.airplanePreset["Cessna152/shutOffSpeed"] = 2; // shutdown rate when the engien is shutoff
154  CommonFunctions.airplanePreset["Cessna152/propellerSpan"] = 1.6; // span of the propeller in meters
155  //fuel
156  CommonFunctions.airplanePreset["Cessna152/fuelCapacity"] = 29; // fuel capacity of the Airplane in galloons
157  CommonFunctions.airplanePreset["Cessna152/fuelBurnRate"] = 6.1; // consumpltion rate Gallons/hr
158  //ground effect
159  CommonFunctions.airplanePreset["Cessna152/groundDistance"] = 3; // Distance from ground when the ground effect starts, generally its equal to wingspan
160  CommonFunctions.airplanePreset["Cessna152/liftForce"] = 50; // lift force generated by the ground effect
161  CommonFunctions.airplanePreset["Cessna152/maxSpeed"] = 15; // max pseed for ground effect
162  //input
163  CommonFunctions.airplanePreset["Cessna152/throttleSpeed"] = 0.1;// Throttle Speed
164  //wheel
165  CommonFunctions.airplanePreset["Cessna152/brakePower"] = 500; // Brake Power
166  CommonFunctions.airplanePreset["Cessna152/steerAngle"] = 20; // steer angle of the wheel
167 
169  CommonFunctions.airplanePreset["F4UCorsair/cameraHeight"] = 25;//
170  CommonFunctions.airplanePreset["F4UCorsair/cameraDistance"] = 25;//
171  CommonFunctions.airplanePreset["F4UCorsair/minHeaightFromGround"] = 20;//
172  //characteristics
173  CommonFunctions.airplanePreset["F4UCorsair/maxMPH"] = 360;//
174  CommonFunctions.airplanePreset["F4UCorsair/rbLerpSpeed"] = 0.1;//
175  CommonFunctions.airplanePreset["F4UCorsair/maxLiftPower"] = 200;//
176  CommonFunctions.airplanePreset["F4UCorsair/flapLiftPower"] = 1000;//
177  CommonFunctions.airplanePreset["F4UCorsair/dragFactor"] = 0.01;//
178  CommonFunctions.airplanePreset["F4UCorsair/flapDragFactor"] = 0.0005;//
179  CommonFunctions.airplanePreset["F4UCorsair/pitchSpeed"] = 25000;//
180  CommonFunctions.airplanePreset["F4UCorsair/rollSpeed"] = 25000;//
181  CommonFunctions.airplanePreset["F4UCorsair/yawSpeed"] = 25000; //
182  // Airplane Controller
183  CommonFunctions.airplanePreset["F4UCorsair/airplaneWeight"] = 2500; //
184  //control surface
185  CommonFunctions.airplanePreset["F4UCorsair/smoothSpeed"] = 4; //
186  CommonFunctions.airplanePreset["F4UCorsair/maxAngle"] = 30;
187  //engine
188  CommonFunctions.airplanePreset["F4UCorsair/maxRPM"] = 6500;//
189  CommonFunctions.airplanePreset["F4UCorsair/shutOffSpeed"] = 2.5;//
190  CommonFunctions.airplanePreset["F4UCorsair/propellerSpan"] = 2.2; //
191  //fuel
192  CommonFunctions.airplanePreset["F4UCorsair/fuelCapacity"] = 75;
193  CommonFunctions.airplanePreset["F4UCorsair/fuelBurnRate"] = 12;
194  //ground effect
195  CommonFunctions.airplanePreset["F4UCorsair/groundDistance"] = 6; //
196  CommonFunctions.airplanePreset["F4UCorsair/liftForce"] = 150; //
197  CommonFunctions.airplanePreset["F4UCorsair/maxSpeed"] = 30; //
198  //input
199  CommonFunctions.airplanePreset["F4UCorsair/throttleSpeed"] = 0.06;//
200  //wheel
201  CommonFunctions.airplanePreset["F4UCorsair/brakePower"] = 500; //
202  CommonFunctions.airplanePreset["F4UCorsair/steerAngle"] = 25; //
203  }
204 
205  }
206 
207 }
208 
209 
Communicator
Definition: InputHandle.cs:10
Commons
Definition: AirplaneProperties.cs:14