thanks for the support!
Ok.. to show i've actually done something for it here are the flight dynamics. it's not finished cus i'm just tweaking it at the moment. but here it is anyway if someone wants to help me with it. you'll need an understanding of flight dynamics though...
@jack
by not a matrix do u mean you want it to be a .x object or something?
the flight dynamics code is not complete and needs some serious tweeking. it's designed for a plane like the eurofighter.
also here is a model of a cessna.
rem constants
weight#=10450.0 : rem pounds
gravitational_acceleration# = 32.174 : `ft/s2
aircraft_mass# = weight#/gravitational_acceleration#
CDo#=0.03
CDa#=0.3
CLo#=0.28
CLa#=3.45
CLq#=0.0
CLda#=0.72
CLde#=0.36
CMo#=0.0
CMq#=-3.6
CMa#=-0.38
CMda#=-1.1
CMde#=-0.5
CYb#=-0.98
CYdr#=0.17
CLb#=-0.12
CLp#=-0.26
CLr#=0.14
CLda#=0.08
CLdr#=-0.105
CNb#=0.25
CNp#=0.002
CNr#=-0.35
CNda#=0.06
CNdr#=0.032
rem 32.174- slugs
b#=27.5 : rem wingspan
S#=260 : rem wingsurface area ft/2
c#=10.8 : rem cord length
rem rho(stp) = 1.293 kg/m3
rho#=0.09482 : rem lbs/cu ft(cubic feet)
adjust#=2
Ixx#=8090
Iyy#=25900
Izz#=29200
Ixz#=1300
U#=0.001
V#=0.001
W#=0.001
dim cc#(10)
vQtrn1# =1
vQtrn2# =1
vQtrn2# =1
vQtrn3# =1
do
rem user input
thrust#=((joystick slider a()*-1)+1000)*8
rudder#=joystick twist z()
elevator#=joystick x()
aileron#=joystick z()
print throttle#
speed# = sqrt(U#*U#+V#*V#+W#*W#)
qbarS#=rho#*((speed#*speed#)*S)/2
if U#=0 or W#=0
alpha#=0
else
alpha#=atan(W#/U#) : `alpha is 0 when W velocity (i.e. vertical velocity) is equal to 0
endif
if V#=0 or U#=0
beta#=0
else
beta#=atan(V#/U#) : `beta is 0 when V velocity (i.e. side velocity) is equal to 0
endif
`beta can be calculated also as asin(V/speed)
`Now is time to calculate lift and drag
lift_coefficient# = CLo# + CLa#*alpha# + CLde#*elevator#
`CLo is the reference lift at zero angle of attack
`CLa is the lift curve slope
`CLde is the lift due to elevator
drag_coefficient# = CDo# + CDa#*alpha# + CDde#*elevator#
`CDo is the reference drag at zero angle of attack
`CDa is the drag curve slope
`CDde is the drag due to elevator
`Calculation of lift and drag coefficients takes into account also other parameters,
`which i avoided to mention to simplify this paper and because their effect is quite minimal:
`but if you want to make a very very realistic simulation, you have to include them. I suggest you study this document
Lift# = lift_coefficient# * qbarS#
Drag# = drag_coefficient# * qbarS#
`where qbarS is the dynamic pressure and is defined as ( rho * speed2 * S / 2 )
`and, in detail, speed is the aircraft speed, rho is the air density at a certain altitude and S is the wing area surface in feet2
`Calculating aero forces
Fx# = lift#*sin(alpha#) - drag#*cos(alpha#) + thrust#
Fz#=(lift#-(lift#*2))*cos(alpha#)-drag#*sin(alpha#) : rem Fz#=-lift#*cos(alpha#)-drag#*sin(alpha#)
Fy# = (CYb#*beta# + CYdr#*rudder#)*qbarS#
`Calculating linear accelerations
Ua#=V#*R#-W#*Q#-gravitational_acceleration#*sin(theta#)+Fx#/aircraft_mass#
Wa# = U#*Q# - V#*P# + gravitational_acceleration# * cos(phi#)*cos(theta#) + Fz#/aircraft_mass#
Va# = W#*P# - U#*R# + gravitational_acceleration# * sin(phi#)*cos(theta#) + Fy#/aircraft_mass#
`Calculate linear velocities
U#= U# + Ua#
W#=W# + Wa#
V#= V# + Va#
print "speed#=";speed#
`Calculate moments
L# = (CLb#*beta# + CLp#*P#*b#/(adjust#*speed#)+CLr#*R#*b#/(speed#)+CLda#*aileron#+CLdr#*rudder#)*qbarS#*b# : `// Roll
M# = (CMo#+CMa#*alpha#+CMq#*Q#*c#/(speed#)+CMde#*elevator#)*qbarS#*c# : `// Pitch
N# = (CNb#*beta# + CNp#*P#*b#/(speed#) + CNr#*R#*b#/(speed#) + CNda#*aileron# + CNdr#*rudder#)*qbarS#*b# : `// Yaw
`CLb is the dihedral effect
`CLp is roll damping
`CLr is the roll due to yaw rate
`Clda is the roll due to aileron
`CLdr is the roll due to rudder
`CMo is the pitch moment coefficient
`CMa is the pitch moment coefficient due to angle of attack
`CMq is the pitch moment coefficient due to picth rate
`CMde is the pitch coefficient due to elevator
`CNb is the weather cocking stability
`CNp is the rudder adverse yaw
`CNr is the yaw damping
`CNda is the yaw due to aileron
`CNdr is the yaw due to rudder
`One note: you understand that it is extremely important to know all the coefficients of the aircraft you want to simulate.
`I started with the coefficients of the A-4 Sparrow, but then i was lucky to find a software of aerodynamics calculations
`( check www.darcorp.com ) where i found the F22 Raptor ones. As i told before, i'd like to build a reference database with all the known coefficients and parameters of all aircrafts.it's quite utopistic i know, but let's just start and see.
`Calculate the rotational body axis accelerations
`Just assuming that :
`Ixx is the roll inertia in slug/feet2
`Iyy is the pitch inertia in slug/feet2
`Izz is the yaw inertia in slug/feet2
`Ixz is the overall inertia along the trasversal Y-Z in slug/feet2
`If fuel consumption or weapon drops are to be simulated, the previous inertial parameters and the mass of the aircraft should be updated in each loop.
`Now we will arrange the inertial parameters and combine them to calculate the aircraft angular accelerations:
`ixz#*ixz# = Ixz#*Ixz# : rem ixz2 = Ixz*Ixz
cc#(0) = 1/(Ixx#*Izz# - (ixz#*ixz#)) : rem cc#(0) = 1/(Ixx#*Izz# - ixz2#)
cc#(1) = cc#(0)*((Iyy#-Izz#)*Izz# - ixz#*ixz#) : rem cc#(1) = cc#(0)*((Iyy#-Izz#)*Izz# - ixz#2)
cc#(2) = cc#(0)*Ixz#*(Ixx# - Iyy# + Izz#)
cc#(3) = cc#(0)*Izz#
cc#(4) = cc#(0)*Ixz#
cc#(7) = 1/Iyy#
cc#(5) = cc#(7)*(Izz# - Ixx#)
cc#(6) = cc#(7)*Ixz#
cc#(8) = cc#(0)*((Ixx# - Iyy#)*Ixx# + ixz#*ixz#) : rem cc#(8) = cc#(0)*((Ixx# - Iyy#)*Ixx# + ixz2)
cc#(9) = cc#(0)*Ixz#*(Iyy# - Izz# - Ixx#)
cc#(10) = cc#(0)*Ixx#
Pa = (cc#(1)*R# + cc#(2)*P#)*Q# + cc#(3)*L# + cc#(4)*N#
Qa = cc#(5)*R#*P# + cc#(6)*(R#*R# - P#*P#) + cc#(7)*M#
Ra = (cc#(8)*P# + cc#(9)*R#)*Q# + cc#(4)*L# + cc#(10)*N#
`Pa,Qa,Ra are the aircraft angular accelerations expressed in rad/sec2 about the X,Y,Z axis
`From these we can calculate the aircraft rotational velocities down here:
P# = P# + (3*Pa# - vlastPdot#)
Q# = Q# + (3*Qa# - vlastQdot#)
R# = R# + (3*Ra# - vlastRdot#)
`where vlastPdot,vlastQdot,vlastRdot are the previous values of Pa, Qa, Ra (that you get at the end of the main loop)
`Calculating theta, phi, psi to rotate aircraft at new angle position
`To achieve this, we have to feed above values and solve quaternion calculations which will provide the angles we want:
vQdot1# = -0.5*(vQtrn2#*P# + vQtrn3#*Q# + vQtrn4#*R#)
vQdot2# = 0.5*(vQtrn1#*P# + vQtrn3#*R# - vQtrn4#*Q#)
vQdot#3 = 0.5*(vQtrn1#*Q# + vQtrn4#*P# - vQtrn2#*R#)
vQdot4# = 0.5*(vQtrn1#*R# + vQtrn2#*Q# - vQtrn3#*P#)
vQtrn1# = vQtrn1# + 0.5*(vlastQdot1# + vQdot1#)
vQtrn2# = vQtrn2# + 0.5*(vlastQdot2# + vQdot2#)
vQtrn3# = vQtrn3# + 0.5*(vlastQdot3# + vQdot3#)
vQtrn4# = vQtrn4# + 0.5*(vlastQdot4# + vQdot4#)
epsilon# = sqrt(vQtrn1#*vQtrn1# + vQtrn2#*vQtrn2# + vQtrn3#*vQtrn3# + vQtrn4#*vQtrn4#)
inv_eps# = 1/epsilon#
vQtrn1# = inv_eps#*vQtrn1#
vQtrn2# = inv_eps#*vQtrn2#
vQtrn2# = inv_eps#*vQtrn2#
vQtrn3# = inv_eps#*vQtrn3#
vlastQdot1# = vQdot1#
vlastQdot2# = vQdot2#
vlastQdot3# = vQdot3#
vlastQdot4# = vQdot4#
Q0Q0# = vQtrn1#*vQtrn1#
Q1Q1# = vQtrn2#*vQtrn2#
Q2Q2# = vQtrn3#*vQtrn3#
Q3Q3# = vQtrn4#*vQtrn4#
Q0Q1# = vQtrn1#*vQtrn2#
Q0Q2# = vQtrn1#*vQtrn3#
Q0Q3# = vQtrn1#*vQtrn4#
Q1Q2# = vQtrn2#*vQtrn3#
Q1Q3# = vQtrn2#*vQtrn4#
Q2Q3# = vQtrn3#*vQtrn4#
mTl2b11# = Q0Q0# + Q1Q1# - Q2Q2# - Q3Q3#
mTl2b12# = 2*(Q1Q2# + Q0Q3#)
mTl2b13# = 2*(Q1Q3# - Q0Q2#)
mTl2b21# = 2*(Q1Q2# - Q0Q3#)
mTl2b22# = Q0Q0# - Q1Q1# + Q2Q2# - Q3Q3#
mTl2b23# = 2*(Q2Q3# + Q0Q1#)
mTl2b31# = 2*(Q1Q3# + Q0Q2#)
mTl2b32# = 2*(Q2Q3# - Q0Q1#)
mTl2b33# = Q0Q0# - Q1Q1# - Q2Q2# + Q3Q3#
theta# = asin( 0-mTl2b13# ) : rem theta# = asin( -mTl2b13# )
psi# = atan( mTl2b12#/mTl2b11# ) : rem psi# = atan2( mTl2b12#, mTl2b11# )
phi# = atan( mTl2b23#/mTl2b33# )
vlastPdot# = Pa#
vlastQdot# = Qa#
vlastRdot# = Ra#
`Calculating position updates
`So, now we have the angles and we go for the position updates (world_x, world_y, world_z are the new increments, in feet, that should be added at current aircraft position to get the new position)
world_x# = U#*cos(theta#)*sin(psi#) + V#*(cos(phi#)*cos(psi#)+sin(phi#)*sin(theta#)*sin(psi#)) + W#*(cos(phi#)*sin(theta#)*sin(psi#) - sin(phi#)*cos(psi#))
world_y# = U#*sin(theta#) - V#*sin(phi#)*cos(theta#) - W#*cos(phi#)*cos(theta#)
world_z# = U#*cos(theta#)*cos(psi#) + V#*(sin(phi#)*sin(theta#)*cos(psi#) - cos(phi#)*sin(psi#)) + W#*(sin(phi#)*sin(psi#) + cos(phi#)*sin(theta#)*cos(psi#))
`So, after all these formulas, you have only to translate and rotate the aircraft at the new angles and positions et voilĂ !
`One important thing: the aerodynamic model has a tendency to "blow up" if the time step between aerodynamic calculations becomes too great,
`so you should run the aerodynamic model at a faster rate than the rest of the system. This means you will have to create a timer in your application, and run the flight model routine at least 100-150 times for every application cycle.
`Other calculations
g_force# = 1/gravitational_acceleration# * lift# * gravitational_acceleration#/weight#
`that can be reduced to
g_force# = lift#/weight#
position object 1,world_x#,world_y#,world_z#
xrotate object 1,theta#
yrotate object 1,psi#
zrotate object 1,phi#
loop
OMG It's the Wilderbeast
We all hate Runescape-http://congascape.tk