From: Richard H. <rj...@za...> - 2016-02-04 07:49:18
|
I've now modified dT for rate limited systems to be correct by adjusting the value of dT that the system channel uses by adding a property and method into the base class to allow the channel to modify dt. I've tested this using an actuator, together with the extraction of simulation/dt into a property for examination; results are as follows: Report (Event 2) executed at time: 30.033033 tests/rate-1 = 902.000000 tests/rate-4 = 225.000000 tests/rate-1-actuator-value = 28.999710 tests/rate-4-actuator-value = 29.066376 tests/rate-1-dt-sum = 0.000000 tests/rate-1-dt = 0.033333 tests/rate-4-dt = 0.133332 Obviously the above shows that the actuators in the two systems running at different exec rates run are actuating at the same rate in simlation time, and that the value of simulation/dt is correctly set. > The comment on dt concerns me. Someone should look into how this patch affects > things like fuel consumption and propeller RPM before it gets accepted. > patch is https://sourceforge.net/u/r-harrison/jsbsim/ci/6ddd575d9e9eb5ec59481b434fae25795d1bfb86/ in patch file format: ------------------------------ From 6ddd575d9e9eb5ec59481b434fae25795d1bfb86 Mon Sep 17 00:00:00 2001 From: Richard Harrison <rj...@za...> Date: Thu, 4 Feb 2016 07:04:04 +0100 Subject: [PATCH] dT adjustments in rate limited system channels Change dt to be dt * number of frames since last run - i.e. to reflect what dt would be in a non-limited channel. This modifies the dt in FGFDMExec, resetting it to the normal value after processing. --- .../aircraft/systemsrate/system-rate-1.xml | 20 ++++++++++++++++++ .../aircraft/systemsrate/system-rate-4.xml | 24 +++++++++++++++++++--- .../aircraft/systemsrate/systems-rate-test-0.xml | 17 ++++++++++++++- src/models/FGFCS.cpp | 2 +- src/models/FGFCSChannel.h | 15 ++++++++++++-- src/models/flight_control/FGFCSComponent.cpp | 1 + src/models/flight_control/FGFCSComponent.h | 2 ++ 7 files changed, 74 insertions(+), 7 deletions(-) diff --git a/check_cases/ground_tests/aircraft/systemsrate/system-rate-1.xml b/check_cases/ground_tests/aircraft/systemsrate/system-rate-1.xml index fe1c479..0988050 100644 --- a/check_cases/ground_tests/aircraft/systemsrate/system-rate-1.xml +++ b/check_cases/ground_tests/aircraft/systemsrate/system-rate-1.xml @@ -2,8 +2,18 @@ <system name="FULL"> <property value="0">tests/rate-1</property> + <property value="0">tests/rate-1-dt-sum</property> + <property value="0">tests/rate-1-actuator-dmd</property> + <property value="1">tests/rate-1-actuator-rate</property> + <channel name="control" execrate="1"> <!-- this is just to do rate-1 = rate-1 + 1 --> + <actuator name="tests/rate-1-actuator-value"> + <input>tests/rate-1-actuator-dmd</input> + <rate_limit>tests/rate-1-actuator-rate</rate_limit> + <output>tests/rate-1-actuator-value</output> + </actuator> + <fcs_function name="tests/rate-1-v"> <function> <sum> @@ -12,6 +22,7 @@ </function> </fcs_function> + <!-- use actuator to test dt is correctly set --> <fcs_function name="tests/rate-1"> <function> <integer> @@ -22,5 +33,14 @@ </integer> </function> </fcs_function> + + <!-- extract dT into a property for examination --> + <fcs_function name="tests/rate-1-dt"> + <function> + <sum> + <property>simulation/dt</property> + </sum> + </function> + </fcs_function> </channel> </system> diff --git a/check_cases/ground_tests/aircraft/systemsrate/system-rate-4.xml b/check_cases/ground_tests/aircraft/systemsrate/system-rate-4.xml index 5bef5c0..6b0cce0 100644 --- a/check_cases/ground_tests/aircraft/systemsrate/system-rate-4.xml +++ b/check_cases/ground_tests/aircraft/systemsrate/system-rate-4.xml @@ -1,7 +1,8 @@ -<?xml version="1.0"?> - <system name="QUARTER" > <property value="0">tests/rate-4</property> + <property value="0">tests/rate-4-actuator-dmd</property> + <property value="1">tests/rate-4-actuator-rate</property> + <channel name="control" execrate="4"> <!-- this is just to do rate-4 = rate-4 + 1 --> <fcs_function name="tests/rate-4-v"> @@ -17,10 +18,27 @@ <integer> <sum> <value>1.0</value> - <property>tests/rate-4-v</property> + <property>tests/rate-4-v</property> </sum> </integer> </function> </fcs_function> + + <!-- use actuator to test dt is correctly set --> + <actuator name="tests/rate-4-actuator-value"> + <input>tests/rate-4-actuator-dmd</input> + <rate_limit>tests/rate-4-actuator-rate</rate_limit> + <output>tests/rate-4-actuator-value</output> + </actuator> + + <!-- extract dT into a property for examination --> + <fcs_function name="tests/rate-4-dt"> + <function> + <sum> + <property>simulation/dt</property> + </sum> + </function> + </fcs_function> + </channel> </system> diff --git a/check_cases/ground_tests/aircraft/systemsrate/systems-rate-test-0.xml b/check_cases/ground_tests/aircraft/systemsrate/systems-rate-test-0.xml index 41d036c..a3e22dc 100644 --- a/check_cases/ground_tests/aircraft/systemsrate/systems-rate-test-0.xml +++ b/check_cases/ground_tests/aircraft/systemsrate/systems-rate-test-0.xml @@ -13,14 +13,29 @@ <notify> <property>tests/rate-1</property> <property>tests/rate-4</property> + <property>tests/rate-1-actuator-value</property> + <property>tests/rate-4-actuator-value</property> + <property>simulation/dt</property> </notify> </event> - + + <event name="Actuator demands"> + <condition> simulation/sim-time-sec ge 1 </condition> + <set name="tests/rate-1-actuator-dmd" value="123456" /> + <set name="tests/rate-4-actuator-dmd" value="123456" /> + <notify/> + </event> + <event name="Report"> <condition> simulation/sim-time-sec ge 30 </condition> <notify> <property>tests/rate-1</property> <property>tests/rate-4</property> + <property>tests/rate-1-actuator-value</property> + <property>tests/rate-4-actuator-value</property> + <property>tests/rate-1-dt-sum</property> + <property>tests/rate-1-dt</property> + <property>tests/rate-4-dt</property> </notify> </event> diff --git a/src/models/FGFCS.cpp b/src/models/FGFCS.cpp index 7db1d32..882490e 100644 --- a/src/models/FGFCS.cpp +++ b/src/models/FGFCS.cpp @@ -181,7 +181,7 @@ bool FGFCS::Run(bool Holding) // Execute system channels in order for (i=0; i<SystemChannels.size(); i++) { if (debug_lvl & 4) cout << " Executing System Channel: " << SystemChannels[i]->GetName() << endl; - SystemChannels[i]->Execute(); + SystemChannels[i]->Execute(FDMExec); } RunPostFunctions(); diff --git a/src/models/FGFCSChannel.h b/src/models/FGFCSChannel.h index 3f5278b..15ecd4b 100644 --- a/src/models/FGFCSChannel.h +++ b/src/models/FGFCSChannel.h @@ -109,7 +109,7 @@ public: FCSComponents[i]->ResetPastStates(); } /// Executes all the components in a channel. - void Execute() { + void Execute(FGFDMExec *exec) { // If there is an on/off property supplied for this channel, check // the value. If it is true, permit execution to continue. If not, return // and do not execute the channel. @@ -118,8 +118,19 @@ public: if (ExecRate <= 1 || ExecFrameCountSinceLastRun >= ExecRate) { + double execDt = exec->GetDeltaT(); + // adjust exec version of dT in rate limited system channels to be what dt would be in a non-limited channel. + // this is necessary to ensure that the property (simulation/dt) is the correct value for the systems channel + if (ExecRate > 1) + exec->Setdt(execDt * ExecFrameCountSinceLastRun); + for (unsigned int i=0; i<FCSComponents.size(); i++) + { + FCSComponents[i]->SetDtForFrameCount(ExecFrameCountSinceLastRun); + FCSComponents[i]->Run(); + } + if (ExecRate > 1) + exec->Setdt(execDt); ExecFrameCountSinceLastRun = 0; - for (unsigned int i=0; i<FCSComponents.size(); i++) FCSComponents[i]->Run(); } ExecFrameCountSinceLastRun = ExecFrameCountSinceLastRun + 1; } diff --git a/src/models/flight_control/FGFCSComponent.cpp b/src/models/flight_control/FGFCSComponent.cpp index 5152a55..5344399 100644 --- a/src/models/flight_control/FGFCSComponent.cpp +++ b/src/models/flight_control/FGFCSComponent.cpp @@ -67,6 +67,7 @@ FGFCSComponent::FGFCSComponent(FGFCS* _fcs, Element* element) : fcs(_fcs) IsOutput = clip = false; string input,init, clip_string; dt = fcs->GetDt(); + base_dt = fcs->GetDt(); PropertyManager = fcs->GetPropertyManager(); if (element->GetName() == string("lag_filter")) { diff --git a/src/models/flight_control/FGFCSComponent.h b/src/models/flight_control/FGFCSComponent.h index 70ae0b6..46f0d07 100644 --- a/src/models/flight_control/FGFCSComponent.h +++ b/src/models/flight_control/FGFCSComponent.h @@ -101,6 +101,7 @@ public: virtual bool Run(void); virtual void SetOutput(void); + virtual void SetDtForFrameCount(int FrameCount) { dt = base_dt * FrameCount;} double GetOutput (void) const {return Output;} std::string GetName(void) const {return Name;} std::string GetType(void) const { return Type; } @@ -131,6 +132,7 @@ protected: int index; float clipMinSign, clipMaxSign; double dt; + double base_dt; bool IsOutput; bool clip; -- 2.6.2.windows.1 |