1 /*
2 * Crrcsim - the Charles River Radio Control Club Flight Simulator Project
3 * Copyright (C) 2009 - Jens Wilhelm Wulf (original author)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330,
17 * Boston, MA 02111-1307, USA.
18 *
19 */
20 #include "limitflipthrottle.h"
21
Cntrl_LimitFlipThrottle(SimpleXMLTransfer * cfg)22 Cntrl_LimitFlipThrottle::Cntrl_LimitFlipThrottle(SimpleXMLTransfer* cfg)
23 {
24 max90 = cfg->getDouble("max90");
25 max180 = cfg->getDouble("max180");
26 }
27
~Cntrl_LimitFlipThrottle()28 Cntrl_LimitFlipThrottle::~Cntrl_LimitFlipThrottle()
29 {
30 }
31
Calc(double dt,FDMBase * fdm,TSimInputs * pInputsFromUser,TSimInputs * pInputsToFDM)32 void Cntrl_LimitFlipThrottle::Calc(double dt,
33 FDMBase* fdm,
34 TSimInputs* pInputsFromUser,
35 TSimInputs* pInputsToFDM)
36 {
37 CRRCMath::Vector3 diff = CRRCMath::Vector3(0, 0, 1) - fdm->WorldToBody(CRRCMath::Vector3(0, 0, 1));
38 double qdiff = diff.r[0]*diff.r[0] + diff.r[1]*diff.r[1] + diff.r[2]*diff.r[2];
39 double max = 1; // assume no limit
40
41 if (qdiff > 2) // at least 90°
42 {
43 max = max90 + (qdiff-2)/2*(max180-max90);
44 }
45 else if (qdiff > 1) // more than 60°, but less than 90°
46 {
47 max = 1 + (qdiff-1)*(max90-1);
48 }
49
50 if (pInputsToFDM->throttle > max)
51 pInputsToFDM->throttle = max;
52 }
53