JSBSim Flight Dynamics Model  1.1.11 (13 Feb 2022)
An Open Source Flight Dynamics and Control Software Library in C++
FGFCSChannel.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 
3  Header: FGGFCSChannel.h
4  Author: Jon S. Berndt
5  Date started: 10/11/12
6 
7  ------------- Copyright (C) 2012 Jon S. Berndt (jon@jsbsim.org) -------------
8 
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
17  details.
18 
19  You should have received a copy of the GNU Lesser General Public License along with
20  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21  Place - Suite 330, Boston, MA 02111-1307, USA.
22 
23  Further information about the GNU Lesser General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25 
26 HISTORY
27 --------------------------------------------------------------------------------
28 10/11/12 JSB Created
29 
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 SENTRY
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
33 
34 #ifndef FGFCSCHANNEL_H
35 #define FGFCSCHANNEL_H
36 
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40 
41 #include <iostream>
42 
43 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 FORWARD DECLARATIONS
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
46 
47 namespace JSBSim {
48 
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 CLASS DOCUMENTATION
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52 
66 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 CLASS DECLARATION
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
69 
70 typedef std::vector <FGFCSComponent*> FCSCompVec;
71 
72 class FGFCSChannel {
73 public:
75  FGFCSChannel(FGFCS* FCS, const std::string &name, int execRate,
76  FGPropertyNode* node=0)
77  : fcs(FCS), OnOffNode(node), Name(name)
78  {
79  ExecRate = execRate < 1 ? 1 : execRate;
80  // Set ExecFrameCountSinceLastRun so that each components are initialized
81  ExecFrameCountSinceLastRun = ExecRate;
82  }
83 
86  for (unsigned int i=0; i<FCSComponents.size(); i++) delete FCSComponents[i];
87  FCSComponents.clear();
88  }
90  std::string GetName() {return Name;}
91 
93  void Add(FGFCSComponent* comp) {
94  FCSComponents.push_back(comp);
95  }
97  size_t GetNumComponents() {return FCSComponents.size();}
99  FGFCSComponent* GetComponent(unsigned int i) {
100  if (i >= GetNumComponents()) {
101  std::cerr << "Tried to get nonexistent component" << std::endl;
102  return 0;
103  } else {
104  return FCSComponents[i];
105  }
106  }
108  void Reset() {
109  for (unsigned int i=0; i<FCSComponents.size(); i++)
110  FCSComponents[i]->ResetPastStates();
111 
112  // Set ExecFrameCountSinceLastRun so that each components are initialized
113  // after a reset.
114  ExecFrameCountSinceLastRun = ExecRate;
115  }
117  void Execute() {
118  // If there is an on/off property supplied for this channel, check
119  // the value. If it is true, permit execution to continue. If not, return
120  // and do not execute the channel.
121  if (OnOffNode && !OnOffNode->getBoolValue()) return;
122 
123  if (fcs->GetDt() != 0.0) {
124  if (ExecFrameCountSinceLastRun >= ExecRate) {
125  ExecFrameCountSinceLastRun = 0;
126  }
127 
128  ++ExecFrameCountSinceLastRun;
129  }
130 
131  // channel will be run at rate 1 if trimming, or when the next execrate
132  // frame is reached
133  if (fcs->GetTrimStatus() || ExecFrameCountSinceLastRun >= ExecRate) {
134  for (unsigned int i=0; i<FCSComponents.size(); i++)
135  FCSComponents[i]->Run();
136  }
137  }
139  int GetRate(void) const { return ExecRate; }
140 
141  private:
142  FGFCS* fcs;
143  FCSCompVec FCSComponents;
144  FGConstPropertyNode_ptr OnOffNode;
145  std::string Name;
146 
147  int ExecRate; // rate at which this system executes, 0 or 1 every frame, 2 every second frame etc..
148  int ExecFrameCountSinceLastRun;
149 };
150 
151 }
152 
153 #endif
JSBSim::FGFCSChannel::GetNumComponents
size_t GetNumComponents()
Returns the number of components in the channel.
Definition: FGFCSChannel.h:97
JSBSim::FGFCSChannel::Execute
void Execute()
Executes all the components in a channel.
Definition: FGFCSChannel.h:117
JSBSim::FGFCSChannel::Reset
void Reset()
Reset the components that can be reset.
Definition: FGFCSChannel.h:108
JSBSim::FGFCSChannel::GetComponent
FGFCSComponent * GetComponent(unsigned int i)
Retrieves a specific component.
Definition: FGFCSChannel.h:99
JSBSim::FGPropertyNode
Class wrapper for property handling.
Definition: FGPropertyManager.h:70
JSBSim::FGFCSComponent
Base class for JSBSim Flight Control System Components.
Definition: FGFCSComponent.h:84
JSBSim::FGFCSChannel::~FGFCSChannel
~FGFCSChannel()
Destructor.
Definition: FGFCSChannel.h:85
JSBSim::FGFCSChannel
Definition: FGFCSChannel.h:72
JSBSim::FGFCSChannel::Add
void Add(FGFCSComponent *comp)
Adds a component to a channel.
Definition: FGFCSChannel.h:93
JSBSim::FGFCS
Encapsulates the Flight Control System (FCS) functionality.
Definition: FGFCS.h:187
JSBSim::FGFCSChannel::GetRate
int GetRate(void) const
Get the channel rate.
Definition: FGFCSChannel.h:139
JSBSim::FGFCSChannel::FGFCSChannel
FGFCSChannel(FGFCS *FCS, const std::string &name, int execRate, FGPropertyNode *node=0)
Constructor.
Definition: FGFCSChannel.h:75
JSBSim::FGFCSChannel::GetName
std::string GetName()
Retrieves the name of the channel.
Definition: FGFCSChannel.h:90