40#include "FGMagnetometer.h"
41#include "simgear/magvar/coremag.hxx"
42#include "models/FGFCS.h"
43#include "models/FGMassBalance.h"
54FGMagnetometer::FGMagnetometer(FGFCS* fcs, Element* element)
55 : FGSensor(fcs, element),
56 FGSensorOrientation(element),
57 counter(0), INERTIAL_UPDATE_RATE(1000)
59 Propagate = fcs->GetExec()->GetPropagate();
60 MassBalance = fcs->GetExec()->GetMassBalance();
61 Inertial = fcs->GetExec()->GetInertial();
63 Element* location_element = element->FindElement(
"location");
65 vLocation = location_element->FindElementTripletConvertTo(
"IN");
67 XMLLogException err(element);
68 err <<
"No location given for magnetometer.\n";
72 vRadius = MassBalance->StructuralToBody(vLocation);
79 #if defined(_MSC_VER) || defined(__MINGW32__)
80 gmtime_s(&ptm, &rawtime);
82 gmtime_r(&rawtime, &ptm);
85 int year = ptm.tm_year;
91 date = (yymmdd_to_julian_days(ptm.tm_year, ptm.tm_mon, ptm.tm_mday));
98FGMagnetometer::~FGMagnetometer()
105void FGMagnetometer::ResetPastStates(
void)
107 FGSensor::ResetPastStates();
113void FGMagnetometer::updateInertialMag(
void)
115 if (counter++ % INERTIAL_UPDATE_RATE == 0)
117 usedLat = (Propagate->GetGeodLatitudeRad());
118 usedLon = (Propagate->GetLongitude());
119 usedAlt = (Propagate->GetGeodeticAltitude()*fttom*0.001);
122 calc_magvar( usedLat, usedLon, usedAlt, date, field );
128bool FGMagnetometer::Run(
void )
132 vRadius = MassBalance->StructuralToBody(vLocation);
137 vMag = Propagate->GetTl2b() * FGColumnVector3(field[3], field[4], field[5]);
144 ProcessSensorSignal();
170void FGMagnetometer::Debug(
int from)
172 string ax[4] = {
"none",
"X",
"Y",
"Z"};
174 if (debug_lvl <= 0)
return;
177 FGLogging log(LogLevel::DEBUG);
179 log <<
" Axis: " << ax[axis] <<
"\n";
182 if (debug_lvl & 2 ) {
183 FGLogging log(LogLevel::DEBUG);
184 if (from == 0) log <<
"Instantiated: FGMagnetometer\n";
185 if (from == 1) log <<
"Destroyed: FGMagnetometer\n";
187 if (debug_lvl & 4 ) {
189 if (debug_lvl & 8 ) {
191 if (debug_lvl & 16) {
193 if (debug_lvl & 64) {
Main namespace for the JSBSim Flight Dynamics Model.