1 // autobrake.cxx - generic, configurable autobrake system
3 // Written by James Turner, started September 2009.
5 // Copyright (C) 2009 Curtis L. Olson
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include "autobrake.hxx"
25 #include <Main/fg_props.hxx>
27 FGAutoBrake::FGAutoBrake() :
28 _lastGroundspeedKts(0.0),
35 _fcsBrakeControl(0.0),
36 _leftBrakeOutput(0.0),
37 _rightBrakeOutput(0.0)
39 // default config, close to Boeing 747-400 / 777 values
42 _configMaxDecel = 11; // ft-sec-sec
43 _configRTODecel = 11; // ft-sec-sec
44 _configRTOSpeed = 85; // kts
47 FGAutoBrake::~FGAutoBrake()
51 void FGAutoBrake::init()
53 _root = fgGetNode("/autopilot/autobrake", true);
55 _root->tie("armed", SGRawValueMethods<FGAutoBrake, bool>
56 (*this, &FGAutoBrake::getArmed, &FGAutoBrake::setArmed));
58 _root->tie("step", SGRawValueMethods<FGAutoBrake, int>
59 (*this, &FGAutoBrake::getStep, &FGAutoBrake::setStep));
61 _root->tie("rto", SGRawValueMethods<FGAutoBrake, bool>
62 (*this, &FGAutoBrake::getRTO, &FGAutoBrake::setRTO));
64 _engineControlsNode = fgGetNode("/controls/engines");
66 // brake position nodes
67 _brakeInputs[0] = fgGetNode("/controls/gear/brake-left");
68 _brakeInputs[1] = fgGetNode("/controls/gear/brake-right");
69 _brakeInputs[2] = fgGetNode("/controls/gear/copilot-brake-left");
70 _brakeInputs[3] = fgGetNode("/controls/gear/copilot-brake-right");
73 SGPropertyNode_ptr config = _root->getChild("config", 0, true);
74 config->tie("num-steps", SGRawValuePointer<int>(&_configNumSteps));
75 config->tie("rto-step", SGRawValuePointer<int>(&_configRTOStep));
76 config->tie("rto-decel-fts-sec", SGRawValuePointer<double>(&_configRTODecel));
77 config->tie("max-decel-fts-sec", SGRawValuePointer<double>(&_configMaxDecel));
78 config->tie("rto-engage-kts", SGRawValuePointer<double>(&_configRTOSpeed));
81 _root->tie("target-decel-fts-sec",
82 SGRawValueMethods<FGAutoBrake,double>(*this, &FGAutoBrake::getTargetDecel));
83 _root->tie("actual-decel-fts-sec",
84 SGRawValueMethods<FGAutoBrake,double>(*this, &FGAutoBrake::getActualDecel));
85 _root->tie("fcs-brake", SGRawValuePointer<double>(&_fcsBrakeControl));
86 _root->tie("brake-left-output", SGRawValuePointer<double>(&_leftBrakeOutput));
87 _root->tie("brake-right-output", SGRawValuePointer<double>(&_rightBrakeOutput));
89 _root->tie("engaged", SGRawValueMethods<FGAutoBrake, bool>(*this, &FGAutoBrake::getEngaged));
92 void FGAutoBrake::postinit()
94 _weightOnWheelsNode = fgGetNode("/gear/gear/wow");
95 _groundspeedNode = fgGetNode("/velocities/groundspeed-kt");
96 _lastWoW = _weightOnWheelsNode->getBoolValue();
100 void FGAutoBrake::bind()
104 void FGAutoBrake::unbind()
108 void FGAutoBrake::update(double dt)
114 double gs = _groundspeedNode->getDoubleValue();
115 _actualDecel = (_lastGroundspeedKts - gs) / dt;
116 _lastGroundspeedKts = gs;
118 _leftBrakeInput = SGMiscd::max(_brakeInputs[0]->getDoubleValue(),
119 _brakeInputs[2]->getDoubleValue());
120 _rightBrakeInput = SGMiscd::max(_brakeInputs[1]->getDoubleValue(),
121 _brakeInputs[3]->getDoubleValue());
123 if (!_armed || (_step == 0)) {
124 // even if we're off or disarmed, the physical valve system must pass
125 // pilot control values through.
126 _leftBrakeOutput = _leftBrakeInput;
127 _rightBrakeOutput = _rightBrakeInput;
134 bool e = shouldEngage();
141 // sum pilot inpiuts with auto-brake FCS input
142 _leftBrakeOutput = SGMiscd::max(_leftBrakeInput, _fcsBrakeControl);
143 _rightBrakeOutput = SGMiscd::max(_rightBrakeInput, _fcsBrakeControl);
145 _lastWoW = _weightOnWheelsNode->getBoolValue();
148 void FGAutoBrake::engage()
150 SG_LOG(SG_AUTOPILOT, SG_INFO, "FGAutoBrake: engaging");
154 void FGAutoBrake::updateEngaged(double dt)
156 // check for pilot braking input cancelling engage
157 const double BRAKE_INPUT_THRESHOLD = 0.02; // 2% application triggers
158 if ((_leftBrakeInput > BRAKE_INPUT_THRESHOLD) || (_rightBrakeInput > BRAKE_INPUT_THRESHOLD)) {
159 SG_LOG(SG_AUTOPILOT, SG_INFO, "auto-brake, detected pilot brake input, disengaing");
164 // update the target deceleration; note step can be changed while engaged
166 _targetDecel = _configRTODecel;
168 double f = (double) _step / _configNumSteps;
169 _targetDecel = _configMaxDecel * f;
173 bool FGAutoBrake::shouldEngage()
176 return shouldEngageRTO();
179 if (_lastWoW || !_weightOnWheelsNode->getBoolValue()) {
183 SG_LOG(SG_AUTOPILOT, SG_INFO, "Autobrake, should enage");
187 bool FGAutoBrake::shouldEngageRTO()
189 double speed = _groundspeedNode->getDoubleValue();
192 if (speed < _configRTOSpeed) {
193 SG_LOG(SG_AUTOPILOT, SG_INFO, "FGAutoBrake: RTO armed, but speed is now below arming speed");
198 if (!_weightOnWheelsNode->getBoolValue()) {
202 return throttlesAtIdle();
205 if (speed > _configRTOSpeed) {
206 SG_LOG(SG_AUTOPILOT, SG_INFO, "Autobrake RTO: passed " << _configRTOSpeed << " knots, arming RTO mode");
214 void FGAutoBrake::disengage()
220 SG_LOG(SG_AUTOPILOT, SG_INFO, "FGAutoBrake: disengage");
227 bool FGAutoBrake::throttlesAtIdle()
229 SGPropertyNode_ptr e;
230 const double IDLE_THROTTLE = 0.05; // 5% margin for idle setting
232 for (int index=0; (e = _engineControlsNode->getChild("engine", index)) != NULL; ++index) {
233 if ((e->getDoubleValue("throttle") > IDLE_THROTTLE) && !e->getBoolValue("reverser")) {
236 } // of engines iteration
238 SG_LOG(SG_AUTOPILOT, SG_INFO, "FGAutoBrake: throttles at idle");
242 void FGAutoBrake::setArmed(bool aArmed)
244 if (aArmed == _armed) {
252 void FGAutoBrake::setRTO(bool aRTO)
255 // ensure we meet RTO selection criteria:
256 if (!_weightOnWheelsNode->getBoolValue()) {
257 SG_LOG(SG_AUTOPILOT, SG_WARN, "auto-brake: cannot select RTO mode, no weight on wheels");
263 _step = _configRTOStep;
265 SG_LOG(SG_AUTOPILOT, SG_INFO, "RTO mode set");
269 // and if we're enaged?
274 void FGAutoBrake::setStep(int aStep)
276 if (aStep == _step) {
280 SG_LOG(SG_AUTOPILOT, SG_INFO, "Autobrake step now=" << aStep);
282 bool validStep = false;
284 if (aStep == _configRTOStep) {
289 validStep = (_step > 0) && (_step <= _configNumSteps);
292 setArmed(validStep); // selecting a valid step arms the system