Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic Aircraft sim not producing desired results. 2

Status
Not open for further replies.

ra1024

Electrical
Jan 30, 2012
8
I'm in dire need of assistance in fixing an aircraft sim. I was a Math/Physics major before switching to electrical engineering so I have a good background in the area but could use a true ae to help with some of the areas that are not quite right.

If I adjust the rudder parameter for example to make it turn well, it messes up the behavior for when the plane falls backwards after flying straight up. This makes me believe I'm not doing something right like not modeling the forces on the control surfaces correctly.

I have about 12 steps in my sim process and model about 11 main forces so it's not a very detailed simulation. If anyone has time to help, it would be greatly appreciated. I would be willing to pay for someone's time if that would be appropriate. I'm including a summary of what I do below but let me know what else I should provide.

Thanks,
Reggie

Vector Setup - I don't suspect any problems here, I deal a lot with vectors and these should be correct.

Rotation Slowdown - I reduce any rotation velocities across all 3 axis here to simulate the wind resistance that would slow down a rotating aircraft that was spinning fast. Here's the calc for each axis.

f1 = angularVelocityX * angularVelocityX * 90 // 90 is an arbitrary constant that gave good results. The faster it's spinning, the greater the slowdown torque
// f1 is now checked to make sure it's not big enough to cause a rotation in the opposite direction, ie it can only slow down the current rotation to 0
torqueX = torqueX - Math.Sign(angularVelocityX) * f1

// Repeat for X & Y axis


Elevator Effect - I add in rotation velocity due to the effect of the elevator. I could have set a torque but decided instead to just directly affect the rotation.

velocityUp = plane's velocity perpendicular to the elevator
curTime = 0.001 // I used fixed time steps of 0.001 seconds
signFactor = 1 or -1 depending on the direction of velocityUp
f4 = dot product of velocity with planes forward vector

f4 = Math.Sign(f4) * (1.0f - Math.Abs(f4)) // If velocity is parallel to elevator, f4 is 0. As velocity approaches completely perpendicular to elevator, f4 goes to 1
angularVelocityX += signFactor * velocityUp * velocityUp * f4 * 0.025f * curTime // 0.025 is a scaling factor


Lifting Force from Wings - If the plane's velocity is forwards, I calculate lift and drag forces for each wing so as to take into account the dihedral angle.

velocityF = plane's velocity with side component removed ( only forwards/upwards velocity components remain )
drag = Get_Point_2D_Float_Graph(angleOfAttack, 0) // look up the drag from a lift/drag curve

totalDrag = drag * wingDragFactor * velocityF * velocityF * 0.5f; // Divide by two since this is just half of the wing

forceX -= totalDrag * xForward // Add in drag forces for each axis due to wing drag
forceY -= totalDrag * yForward
forceZ -= totalDrag * zForward


signFactor = 1 or -1 depending on the direction of the angle of attack
lift = Get_Point_2D_Float_Graph(angleOfAttack, 1) // look up the lift from a lift/drag curve
totalLiftRightWing = lift * wingLiftFactor * velocityF * velocityF

forceX += totalLift * signFactor * wingVectorUpX
forceY += totalLift * signFactor * wingVectorUpY
forceZ += totalLift * signFactor * wingVectorUpZ

// Repeat for second wing


Dihedral Torque - I add in torque produced by the wings dihedral angle.

torqueY -= mainVelocity * (totalLiftLeftWing - totalLiftRightWing) * 0.000000005 // Last number is a constant that produced a good result


Rudder

velocityRight = velocity component parallel to the plane's right vector ( as seen from pilot's viewpont )
torqueZ -= Math.Sign(velocityRight) * velocityRight * velocityRight * 0.075f



Engine

forceX += xForward * engineThrust
forceY += yForward * engineThrust
forceZ += zForward * engineThrust

Wind Resistance

f2 = velocityForward * velocityForward * flatPlateArea;
forceX -= f2 * xForward
forceY -= f2 * yForward
forceZ -= f2 * zForward

Force Against Wings - This would come more into play if the plane were dropped with zero velocity

f1 = velocityUp * velocityUp * areaWing;
forceX -= f1 * xUp;
forceY -= f1 * yUp;
forceZ -= f1 * zUp;


Gravity

forceZ += DefinesClass.GRAVITY * mass

Controls Input

// rotZ = rudder input
// rotY = aileron input
// rotX = elevator input

torqueZ -= rotZ * 0.001f * velocityForwards // 0.001f is a scaling factor for the input parameter
torqueY += rotY * 0.00045 * fuselageVelocitySquared // 0.00045 is just a scaling factor for the input parameter
torqueX += rotX * 0.00012 * fuselageVelocitySquared // 0.00012 is just a scaling factor for the input parameter


Calcuatle Position, Velocity, and Rotations - After summing up the forces and torques, I have a basic physics routine that calucates the new state of the aircraft. This is pretty straightforward and I don't believe I have any issues here.

get_Planes_Position(airCraftData, curTime)






















 
Replies continue below

Recommended for you

berkshire:

Thank you for the feedback. Although my primary training is in electrical, I am intensely interested in everything about aviation and thus I really appreciate the information you provided.

Regarding your statement about the flat spin that "...it occurs when the horizontal stabilizor is lifting or has minimal download..." that makes sense based on what I think I have previously learned about aircraft design. If I understand correctly, under normal conditions the horizontal stabilizor is supposed to provide a significant download to counteract the nose down tendency of a typical aircraft wing design.
 
Having the CG forward of the center of lift produces a "stable" aircraft that recovers from stall naturally with out control input. As the CG moves closer to the Center of Lift, the aircraft becomes less stable, but more maneuverable. Most military aricraft are designed to unstable, in order to be more maneuverable. Modern fighters would be dangerous or impossible to fly without sophisiticated computer systems.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor