Skip to content

Fixed f450 example: engine rpm is zero when low fps#1323

Merged
seanmcleod70 merged 4 commits intoJSBSim-Team:masterfrom
scropions:master
Sep 1, 2025
Merged

Fixed f450 example: engine rpm is zero when low fps#1323
seanmcleod70 merged 4 commits intoJSBSim-Team:masterfrom
scropions:master

Conversation

@scropions
Copy link
Contributor

image image image

@seanmcleod70
Copy link
Contributor

@scropions we need more context, at a minimum link to the original issue, since you can't assume everyone reviewing this PR would've seen and read the original issue that was submitted.

Secondly, can you explain how or why the UE frame rate effects the original properties used in Effectors.xml and FlightControl.xml and how changing the properties to the ones in your commit avoid the issue.

@scropions
Copy link
Contributor Author

scropions commented Aug 25, 2025

https://github.com/JSBSim-Team/jsbsim/tree/83e3df2c49c13eae78ab7853848cdd9e02c6c5ac its forked branch
#1323 its issue
I haven't fully explored this issue. I only noticed that output in "fcs/throttle-cmd-norm" causes problems, but in "fcs/throttle-pos-norm" everything works fine. Also, in some examples I saw that "fcs/throttle-cmd-norm" is used as input. I applied them. I simply suggested an implementation option that worked well for me. You are developers this app and you understand the meaning of this code better. That's why I created pr.

@seanmcleod70
Copy link
Contributor

https://github.com/JSBSim-Team/jsbsim/tree/83e3df2c49c13eae78ab7853848cdd9e02c6c5ac its forked branch
#1323 its issue

What you're trying to say is that this PR is related to issue - #1322

I simply suggested an implementation option that worked well for me.

Okay, but then please state that. We're not mind readers. All we got was 3 screenshots and some modified code. If you don't fully understand the cause and the solution, but have stumbled across some combination of changes that appears to fix it, then just state that.

I assumed you understood the cause and the fix, but just hadn't mentioned it. So before taking a more detailed look I was first waiting for some more details. We're not going to just merge in a PR if no one understands the cause and fix, just simply because it appears to work.

You are developers this app and you understand the meaning of this code better. That's why I created pr.

This particular model, added by @pbecchi 3 years ago, and has a fair amount of custom flight control systems and since quadcopters don't typically make up a large proportion of the aircraft models I'd guess most of the regular maintainers don't know it's implementation well.

But based on your commit I've taken a bit of a closer look now and these are my initial comments.

So FlightControl.xml takes in pilot inputs fcs/aileron-cmd-norm, fcs/elevator-cmd-norm, fcs/rudder-cmd-norm to generate rate commands for each of the 3-axes. Note I don't see any use of fcs/throttle-cmd-norm. Which I assumed would be used as input for height control.

It looks like instead there is a fcs/cmdHeave_nd but I don't see a direct real-time pilot input for it? I only see it set in scripts\Test_F450_Launch.xml?

The various inputs are then mixed to finally generate ESC commands to the motors, e.g.

<system name="Effectors">
<channel name="Electronic Speed Conrollers">
<actuator name="Front Right">
<input>fcs/cmdEscFR_nd</input>
<clipto>
<min>0.0</min>
<max>1.0</max>
</clipto>
<output>fcs/throttle-cmd-norm[0]</output>
</actuator>

Now the output of this, i.e. fcs/throttle-cmd-norm[0] does look unusual/suspicious. Since the point the ESC here is to set the thrust of the relevant motor.

And the FGBrushLessDCMotor makes use of in.ThrottlePos rather than throttle command.

double V = MaxVolts * in.ThrottlePos[EngineNumber];

So changing this to fcs/throttle-pos-norm[0] does seem like the right thing to do.

Now in terms of what was reported in the issue, I think what is happening is that during the UE loop the fcs/throttle-cmd-norm[x] was being set to 1, and the default implementation in FGFCS is:

jsbsim/src/models/FGFCS.cpp

Lines 147 to 152 in 83e3df2

// Notes: In this logic the default engine commands are set. This is simply a
// sort of safe-mode method in case the user has not defined control laws for
// throttle, mixture, and prop-advance. The throttle, mixture, and prop advance
// positions are set equal to the respective commands. Any control logic that is
// actually present in the flight_control or autopilot section will override
// these simple assignments.

for (i=0; i<ThrottlePos.size(); i++) ThrottlePos[i] = ThrottleCmd[i];

So then during the first time step in JSBSim throttle pos is 1 and that's what the brushless engine code sees and uses. But, the effector code then overwrites fcs/throttle-cmd-norm with a smaller value as part of it's output. So subsequent JSBSim time steps, remember it's being run at 120Hz now make use of this as the throttle pos.

Until there is another UE game loop, which resets fcs/throttle-cmd-norm[x] to 1 and we then start over. So if the UE game loop/FPS is high enough then the throttle pos is set back to 1 quite frequently and the drone appears to generate enough RPM etc. to take-off, hover etc. But when the UE game loop rate drops, say to only 10Hz, then it the throttle position doesn't get set back to 1 frequently enough, and you end up with a value much smaller than 1, so the RPM drops, thrust drops etc. and the drone then crashes.

