2010-09-08 05:21:46 -03:00
|
|
|
// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: t -*-
|
|
|
|
|
|
|
|
// Assorted useful math operations for ArduPilot(Mega)
|
|
|
|
|
2012-02-17 19:00:26 -04:00
|
|
|
#include <AP_Common.h>
|
2011-12-15 22:47:07 -04:00
|
|
|
#include <stdint.h>
|
2010-09-08 05:21:46 -03:00
|
|
|
#include "vector2.h"
|
|
|
|
#include "vector3.h"
|
|
|
|
#include "matrix3.h"
|
2012-03-04 23:31:47 -04:00
|
|
|
#include "quaternion.h"
|
2011-12-14 23:34:58 -04:00
|
|
|
#include "polygon.h"
|
2012-02-17 19:00:26 -04:00
|
|
|
|
|
|
|
// define AP_Param types AP_Vector3f and Ap_Matrix3f
|
|
|
|
AP_PARAMDEFV(Matrix3f, Matrix3f, AP_PARAM_MATRIX3F);
|
|
|
|
AP_PARAMDEFV(Vector3f, Vector3f, AP_PARAM_VECTOR3F);
|
2012-02-23 07:56:40 -04:00
|
|
|
|
|
|
|
// a varient of asin() that always gives a valid answer.
|
|
|
|
float safe_asin(float v);
|
2012-02-23 19:40:56 -04:00
|
|
|
|
|
|
|
// a varient of sqrt() that always gives a valid answer.
|
|
|
|
float safe_sqrt(float v);
|
2012-02-23 20:23:12 -04:00
|
|
|
|
|
|
|
// create a rotation matrix given some euler angles
|
|
|
|
void rotation_matrix_from_euler(Matrix3f &m, float roll, float pitch, float yaw);
|
|
|
|
|
|
|
|
// calculate euler angles from a rotation matrix
|
2012-03-05 07:41:10 -04:00
|
|
|
void calculate_euler_angles(const Matrix3f &m, float *roll, float *pitch, float *yaw);
|
2012-03-04 23:31:47 -04:00
|
|
|
|
|
|
|
// create a quaternion from Euler angles
|
|
|
|
void quaternion_from_euler(Quaternion &q, float roll, float pitch, float yaw);
|
|
|
|
|
|
|
|
// create eulers from a quaternion
|
2012-03-05 07:41:10 -04:00
|
|
|
void euler_from_quaternion(const Quaternion &q, float *roll, float *pitch, float *yaw);
|
|
|
|
|
|
|
|
// convert a quaternion to a rotation matrix
|
|
|
|
void quaternion_to_rotation_matrix(const Quaternion &q, Matrix3f &m);
|
|
|
|
|
|
|
|
// convert a vector in earth frame to a vector in body frame,
|
|
|
|
// assuming body current rotation is given by a quaternion
|
|
|
|
void quaternion_earth_to_body(const Quaternion &q, Vector3f &v);
|