2011-09-08 22:31:32 -03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using YLScsDrawing.Drawing3d;
|
2012-01-15 05:00:50 -04:00
|
|
|
|
using ArdupilotMega.HIL;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
|
|
|
|
namespace ArdupilotMega.HIL
|
|
|
|
|
{
|
2012-01-15 05:00:50 -04:00
|
|
|
|
public class Aircraft : Utils
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
2012-01-15 05:00:50 -04:00
|
|
|
|
Aircraft self;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
public double home_latitude = 0;
|
|
|
|
|
public double home_longitude = 0;
|
|
|
|
|
public double home_altitude = 0;
|
|
|
|
|
public double ground_level = 0;
|
|
|
|
|
public double frame_height = 0.0;
|
|
|
|
|
|
|
|
|
|
public double latitude = 0;
|
|
|
|
|
public double longitude = 0;
|
|
|
|
|
public double altitude = 0;
|
|
|
|
|
|
2012-07-29 20:23:42 -03:00
|
|
|
|
public Matrix3 dcm = new Matrix3();
|
2012-01-15 05:00:50 -04:00
|
|
|
|
|
2012-07-29 20:23:42 -03:00
|
|
|
|
public Vector3 gyro = new Vector3(0, 0, 0);
|
2012-01-15 05:00:50 -04:00
|
|
|
|
|
2012-07-29 20:23:42 -03:00
|
|
|
|
public Vector3 accel_body = new Vector3(0, 0, 0);
|
2012-01-15 05:00:50 -04:00
|
|
|
|
|
2012-07-29 20:23:42 -03:00
|
|
|
|
public Vector3 velocity = new Vector3(0, 0, 0); //# m/s, North, East, Up
|
|
|
|
|
public Vector3 position = new Vector3(0, 0, 0); //# m North, East, Up
|
2011-09-08 22:31:32 -03:00
|
|
|
|
public double mass = 0.0;
|
|
|
|
|
public double update_frequency = 50;//# in Hz
|
2012-07-29 20:23:42 -03:00
|
|
|
|
public double gravity = 9.80665;//# m/s/s
|
|
|
|
|
public Vector3 accelerometer = new Vector3(0, 0, -9.80665);
|
|
|
|
|
|
|
|
|
|
public double roll = 0;
|
|
|
|
|
public double pitch = 0;
|
|
|
|
|
public double yaw = 0;
|
2012-01-15 05:00:50 -04:00
|
|
|
|
|
2012-11-25 01:42:46 -04:00
|
|
|
|
public Wind wind = new Wind("0,0,0");
|
|
|
|
|
|
2012-01-15 05:00:50 -04:00
|
|
|
|
public Aircraft()
|
|
|
|
|
{
|
|
|
|
|
self = this;
|
|
|
|
|
}
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2012-07-29 20:23:42 -03:00
|
|
|
|
public bool on_ground(Vector3 position = null)
|
2011-09-08 22:31:32 -03:00
|
|
|
|
{
|
2012-07-29 20:23:42 -03:00
|
|
|
|
// '''return true if we are on the ground'''
|
|
|
|
|
if (position == null)
|
|
|
|
|
position = self.position;
|
|
|
|
|
return (-position.z) + self.home_altitude <= self.ground_level + self.frame_height;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-29 20:23:42 -03:00
|
|
|
|
public void update_position(double delta_time = 0)
|
2012-01-15 05:00:50 -04:00
|
|
|
|
{
|
|
|
|
|
//'''update lat/lon/alt from position'''
|
|
|
|
|
|
2012-07-29 20:23:42 -03:00
|
|
|
|
double bearing = degrees(atan2(self.position.y, self.position.x));
|
|
|
|
|
double distance = sqrt(self.position.x * self.position.x + self.position.y * self.position.y);
|
2012-01-15 05:00:50 -04:00
|
|
|
|
|
2012-07-29 20:23:42 -03:00
|
|
|
|
gps_newpos(self.home_latitude, self.home_longitude,
|
|
|
|
|
bearing, distance);
|
2012-01-15 05:00:50 -04:00
|
|
|
|
|
2012-07-29 20:23:42 -03:00
|
|
|
|
self.altitude = self.home_altitude - self.position.z;
|
2012-01-15 05:00:50 -04:00
|
|
|
|
|
2012-07-29 20:23:42 -03:00
|
|
|
|
Vector3 velocity_body = self.dcm.transposed() * self.velocity;
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2012-07-29 20:23:42 -03:00
|
|
|
|
self.accelerometer = self.accel_body.copy();
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
2012-07-29 20:23:42 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void gps_newpos(double lat, double lon, double bearing, double distance)
|
|
|
|
|
{
|
|
|
|
|
// '''extrapolate latitude/longitude given a heading and distance
|
|
|
|
|
// thanks to http://www.movable-type.co.uk/scripts/latlong.html
|
|
|
|
|
// '''
|
|
|
|
|
// from math import sin, asin, cos, atan2, radians, degrees
|
|
|
|
|
double radius_of_earth = 6378100.0;//# in meters
|
|
|
|
|
|
|
|
|
|
double lat1 = radians(lat);
|
|
|
|
|
double lon1 = radians(lon);
|
|
|
|
|
double brng = radians(bearing);
|
|
|
|
|
double dr = distance / radius_of_earth;
|
|
|
|
|
|
|
|
|
|
double lat2 = asin(sin(lat1) * cos(dr) +
|
|
|
|
|
cos(lat1) * sin(dr) * cos(brng));
|
|
|
|
|
double lon2 = lon1 + atan2(sin(brng) * sin(dr) * cos(lat1),
|
|
|
|
|
cos(dr) - sin(lat1) * sin(lat2));
|
|
|
|
|
|
|
|
|
|
latitude = degrees(lat2);
|
|
|
|
|
longitude = degrees(lon2);
|
|
|
|
|
//return (degrees(lat2), degrees(lon2));
|
|
|
|
|
}
|
2011-09-08 22:31:32 -03:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|