Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIM_Plane.cpp uses torque as rotation acceleration when updating simulation dynamics #26972

Open
magate opened this issue May 3, 2024 · 0 comments
Labels

Comments

@magate
Copy link
Contributor

magate commented May 3, 2024

Bug report

Issue details

I'm pretty sure there is a bug in the simulation in SIM_Plane.cpp , rot_accel = getTorque(aileron, rudder, thrust, force); returns a torque not an angular acceleration. https://github.com/ArduPilot/ardupilot/blob/e2767f899ffae99b5778745bac5c9cfbbbcdfc88/libraries/SITL/SIM_Plane.cpp#L343C5-L343C15

If we do a quick unit conversion just on the first term in la = qbar*b*(c_l_0 assuming c_l_0 is unit less means (qbar = 1.0/2.0*rho*pow(effective_airspeed,2)*s which would be [kg/m^3*m^2/s^2*m^2] ==> [kg*m/s^2] b = [m] ==> kg*m^2/s^2 which is correct for torque torque = Fxd N*m ==> kg*m/s^2*m ==> kg*m^2/s^2.

la = qbar*b*(c_l_0 + c_l_b*beta + c_l_p*b*p/(2*effective_airspeed) + c_l_r*b*r/(2*effective_airspeed) + c_l_deltaa*inputAileron + c_l_deltar*inputRudder);

This is a long way to say that getTorque is returning a torque. This is also clear form adding the alignment where it is force*distance.

la += CGOffset.y * force.z - CGOffset.z * force.y;

However, rot_accel which is actually a torque is used to directly update the simulation dynamics https://github.com/ArduPilot/ardupilot/blob/2a218221f06b7ec5b6bb78ed82fdcf35c4db1e32/libraries/SITL/SIM_Plane.cpp#L397C5-L397C20.

This is OK if we assume moment of inertia is Vector3f moment_of_inertia = {1.0, 1.0, 1.0};.

Where this becomes an issue is in QuadPlane if a user wanted to get the moments of inertia used in the copter simulation.

https://github.com/ArduPilot/ardupilot/blob/2a218221f06b7ec5b6bb78ed82fdcf35c4db1e32/libraries/SITL/SIM_Frame.cpp#L572C1-L575C56

This has been corrected there where the variable reflects that it is a torque. #20529

Note

Unfortunately, dividing the plane rotational acceleration by the copter moments of inertia makes the quadplane sim unflyable.

Version
Went through the code on master and it looks like there are no plane moment of inertias. It's possible I'm missing it. It looks like the other sims do this.

Platform
[ ] All
[ ] AntennaTracker
[ ] Copter
[ x ] Plane
[ ] Rover
[ ] Submarine

Airframe type
QuadPlane

Hardware type
SITL

Logs
Not applicable.

@Ryanf55 Ryanf55 added the SITL label May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants