1 // FGAICarrier - FGAIShip-derived class creates an AI aircraft carrier
3 // Written by David Culp, started October 2004.
4 // - davidculp2@comcast.net
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License as
8 // published by the Free Software Foundation; either version 2 of the
9 // License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 #include <osg/Drawable>
30 #include <osg/Transform>
31 #include <osg/NodeVisitor>
32 #include <osg/TemplatePrimitiveFunctor>
34 #include <simgear/sg_inlines.h>
35 #include <simgear/math/SGMath.hxx>
36 #include <simgear/math/sg_geodesy.hxx>
37 #include <simgear/scene/util/SGNodeMasks.hxx>
38 #include <simgear/scene/util/SGSceneUserData.hxx>
39 #include <simgear/scene/bvh/BVHGroup.hxx>
40 #include <simgear/scene/bvh/BVHLineGeometry.hxx>
43 #include <Main/util.hxx>
44 #include <Main/viewer.hxx>
46 #include "AICarrier.hxx"
48 /// Hmm: move that kind of configuration into the model file???
49 class LineCollector : public osg::NodeVisitor {
50 struct LinePrimitiveFunctor {
51 LinePrimitiveFunctor() : _lineCollector(0)
53 void operator() (const osg::Vec3&, bool)
55 void operator() (const osg::Vec3& v1, const osg::Vec3& v2, bool)
56 { if (_lineCollector) _lineCollector->addLine(v1, v2); }
57 void operator() (const osg::Vec3&, const osg::Vec3&, const osg::Vec3&,
60 void operator() (const osg::Vec3&, const osg::Vec3&, const osg::Vec3&,
61 const osg::Vec3&, bool)
63 LineCollector* _lineCollector;
68 osg::NodeVisitor(osg::NodeVisitor::NODE_VISITOR,
69 osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
71 virtual void apply(osg::Geode& geode)
73 osg::TemplatePrimitiveFunctor<LinePrimitiveFunctor> pf;
74 pf._lineCollector = this;
75 for (unsigned i = 0; i < geode.getNumDrawables(); ++i) {
76 geode.getDrawable(i)->accept(pf);
79 virtual void apply(osg::Node& node)
83 virtual void apply(osg::Transform& transform)
85 osg::Matrix matrix = _matrix;
86 if (transform.computeLocalToWorldMatrix(_matrix, this))
91 const std::vector<SGLineSegmentf>& getLineSegments() const
92 { return _lineSegments; }
94 void addLine(const osg::Vec3& v1, const osg::Vec3& v2)
96 // Trick to get the ends in the right order.
97 // Use the x axis in the original coordinate system. Choose the
98 // most negative x-axis as the one pointing forward
99 SGVec3f tv1(_matrix.preMult(v1));
100 SGVec3f tv2(_matrix.preMult(v2));
102 _lineSegments.push_back(SGLineSegmentf(tv1, tv2));
104 _lineSegments.push_back(SGLineSegmentf(tv2, tv1));
107 void addBVHElements(osg::Node& node, simgear::BVHLineGeometry::Type type)
109 if (_lineSegments.empty())
112 SGSceneUserData* userData;
113 userData = SGSceneUserData::getOrCreateSceneUserData(&node);
115 simgear::BVHNode* bvNode = userData->getBVHNode();
116 if (!bvNode && _lineSegments.size() == 1) {
117 simgear::BVHLineGeometry* bvLine;
118 bvLine = new simgear::BVHLineGeometry(_lineSegments.front(), type);
119 userData->setBVHNode(bvLine);
123 simgear::BVHGroup* group = new simgear::BVHGroup;
125 group->addChild(bvNode);
127 for (unsigned i = 0; i < _lineSegments.size(); ++i) {
128 simgear::BVHLineGeometry* bvLine;
129 bvLine = new simgear::BVHLineGeometry(_lineSegments[i], type);
130 group->addChild(bvLine);
132 userData->setBVHNode(group);
137 std::vector<SGLineSegmentf> _lineSegments;
140 class FGCarrierVisitor : public osg::NodeVisitor {
142 FGCarrierVisitor(FGAICarrier* carrier,
143 const std::list<std::string>& wireObjects,
144 const std::list<std::string>& catapultObjects) :
145 osg::NodeVisitor(osg::NodeVisitor::NODE_VISITOR,
146 osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
147 mWireObjects(wireObjects),
148 mCatapultObjects(catapultObjects)
150 virtual void apply(osg::Node& node)
152 if (std::find(mWireObjects.begin(), mWireObjects.end(), node.getName())
153 != mWireObjects.end()) {
154 LineCollector lineCollector;
155 node.accept(lineCollector);
156 simgear::BVHLineGeometry::Type type;
157 type = simgear::BVHLineGeometry::CarrierWire;
158 lineCollector.addBVHElements(node, type);
160 if (std::find(mCatapultObjects.begin(), mCatapultObjects.end(),
161 node.getName()) != mCatapultObjects.end()) {
162 LineCollector lineCollector;
163 node.accept(lineCollector);
164 simgear::BVHLineGeometry::Type type;
165 type = simgear::BVHLineGeometry::CarrierCatapult;
166 lineCollector.addBVHElements(node, type);
173 std::list<std::string> mWireObjects;
174 std::list<std::string> mCatapultObjects;
177 FGAICarrier::FGAICarrier() : FGAIShip(otCarrier) {
180 FGAICarrier::~FGAICarrier() {
183 void FGAICarrier::readFromScenario(SGPropertyNode* scFileNode) {
187 FGAIShip::readFromScenario(scFileNode);
189 setRadius(scFileNode->getDoubleValue("turn-radius-ft", 2000));
190 setSign(scFileNode->getStringValue("pennant-number"));
191 setWind_from_east(scFileNode->getDoubleValue("wind_from_east", 0));
192 setWind_from_north(scFileNode->getDoubleValue("wind_from_north", 0));
193 setTACANChannelID(scFileNode->getStringValue("TACAN-channel-ID", "029Y"));
194 setMaxLat(scFileNode->getDoubleValue("max-lat", 0));
195 setMinLat(scFileNode->getDoubleValue("min-lat", 0));
196 setMaxLong(scFileNode->getDoubleValue("max-long", 0));
197 setMinLong(scFileNode->getDoubleValue("min-long", 0));
199 SGPropertyNode* flols = scFileNode->getChild("flols-pos");
201 // Transform to the right coordinate frame, configuration is done in
202 // the usual x-back, y-right, z-up coordinates, computations
203 // in the simulation usual body x-forward, y-right, z-down coordinates
204 flols_off(0) = - flols->getDoubleValue("x-offset-m", 0);
205 flols_off(1) = flols->getDoubleValue("y-offset-m", 0);
206 flols_off(2) = - flols->getDoubleValue("z-offset-m", 0);
208 flols_off = SGVec3d::zeros();
210 std::vector<SGPropertyNode_ptr> props = scFileNode->getChildren("wire");
211 std::vector<SGPropertyNode_ptr>::const_iterator it;
212 for (it = props.begin(); it != props.end(); ++it) {
213 std::string s = (*it)->getStringValue();
215 wire_objects.push_back(s);
218 props = scFileNode->getChildren("catapult");
219 for (it = props.begin(); it != props.end(); ++it) {
220 std::string s = (*it)->getStringValue();
222 catapult_objects.push_back(s);
225 props = scFileNode->getChildren("parking-pos");
226 for (it = props.begin(); it != props.end(); ++it) {
227 string name = (*it)->getStringValue("name", "unnamed");
228 // Transform to the right coordinate frame, configuration is done in
229 // the usual x-back, y-right, z-up coordinates, computations
230 // in the simulation usual body x-forward, y-right, z-down coordinates
231 double offset_x = -(*it)->getDoubleValue("x-offset-m", 0);
232 double offset_y = (*it)->getDoubleValue("y-offset-m", 0);
233 double offset_z = -(*it)->getDoubleValue("z-offset-m", 0);
234 double hd = (*it)->getDoubleValue("heading-offset-deg", 0);
235 ParkPosition pp(name, SGVec3d(offset_x, offset_y, offset_z), hd);
236 ppositions.push_back(pp);
240 void FGAICarrier::setWind_from_east(double fps) {
241 wind_from_east = fps;
244 void FGAICarrier::setWind_from_north(double fps) {
245 wind_from_north = fps;
248 void FGAICarrier::setMaxLat(double deg) {
252 void FGAICarrier::setMinLat(double deg) {
256 void FGAICarrier::setMaxLong(double deg) {
257 max_long = fabs(deg);
260 void FGAICarrier::setMinLong(double deg) {
261 min_long = fabs(deg);
264 void FGAICarrier::setSign(const string& s) {
268 void FGAICarrier::setTACANChannelID(const string& id) {
269 TACAN_channel_id = id;
272 void FGAICarrier::update(double dt) {
273 // For computation of rotation speeds we just use finite differences here.
274 // That is perfectly valid since this thing is not driven by accelerations
275 // but by just apply discrete changes at its velocity variables.
276 // Update the velocity information stored in those nodes.
277 // Transform that one to the horizontal local coordinate system.
278 SGQuatd ec2hl = SGQuatd::fromLonLat(pos);
279 // The orientation of the carrier wrt the horizontal local frame
280 SGQuatd hl2body = SGQuatd::fromYawPitchRollDeg(hdg, pitch, roll);
281 // and postrotate the orientation of the AIModel wrt the horizontal
283 SGQuatd ec2body = ec2hl*hl2body;
284 // The cartesian position of the carrier in the wgs84 world
285 SGVec3d cartPos = SGVec3d::fromGeod(pos);
287 // Compute the velocity in m/s in the body frame
288 aip.setBodyLinearVelocity(SGVec3d(0.51444444*speed, 0, 0));
290 // Now update the position and heading. This will compute new hdg and
291 // roll values required for the rotation speed computation.
292 FGAIShip::update(dt);
295 //automatic turn into wind with a target wind of 25 kts otd
296 if(turn_to_launch_hdg){
298 } else if(OutsideBox() || returning) {// check that the carrier is inside the operating box
304 // Only change these values if we are able to compute them safely
305 if (SGLimits<double>::min() < dt) {
306 // Now here is the finite difference ...
308 // Transform that one to the horizontal local coordinate system.
309 SGQuatd ec2hlNew = SGQuatd::fromLonLat(pos);
310 // compute the new orientation
311 SGQuatd hl2bodyNew = SGQuatd::fromYawPitchRollDeg(hdg, pitch, roll);
312 // The rotation difference
313 SGQuatd dOr = inverse(ec2body)*ec2hlNew*hl2bodyNew;
314 SGVec3d dOrAngleAxis;
315 dOr.getAngleAxis(dOrAngleAxis);
316 // divided by the time difference provides a rotation speed vector
319 aip.setBodyAngularVelocity(dOrAngleAxis);
323 UpdateElevator(dt, transition_time);
324 UpdateJBD(dt, jbd_transition_time);
325 // For the flols reuse some computations done above ...
327 // The position of the eyepoint - at least near that ...
328 SGVec3d eyePos(globals->get_current_view()->get_view_pos());
329 // Add the position offset of the AIModel to gain the earth
331 SGVec3d eyeWrtCarrier = eyePos - cartPos;
332 // rotate the eyepoint wrt carrier vector into the carriers frame
333 eyeWrtCarrier = ec2body.transform(eyeWrtCarrier);
334 // the eyepoints vector wrt the flols position
335 SGVec3d eyeWrtFlols = eyeWrtCarrier - flols_off;
337 // the distance from the eyepoint to the flols
338 dist = norm(eyeWrtFlols);
340 // now the angle, positive angles are upwards
341 if (fabs(dist) < SGLimits<float>::min()) {
344 double sAngle = -eyeWrtFlols(2)/dist;
345 sAngle = SGMiscd::min(1, SGMiscd::max(-1, sAngle));
346 angle = SGMiscd::rad2deg(asin(sAngle));
349 // set the value of source
350 if ( angle <= 4.35 && angle > 4.01 )
352 else if ( angle <= 4.01 && angle > 3.670 )
354 else if ( angle <= 3.670 && angle > 3.330 )
356 else if ( angle <= 3.330 && angle > 2.990 )
358 else if ( angle <= 2.990 && angle > 2.650 )
360 else if ( angle <= 2.650 )
366 bool FGAICarrier::init(bool search_in_AI_path) {
367 if (!FGAIShip::init(search_in_AI_path))
370 _longitude_node = fgGetNode("/position/longitude-deg", true);
371 _latitude_node = fgGetNode("/position/latitude-deg", true);
372 _altitude_node = fgGetNode("/position/altitude-ft", true);
374 _launchbar_state_node = fgGetNode("/gear/launchbar/state", true);
376 _surface_wind_from_deg_node =
377 fgGetNode("/environment/config/boundary/entry[0]/wind-from-heading-deg", true);
378 _surface_wind_speed_node =
379 fgGetNode("/environment/config/boundary/entry[0]/wind-speed-kt", true);
382 turn_to_launch_hdg = false;
391 transition_time = 150;
392 time_constant = 0.005;
393 jbd_pos_norm = raw_jbd_pos_norm = 0;
395 jbd_transition_time = 3;
396 jbd_time_constant = 0.1;
400 void FGAICarrier::initModel(osg::Node *node)
402 // SG_LOG(SG_GENERAL, SG_BULK, "AICarrier::initModel()" );
403 FGAIShip::initModel(node);
404 // process the 3d model here
405 // mark some objects solid, mark the wires ...
406 FGCarrierVisitor carrierVisitor(this, wire_objects, catapult_objects);
407 model->accept(carrierVisitor);
408 model->setNodeMask(model->getNodeMask() | SG_NODEMASK_TERRAIN_BIT);
411 void FGAICarrier::bind() {
414 props->untie("velocities/true-airspeed-kt");
416 props->tie("controls/flols/source-lights",
417 SGRawValuePointer<int>(&source));
418 props->tie("controls/flols/distance-m",
419 SGRawValuePointer<double>(&dist));
420 props->tie("controls/flols/angle-degs",
421 SGRawValuePointer<double>(&angle));
422 props->tie("controls/turn-to-launch-hdg",
423 SGRawValuePointer<bool>(&turn_to_launch_hdg));
424 props->tie("controls/in-to-wind",
425 SGRawValuePointer<bool>(&turn_to_launch_hdg));
426 props->tie("controls/base-course-deg",
427 SGRawValuePointer<double>(&base_course));
428 props->tie("controls/base-speed-kts",
429 SGRawValuePointer<double>(&base_speed));
430 props->tie("controls/start-pos-lat-deg",
431 SGRawValueMethods<SGGeod,double>(pos, &SGGeod::getLatitudeDeg));
432 props->tie("controls/start-pos-long-deg",
433 SGRawValueMethods<SGGeod,double>(pos, &SGGeod::getLongitudeDeg));
434 props->tie("velocities/speed-kts",
435 SGRawValuePointer<double>(&speed));
436 props->tie("environment/surface-wind-speed-true-kts",
437 SGRawValuePointer<double>(&wind_speed_kts));
438 props->tie("environment/surface-wind-from-true-degs",
439 SGRawValuePointer<double>(&wind_from_deg));
440 props->tie("environment/rel-wind-from-degs",
441 SGRawValuePointer<double>(&rel_wind_from_deg));
442 props->tie("environment/rel-wind-from-carrier-hdg-degs",
443 SGRawValuePointer<double>(&rel_wind));
444 props->tie("environment/rel-wind-speed-kts",
445 SGRawValuePointer<double>(&rel_wind_speed_kts));
446 props->tie("controls/flols/wave-off-lights",
447 SGRawValuePointer<bool>(&wave_off_lights));
448 props->tie("controls/elevators",
449 SGRawValuePointer<bool>(&elevators));
450 props->tie("surface-positions/elevators-pos-norm",
451 SGRawValuePointer<double>(&pos_norm));
452 props->tie("controls/elevators-trans-time-s",
453 SGRawValuePointer<double>(&transition_time));
454 props->tie("controls/elevators-time-constant",
455 SGRawValuePointer<double>(&time_constant));
456 props->tie("controls/jbd",
457 SGRawValuePointer<bool>(&jbd));
458 props->tie("surface-positions/jbd-pos-norm",
459 SGRawValuePointer<double>(&jbd_pos_norm));
460 props->tie("controls/jbd-trans-time-s",
461 SGRawValuePointer<double>(&jbd_transition_time));
462 props->tie("controls/jbd-time-constant",
463 SGRawValuePointer<double>(&jbd_time_constant));
465 props->setBoolValue("controls/flols/cut-lights", false);
466 props->setBoolValue("controls/flols/wave-off-lights", false);
467 props->setBoolValue("controls/flols/cond-datum-lights", true);
468 props->setBoolValue("controls/crew", false);
469 props->setStringValue("navaids/tacan/channel-ID", TACAN_channel_id.c_str());
470 props->setStringValue("sign", sign.c_str());
471 props->setBoolValue("controls/lighting/deck-lights", false);
472 props->setDoubleValue("controls/lighting/flood-lights-red-norm", 0);
476 void FGAICarrier::unbind() {
479 props->untie("velocities/true-airspeed-kt");
480 props->untie("controls/flols/source-lights");
481 props->untie("controls/flols/distance-m");
482 props->untie("controls/flols/angle-degs");
483 props->untie("controls/turn-to-launch-hdg");
484 props->untie("velocities/speed-kts");
485 props->untie("environment/wind-speed-true-kts");
486 props->untie("environment/wind-from-true-degs");
487 props->untie("environment/rel-wind-from-degs");
488 props->untie("environment/rel-wind-speed-kts");
489 props->untie("controls/flols/wave-off-lights");
490 props->untie("controls/elevators");
491 props->untie("surface-positions/elevators-pos-norm");
492 props->untie("controls/elevators-trans-time-secs");
493 props->untie("controls/elevators-time-constant");
494 props->untie("controls/jbd");
495 props->untie("surface-positions/jbd-pos-norm");
496 props->untie("controls/jbd-trans-time-s");
497 props->untie("controls/jbd-time-constant");
502 bool FGAICarrier::getParkPosition(const string& id, SGGeod& geodPos,
503 double& hdng, SGVec3d& uvw)
506 // FIXME: does not yet cover rotation speeds.
507 list<ParkPosition>::iterator it = ppositions.begin();
508 while (it != ppositions.end()) {
509 // Take either the specified one or the first one ...
510 if ((*it).name == id || id.empty()) {
511 ParkPosition ppos = *it;
512 SGVec3d cartPos = getCartPosAt(ppos.offset);
513 geodPos = SGGeod::fromCart(cartPos);
514 hdng = hdg + ppos.heading_deg;
515 double shdng = sin(ppos.heading_deg * SGD_DEGREES_TO_RADIANS);
516 double chdng = cos(ppos.heading_deg * SGD_DEGREES_TO_RADIANS);
517 double speed_fps = speed*1.6878099;
518 uvw = SGVec3d(chdng*speed_fps, shdng*speed_fps, 0);
527 // find relative wind
528 void FGAICarrier::UpdateWind( double dt) {
530 //get the surface wind speed and direction
531 wind_from_deg = _surface_wind_from_deg_node->getDoubleValue();
532 wind_speed_kts = _surface_wind_speed_node->getDoubleValue();
534 //calculate the surface wind speed north and east in kts
535 double wind_speed_from_north_kts = cos( wind_from_deg / SGD_RADIANS_TO_DEGREES )* wind_speed_kts ;
536 double wind_speed_from_east_kts = sin( wind_from_deg / SGD_RADIANS_TO_DEGREES )* wind_speed_kts ;
538 //calculate the carrier speed north and east in kts
539 double speed_north_kts = cos( hdg / SGD_RADIANS_TO_DEGREES )* speed ;
540 double speed_east_kts = sin( hdg / SGD_RADIANS_TO_DEGREES )* speed ;
542 //calculate the relative wind speed north and east in kts
543 double rel_wind_speed_from_east_kts = wind_speed_from_east_kts + speed_east_kts;
544 double rel_wind_speed_from_north_kts = wind_speed_from_north_kts + speed_north_kts;
546 //combine relative speeds north and east to get relative windspeed in kts
547 rel_wind_speed_kts = sqrt((rel_wind_speed_from_east_kts * rel_wind_speed_from_east_kts)
548 + (rel_wind_speed_from_north_kts * rel_wind_speed_from_north_kts));
550 //calculate the relative wind direction
551 rel_wind_from_deg = atan2(rel_wind_speed_from_east_kts, rel_wind_speed_from_north_kts)
552 * SG_RADIANS_TO_DEGREES;
555 rel_wind = rel_wind_from_deg - hdg;
556 SG_NORMALIZE_RANGE(rel_wind, -180.0, 180.0);
558 //switch the wave-off lights
560 wave_off_lights = false;
562 wave_off_lights = true;
564 // cout << "rel wind: " << rel_wind << endl;
569 void FGAICarrier::TurnToLaunch(){
571 //calculate tgt speed
572 double tgt_speed = 25 - wind_speed_kts;
577 FGAIShip::TurnTo(wind_from_deg);
578 FGAIShip::AccelTo(tgt_speed);
583 void FGAICarrier::TurnToBase(){
586 FGAIShip::TurnTo(base_course);
587 FGAIShip::AccelTo(base_speed);
592 void FGAICarrier::ReturnToBox(){
593 double course, distance, az2;
595 //calculate the bearing and range of the initial position from the carrier
596 geo_inverse_wgs_84(pos, mOpBoxPos, &course, &az2, &distance);
598 distance *= SG_METER_TO_NM;
600 //cout << "return course: " << course << " distance: " << distance << endl;
602 FGAIShip::TurnTo(course);
603 FGAIShip::AccelTo(base_speed);
610 } // end turn to base
613 bool FGAICarrier::OutsideBox() { //returns true if the carrier is outside operating box
615 if ( max_lat == 0 && min_lat == 0 && max_long == 0 && min_long == 0) {
616 SG_LOG(SG_GENERAL, SG_DEBUG, "AICarrier: No Operating Box defined" );
620 if (mOpBoxPos.getLatitudeDeg() >= 0) { //northern hemisphere
621 if (pos.getLatitudeDeg() >= mOpBoxPos.getLatitudeDeg() + max_lat)
624 if (pos.getLatitudeDeg() <= mOpBoxPos.getLatitudeDeg() - min_lat)
627 } else { //southern hemisphere
628 if (pos.getLatitudeDeg() <= mOpBoxPos.getLatitudeDeg() - max_lat)
631 if (pos.getLatitudeDeg() >= mOpBoxPos.getLatitudeDeg() + min_lat)
635 if (mOpBoxPos.getLongitudeDeg() >=0) { //eastern hemisphere
636 if (pos.getLongitudeDeg() >= mOpBoxPos.getLongitudeDeg() + max_long)
639 if (pos.getLongitudeDeg() <= mOpBoxPos.getLongitudeDeg() - min_long)
642 } else { //western hemisphere
643 if (pos.getLongitudeDeg() <= mOpBoxPos.getLongitudeDeg() - max_long)
646 if (pos.getLongitudeDeg() >= mOpBoxPos.getLongitudeDeg() + min_long)
650 SG_LOG(SG_GENERAL, SG_DEBUG, "AICarrier: Inside Operating Box" );
656 bool FGAICarrier::InToWind() {
657 if ( fabs(rel_wind) < 5 )
664 void FGAICarrier::UpdateElevator(double dt, double transition_time) {
668 if ((elevators && pos_norm >= 1 ) || (!elevators && pos_norm <= 0 ))
671 // move the elevators
673 step = dt/transition_time;
677 step = -dt/transition_time;
681 // assume a linear relationship
682 raw_pos_norm += step;
685 pos_norm = (raw_pos_norm * time_constant) + (pos_norm * (1 - time_constant));
687 //sanitise the output
688 if (raw_pos_norm >= 1) {
690 } else if (raw_pos_norm <= 0) {
695 } // end UpdateElevator
697 void FGAICarrier::UpdateJBD(double dt, double jbd_transition_time) {
699 string launchbar_state = _launchbar_state_node->getStringValue();
702 if (launchbar_state == "Engaged"){
708 if (( jbd && jbd_pos_norm >= 1 ) || ( !jbd && jbd_pos_norm <= 0 )){
714 step = dt/jbd_transition_time;
718 step = -dt/jbd_transition_time;
723 // assume a linear relationship
724 raw_jbd_pos_norm += step;
727 jbd_pos_norm = (raw_jbd_pos_norm * jbd_time_constant) + (jbd_pos_norm * (1 - jbd_time_constant));
729 //sanitise the output
730 if (jbd_pos_norm >= 1) {
732 } else if (jbd_pos_norm <= 0) {