30#include <simgear/scene/material/mat.hxx>
40 _interval(node->getDoubleValue(
"update-interval-sec", 1.0))
42 _name = node->getStringValue(
"name",
"radar-altimeter");
43 _num = node->getIntValue(
"number", 0);
54 std::string branch =
"/instrumentation/" + _name;
55 _Instrument =
fgGetNode(branch, _num,
true);
57 _sceneryLoaded =
fgGetNode(
"/sim/sceneryloaded",
true);
58 _serviceable_node = _Instrument->getNode(
"serviceable",
true);
60 _user_alt_agl_node =
fgGetNode(
"/position/altitude-agl-ft",
true);
61 _rad_alt_warning_node =
fgGetNode(
"/sim/alarms/rad-alt-warning",
true);
63 _Instrument->setFloatValue(
"tilt",-85);
64 _Instrument->setStringValue(
"status",
"RA");
66 _Instrument->getDoubleValue(
"elev-limit",
true);
67 _Instrument->getDoubleValue(
"elev-step-deg",
true);
68 _Instrument->getDoubleValue(
"az-limit-deg",
true);
69 _Instrument->getDoubleValue(
"az-step-deg",
true);
70 _Instrument->getDoubleValue(
"max-range-m",
true);
71 _Instrument->getDoubleValue(
"min-range-m",
true);
72 _Instrument->getDoubleValue(
"tilt",
true);
73 _Instrument->getDoubleValue(
"set-height-ft",
true);
74 _Instrument->getDoubleValue(
"set-excursion-percent",
true);
76 _antennaOffset = SGVec3d(_Instrument->getDoubleValue(
"antenna/x-offset-m"),
77 _Instrument->getDoubleValue(
"antenna/y-offset-m"),
78 _Instrument->getDoubleValue(
"antenna/z-offset-m"));
84 if (!_sceneryLoaded->getBoolValue())
87 if ( ! _serviceable_node->getBoolValue() ) {
88 _Instrument->setStringValue(
"status",
"");
92 _time += delta_time_sec;
93 if (_time < _interval)
103RadarAltimeter::getDistanceAntennaToHit(
const SGVec3d& nearestHit)
const
105 return norm(nearestHit - getCartAntennaPos());
109RadarAltimeter::updateSetHeight()
111 double set_ht_ft = _Instrument->getDoubleValue(
"set-height-ft", 9999);
112 double set_excur = _Instrument->getDoubleValue(
"set-excursion-percent", 0);
113 if (set_ht_ft == 9999) {
114 _rad_alt_warning_node->setIntValue(9999);
118 double radarAltFt = _min_radalt * SG_METER_TO_FEET;
119 if (radarAltFt < set_ht_ft * (100 - set_excur)/100)
120 _rad_alt_warning_node->setIntValue(-1);
121 else if (radarAltFt > set_ht_ft * (100 + set_excur)/100)
122 _rad_alt_warning_node->setIntValue(1);
124 _rad_alt_warning_node->setIntValue(0);
128RadarAltimeter::update_altitude()
130 double el_limit = _Instrument->getDoubleValue(
"elev-limit", 15);
131 double el_step = _Instrument->getDoubleValue(
"elev-step-deg", 15);
132 double az_limit = _Instrument->getDoubleValue(
"az-limit-deg", 15);
133 double az_step = _Instrument->getDoubleValue(
"az-step-deg", 15);
134 double max_range = _Instrument->getDoubleValue(
"max-range-m", 1500);
135 double min_range = _Instrument->getDoubleValue(
"min-range-m", 0.001);
138 _min_radalt = max_range;
139 bool haveHit =
false;
140 SGVec3d cartantennapos = getCartAntennaPos();
142 for(
double brg = -az_limit; brg <= az_limit; brg += az_step){
143 for(
double elev = el_limit; elev >= - el_limit; elev -= el_step){
144 SGVec3d userVec = rayVector(brg, elev);
148 double measuredDistance = dist(cartantennapos, nearestHit);
150 if (measuredDistance >= min_range && measuredDistance <= max_range) {
151 if (measuredDistance < _min_radalt) {
152 _min_radalt = measuredDistance;
159 _Instrument->setDoubleValue(
"radar-altitude-ft", _min_radalt * SG_METER_TO_FEET);
161 _rad_alt_warning_node->setIntValue(9999);
166RadarAltimeter::getCartAntennaPos()
const
168 double yaw, pitch, roll;
181 hlTrans *= SGQuatd::fromYawPitchRollDeg(yaw,pitch,roll);
185 SGVec3d ecfOffset = hlTrans.backTransform(_antennaOffset);
191SGVec3d RadarAltimeter::rayVector(
double az,
double el)
const
193 double yaw, pitch, roll;
196 double tilt = _Instrument->getDoubleValue(
"tilt");
197 bool roll_stab =
false,
200 SGQuatd offset = SGQuatd::fromYawPitchRollDeg(az, el + tilt, 0);
207 hlTrans *= SGQuatd::fromYawPitchRollDeg(yaw,
208 pitch_stab ? 0 :pitch,
209 roll_stab ? 0 : roll);
214 SGVec3d angleaxis(1,0,0);
215 return hlTrans.backTransform(angleaxis);
222SGSubsystemMgr::InstancedRegistrant<RadarAltimeter> registrantRadarAltimeter(
224 {{
"instrumentation", SGSubsystemMgr::Dependency::HARD}});
SGGeod get_aircraft_position() const
void get_aircraft_orientation(double &heading, double &pitch, double &roll)
SGVec3d get_aircraft_position_cart() const
FGScenery * get_scenery() const
bool get_cart_ground_intersection(const SGVec3d &start, const SGVec3d &dir, SGVec3d &nearestHit, const osg::Node *butNotFrom=0)
Compute the nearest intersection point of the line starting from start going in direction dir with th...
virtual ~RadarAltimeter()
RadarAltimeter(SGPropertyNode *node)
void update(double dt) override
SGPropertyNode * fgGetNode(const char *path, bool create)
Get a property node.