I'll take a look at your changes to FlightControl.xml next.

@seanmcleod70
Copy link
Contributor

I'll take a look at your changes to FlightControl.xml next.

In my comments above, my references to what I saw in FlightControl.xml were based on what I saw in the original FlightControl.xml.

It looks like instead there is a fcs/cmdHeave_nd but I don't see a direct real-time pilot input for it? I only see it set in scripts\Test_F450_Launch.xml?

So, I see now looking at your modified FlightControl.xml that you addressed this, replacing fcs/cmdHeave_nd with fcs/throttle-cmd-norm[x].

However, it looks like you've replaced a single heave command with 4 separate ones. I'm not sure that's typical for a quadcopter. I would expect to only have a single pilot input for heave.

@scropions
Copy link
Contributor Author

scropions commented Aug 25, 2025

I didn't find any usage of Heave in the source code, and it seems like it's always empty. I also didn't find ThrottleCmd in the calculations, but ThrottlePos is used there.

for (i=0; i<ThrottlePos.size(); i++) ThrottlePos[i] = ThrottleCmd[i];

For calculation is using
HP = PowerWatts * in.ThrottlePos[EngineNumber] / hptowatts;

double V = MaxVolts * in.ThrottlePos[EngineNumber];

Sorry for my English, but I don't know it well and I communicate with the help of a translator.
In this example, cmd is also used for input and pos is output data.
https://wiki.paparazziuav.org/wiki/AR_Drone_2
(flight control section)
And we have 4 engines, which means the input power must be separate for each.

@seanmcleod70
Copy link
Contributor

And we have 4 engines, which means the input power must be separate for each.

You don't need to have 4 user inputs because there are 4 engines. The user can input a single heave/vertical velocity command etc. and the flight control system will then work out how much power to request from each of the 4 engines. The flight control system also looks at the other user inputs/commands like pitch rate, roll rate, yaw rate and then mixes all those with the single heave command to come up with particular power requests for each of the 4 engines.

@gallonmate
Copy link
Contributor

The Effectors.xml change is good. Even for just JSBSim standlone without Unreal Engine, this part of the PR makes sense.

The FlightControl.xml technically doesn't need to change. The fcs/cmdHeave_nd property can be controlled in UE with the JSBSim command console node. But if it's going to be changed, then Sean is correct, it should be just be replaced with the singular property fcs/throttle-cmd-norm. And then also the Test Launch F450 xml script would need to be updated to replace the fcs/cmdHeave_nd.

@scropions
Copy link
Contributor Author

@gallonmate okay. I'll create tests. If we use fcs/cmdHeave_nd, it's not clear to the user whether it should be passed as a separate parameter? Such examples and models should be easily configurable and not require knowledge from the user.

@scropions
Copy link
Contributor Author

scropions commented Aug 28, 2025

first diff:
image
second diff:
image
column G - /fdm/jsbsim/propulsion/engine/propeller-rpm

column H - /fdm/jsbsim/propulsion/engine/thrust-lbs

column I - /fdm/jsbsim/propulsion/engine/power-hp

before changes

afterchanges

@seanmcleod70
Copy link
Contributor

@scropions here is an example of the user inputs for DJI quadcopters. As you can see, there is only a single throttle/heave user input.

https://developer.dji.com/mobile-sdk/documentation/introduction/component-guide-remotecontroller.html

image

@scropions
Copy link
Contributor Author

scropions commented Aug 29, 2025

Its just input. In unreal engine we take and send only one input too

@seanmcleod70
Copy link
Contributor

In unreal engine we take and send only one input too

You may have a single input in Unreal, but given your changes to FlightControl.xml in this PR it means you then need to copy that single input to 4 other properties, i.e. fcs/throttle-cmd-norm[0], fcs/throttle-cmd-norm[1], fcs/throttle-cmd-norm[2], fcs/throttle-cmd-norm[3]. Just as you've had to do so in Test_F450_Launch.xml.

Compared to, before your changes, you would only need to copy that single Unreal input to just one property, i.e. fcs/cmdHeave_nd.

@gallonmate
Copy link
Contributor

gallonmate commented Aug 29, 2025

Yes the heave cmd should only be replaced with one throttle cmd. Do not use multiple numbered throttles. Do not use [0], [1], etc, even if it works, it's redundant and confusing. Replace fcs/cmdHeave_nd with just fcs/throttle-cmd-norm that's it and then PR is good. And change scasengage back to 0.

As said before the Effectors.xml fixes the bug with the F450. No other changes are needed but if changing heave cmd, then only replace the heave cmd with this exactly: fcs/throttle-cmd-norm.

@scropions
Copy link
Contributor Author

Done. Setting the value to 0 disables standard drone control.

@seanmcleod70 seanmcleod70 merged commit a96870b into JSBSim-Team:master Sep 1, 2025
@seanmcleod70
Copy link
Contributor

@scropions thanks, your PR has now been merged.

bcoconni pushed a commit to bcoconni/jsbsim that referenced this pull request Feb 6, 2026
Co-authored-by: PELENG/baturin_iv <baturin_iv@peleng.by>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants