1 /*
2  * CRRCsim - the Charles River Radio Control Club Flight Simulator Project
3  *   Copyright (C) 2008 - 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 "controller.h"
21 
22 #include <iostream>
23 
24 #include "cntrl_initinputs/cntrl_initinputs.h"
25 #include "cntrl_rateofclimb/cntrl_rateofclimb.h"
26 #include "cntrl_phugoid/cntrl_phugoid.h"
27 #include "cntrl_setuserinput/cntrl_setuserinput.h"
28 #include "cntrl_omega/cntrl_omega.h"
29 #include "cntrl_mcopter01/cntrl_mcopter01.h"
30 #include "cntrl_scalethrottle/scalethrottle.h"
31 #include "cntrl_limitflipthr/limitflipthrottle.h"
32 
33 
LoadList(SimpleXMLTransfer * cfg,std::vector<Controller * > & controllers)34 void Controller::LoadList(SimpleXMLTransfer*       cfg,
35                           std::vector<Controller*> &controllers)
36 {
37   try
38   {
39     SimpleXMLTransfer* cntrldescr;
40     Controller*        cntrl;
41     std::string name;
42     for (int n=0; n<cfg->getChildCount(); n++)
43     {
44       cntrldescr = cfg->getChildAt(n);
45       name       = cntrldescr->getName();
46       cntrl      = 0;
47       /*
48        * MNav is not converted to this structure yet but should be...
49       if (name.compare("MNAV") == 0)
50         cntrl = new Cntrl_MNAV(cntrldescr);
51       else */
52       if (name.compare("InitInputs") == 0)
53         cntrl = new Cntrl_InitInputs(cntrldescr);
54       else if (name.compare("SetUserInput") == 0)
55         cntrl = new Cntrl_SetUserInput(cntrldescr);
56       else if (name.compare("RateOfClimb") == 0)
57         cntrl = new Cntrl_RateOfClimb(cntrldescr);
58       else if (name.compare("Phugoid") == 0)
59         cntrl = new Cntrl_Phugoid(cntrldescr);
60       else if (name.compare("Omega") == 0)
61         cntrl = new Cntrl_Omega(cntrldescr);
62       else if (name.compare("MCopter01") == 0)
63         cntrl = new Cntrl_MCopter01(cntrldescr);
64       else if (name.compare("ScaleThrottle") == 0)
65         cntrl = new Cntrl_ScaleThrottle(cntrldescr);
66       else if (name.compare("LimitFlipThrottle") == 0)
67         cntrl = new Cntrl_LimitFlipThrottle(cntrldescr);
68 
69       if (cntrl)
70         controllers.push_back(cntrl);
71     }
72   }
73   catch (XMLException e)
74   {
75     std::cerr << "XMLException when initializing controllers: " << e.what() << "\n";
76   }
77 }
78 
Limit(float & flVal)79 int Controller::Limit(float &flVal)
80 {
81   if (flVal > 0.5)
82   {
83     flVal = 0.5;
84     return(1);
85   }
86   else if (flVal < -0.5)
87   {
88     flVal = -0.5;
89     return(-1);
90   }
91   else
92     return(0);
93 }
94