PDA

View Full Version : Black-Box script for SP training



No1_Jacko
Apr-05-2014, 06:42
Folks

I came across this piece of code that is meant to make a csv file loggin your flight parameters to look at later i excel. I don't have a good knowledge but woundered if someone could kindly fix this at the moment it gives errors
Cheers
Jacko

//-$debug
using System;
using System.Threading;
using System.Collections.Generic;
using maddox.game;
using maddox.game.world;
using maddox.GP;


public class Mission : AMission
{
//flag
bool done = false;

//Create Stream
System.IO.StreamWriter sw;

//Strings
string str_log = System.String.Empty;
string str_hud = System.String.Empty;

//Create Log File
System.IO.FileInfo fi = new System.IO.FileInfo("C:\\FLIGHT_TEST_DATA.CSV");

//Script Main
public override void OnTickGame()
{
//Init Ticker
base.OnTickGame();

//loop rate set to ~1/30th of a second, i.e. 30 ticks = ~1 second
if (Time.tickCounter() % 30 == 1)
{
//Get player aircraft
AiAircraft curPlane = GamePlay.gpPlayer().Place() as AiAircraft;

if (curPlane != null)
{
//Instrumentation - Machine Spatial
double I_VelocityIAS = curPlane.getParameter(part.ParameterTypes.I_Veloci tyIAS, -1);
double I_Altitude = curPlane.getParameter(part.ParameterTypes.I_Altitu de, -1);
double I_Variometer = curPlane.getParameter(part.ParameterTypes.I_Variom eter, -1);
double I_MagneticCompass = curPlane.getParameter(part.ParameterTypes.I_Magnet icCompass, -1);

//Parameters - Machine Spatial
double Z_Overload = curPlane.getParameter(part.ParameterTypes.Z_Overlo ad, -1);
double Z_AltitudeAGL = curPlane.getParameter(part.ParameterTypes.Z_Altitu deAGL, -1);
double Z_AltitudeMSL = curPlane.getParameter(part.ParameterTypes.Z_Altitu deMSL, -1);
double Z_VelocityIAS = curPlane.getParameter(part.ParameterTypes.Z_Veloci tyIAS, -1);
double Z_VelocityTAS = curPlane.getParameter(part.ParameterTypes.Z_Veloci tyTAS, -1);
double Z_VelocityMach = curPlane.getParameter(part.ParameterTypes.Z_Veloci tyMach, -1);
double Z_AmbientAirTemperature = curPlane.getParameter(part.ParameterTypes.Z_Ambien tAirTemperature, -1);

//Game Time
double dtime = Time.current();

//Log Header
if (done == false)
{
//Write Header
sw = fi.AppendText();
sw.WriteLine("TIME,HDG,ALT,IAS,ROC,TEMP");
sw.Close();
done = true;
}

//Log Data
str_log = dtime.ToString("0.00") + "," //TIME
I_MagneticCompass.ToString("0.00") + "," //HDG
I_Altitude.ToString("0.00") + "," //ALT
I_VelocityIAS.ToString("0.00") + "," //IAS
I_Variometer.ToString("0.00") + "," //ROC
Z_AmbientAirTemperature.ToString("0.00"); //TEMP

sw = fi.AppendText();
sw.WriteLine(str_log);
sw.Close();

//Display HUD
GamePlay.gpHUDLogCenter("TIME: " + dtime.ToString("0.00") + //TIME
" HDG: " + I_MagneticCompass.ToString("0.00") + //HDG
" ALT: " + I_Altitude.ToString("0.00") + //ALT
" IAS: " + I_VelocityIAS.ToString("0.00") + //IAS
" ROC: " + I_Variometer.ToString("0.00") + //ROC
" TEMP: " + Z_AmbientAirTemperature.ToString("0.00")); //TEMP
}
}
}
}

Roni86
Apr-05-2014, 08:56
Hi Jacko,

please find attached the revised code. In the org. code were some type mistache.


//-$debug
using System;
using System.Threading;
using System.Collections.Generic;
using maddox.game;
using maddox.game.world;
using maddox.GP;


public class Mission : AMission
{
//flag
bool done = false;

//Create Stream
System.IO.StreamWriter sw;

//Strings
string str_log = System.String.Empty;
string str_hud = System.String.Empty;

//Create Log File
System.IO.FileInfo fi = new System.IO.FileInfo("C:\\FLIGHT_TEST_DATA.CSV");

//Script Main
public override void OnTickGame()
{
//Init Ticker
base.OnTickGame();

//loop rate set to ~1/30th of a second, i.e. 30 ticks = ~1 second
if (Time.tickCounter() % 30 == 1)
{
//Get player aircraft
AiAircraft curPlane = GamePlay.gpPlayer().Place() as AiAircraft;

if (curPlane != null)
{
//Instrumentation - Machine Spatial
double I_VelocityIAS = curPlane.getParameter(part.ParameterTypes.I_Veloci tyIAS, -1);
double I_Altitude = curPlane.getParameter(part.ParameterTypes.I_Altitu de, -1);
double I_Variometer = curPlane.getParameter(part.ParameterTypes.I_Variom eter, -1);
double I_MagneticCompass = curPlane.getParameter(part.ParameterTypes.I_Magnet icCompass, -1);

//Parameters - Machine Spatial
double Z_Overload = curPlane.getParameter(part.ParameterTypes.Z_Overlo ad, -1);
double Z_AltitudeAGL = curPlane.getParameter(part.ParameterTypes.Z_Altitu deAGL, -1);
double Z_AltitudeMSL = curPlane.getParameter(part.ParameterTypes.Z_Altitu deMSL, -1);
double Z_VelocityIAS = curPlane.getParameter(part.ParameterTypes.Z_Veloci tyIAS, -1);
double Z_VelocityTAS = curPlane.getParameter(part.ParameterTypes.Z_Veloci tyTAS, -1);
double Z_VelocityMach = curPlane.getParameter(part.ParameterTypes.Z_Veloci tyMach, -1);
double Z_AmbientAirTemperature = curPlane.getParameter(part.ParameterTypes.Z_Ambien tAirTemperature, -1);

//Game Time
double dtime = Time.current();

//Log Header
if (done == false)
{
//Write Header
sw = fi.AppendText();
sw.WriteLine("TIME;HDG;ALT;IAS;ROC;TEMP");
sw.Close();
done = true;
}

//Log Data
str_log = dtime.ToString("0.00") + ";" + I_MagneticCompass.ToString("0.00") + ";"
+I_Altitude.ToString("0.00") + ";"
+I_VelocityIAS.ToString("0.00") + ";"
+I_Variometer.ToString("0.00") + ";"
+Z_AmbientAirTemperature.ToString("0.00"); //TEMP

sw = fi.AppendText();
sw.WriteLine(str_log);
sw.Close();

//Display HUD
GamePlay.gpHUDLogCenter("TIME: " + dtime.ToString("0.00") +
" HDG: " + I_MagneticCompass.ToString("0.00") +
" ALT: " + I_Altitude.ToString("0.00") +
" IAS: " + I_VelocityIAS.ToString("0.00") +
" ROC: " + I_Variometer.ToString("0.00") +
" TEMP: " + Z_AmbientAirTemperature.ToString("0.00"));
}
}
}
}


I've proved this script inside the FMB and it works.

Greeting
Roni

No1_Jacko
Apr-05-2014, 09:37
Greetings Roni,
Thanks for the quick reply.
It has cleared the errors but is not working so I will need to look deeper in this.
Cheers
Jacko

Roni86
Apr-05-2014, 10:44
Can you tell me what is the problem?

You have the .csv file in the specified path?

In my sample mission it works without a problem.

You find this simple sample attched.

Roni

No1_Jacko
Apr-05-2014, 13:33
Ahhh thanks the tip was I should have created the csv file as a blank because obviously it was only writing and not crerating the file in the first place.

Thanks again