1
0
Fork 0

[JSBSim] Added cyclic clipping for FCS components

This commit is contained in:
Bertrand Coconnier 2018-12-30 20:51:18 +01:00
parent 27ddcedad2
commit 466fb0979d
2 changed files with 24 additions and 19 deletions

View file

@ -37,12 +37,8 @@ COMMENTS, REFERENCES, and NOTES
INCLUDES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include <iostream>
#include <cstdlib>
#include "FGFCSComponent.h"
#include "input_output/FGXMLElement.h"
#include "math/FGPropertyValue.h"
#include "models/FGFCS.h"
#include "math/FGParameterValue.h"
@ -60,7 +56,7 @@ FGFCSComponent::FGFCSComponent(FGFCS* _fcs, Element* element) : fcs(_fcs)
Input = Output = delay_time = 0.0;
delay = index = 0;
ClipMin = ClipMax = nullptr;
IsOutput = clip = false;
IsOutput = clip = cyclic_clip = false;
dt = fcs->GetChannelDeltaT();
PropertyManager = fcs->GetPropertyManager();
@ -185,6 +181,10 @@ FGFCSComponent::FGFCSComponent(FGFCS* _fcs, Element* element) : fcs(_fcs)
clip_string = el->GetDataLine();
ClipMax = new FGParameterValue(clip_string, PropertyManager);
clip_string = clip_el->GetAttributeValue("type");
if (clip_string == "cyclic")
cyclic_clip = true;
clip = true;
}
@ -229,8 +229,16 @@ void FGFCSComponent::Delay(void)
void FGFCSComponent::Clip(void)
{
if (clip)
Output = Constrain(ClipMin->GetValue(), Output, ClipMax->GetValue());
if (clip) {
double vmin = ClipMin->GetValue();
if (cyclic_clip) {
double value = Output - vmin;
double range = ClipMax->GetValue() - vmin;
Output = fmod(value, range) + vmin;
}
else
Output = Constrain(vmin, Output, ClipMax->GetValue());
}
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

View file

@ -7,21 +7,21 @@
------------- Copyright (C) 2000 Jon S. Berndt (jon@jsbsim.org) -------------
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option) any
later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc., 59
Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Further information about the GNU Lesser General Public License can also be found on
the world wide web at http://www.gnu.org.
Further information about the GNU Lesser General Public License can also be
found on the world wide web at http://www.gnu.org.
HISTORY
--------------------------------------------------------------------------------
@ -37,9 +37,6 @@ SENTRY
INCLUDES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#include <string>
#include <vector>
#include "FGJSBBase.h"
#include "math/FGPropertyValue.h"
@ -117,7 +114,7 @@ protected:
int index;
double dt;
bool IsOutput;
bool clip;
bool clip, cyclic_clip;
void Delay(void);
void Clip(void);