2012-03-22 08:50:47 -03:00
|
|
|
import math, util, rotmat
|
|
|
|
from rotmat import Vector3, Matrix3
|
2011-12-02 00:13:50 -04:00
|
|
|
|
|
|
|
class Aircraft(object):
|
|
|
|
'''a basic aircraft class'''
|
|
|
|
def __init__(self):
|
|
|
|
self.home_latitude = 0
|
|
|
|
self.home_longitude = 0
|
|
|
|
self.home_altitude = 0
|
|
|
|
self.ground_level = 0
|
|
|
|
self.frame_height = 0.0
|
|
|
|
|
|
|
|
self.latitude = self.home_latitude
|
|
|
|
self.longitude = self.home_longitude
|
|
|
|
self.altitude = self.home_altitude
|
|
|
|
|
2012-03-22 08:50:47 -03:00
|
|
|
self.dcm = Matrix3()
|
2011-12-05 02:44:04 -04:00
|
|
|
|
2012-03-22 08:50:47 -03:00
|
|
|
# rotation rate in body frame
|
|
|
|
self.gyro = Vector3(0,0,0) # rad/s
|
2011-12-05 02:44:04 -04:00
|
|
|
|
2012-03-22 08:50:47 -03:00
|
|
|
self.velocity = Vector3(0, 0, 0) # m/s, North, East, Down
|
|
|
|
self.position = Vector3(0, 0, 0) # m North, East, Down
|
|
|
|
self.last_velocity = self.velocity.copy()
|
2011-12-02 00:13:50 -04:00
|
|
|
self.mass = 0.0
|
|
|
|
self.update_frequency = 50 # in Hz
|
|
|
|
self.gravity = 9.8 # m/s/s
|
2012-03-22 08:50:47 -03:00
|
|
|
self.accelerometer = Vector3(0, 0, self.gravity)
|
2011-12-02 00:13:50 -04:00
|
|
|
|
2011-12-12 19:11:10 -04:00
|
|
|
self.wind = util.Wind('0,0,0')
|
|
|
|
|
2012-03-22 08:50:47 -03:00
|
|
|
def update_position(self, delta_time):
|
2011-12-02 00:13:50 -04:00
|
|
|
'''update lat/lon/alt from position'''
|
|
|
|
|
|
|
|
radius_of_earth = 6378100.0 # in meters
|
|
|
|
dlat = math.degrees(math.atan(self.position.x/radius_of_earth))
|
|
|
|
self.latitude = self.home_latitude + dlat
|
2012-03-22 08:50:47 -03:00
|
|
|
lon_scale = math.cos(math.radians(self.latitude));
|
|
|
|
dlon = math.degrees(math.atan(self.position.y/radius_of_earth))/lon_scale
|
2011-12-02 00:13:50 -04:00
|
|
|
self.longitude = self.home_longitude + dlon
|
|
|
|
|
2012-03-22 08:50:47 -03:00
|
|
|
self.altitude = self.home_altitude - self.position.z
|
|
|
|
|
2011-12-02 00:13:50 -04:00
|
|
|
# work out what the accelerometer would see
|
2012-03-22 08:50:47 -03:00
|
|
|
self.accelerometer = ((self.velocity - self.last_velocity)/delta_time) + Vector3(0,0,self.gravity)
|
|
|
|
# self.accelerometer = Vector3(0,0,-self.gravity)
|
|
|
|
self.accelerometer = self.dcm.transposed() * self.accelerometer
|
|
|
|
self.last_velocity = self.velocity.copy()
|