2010-09-21 21:29:35 +02:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file CoordinateConverions.h
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
|
|
* @brief Header for Coordinate conversions library in CoordinateConversions.c
|
|
|
|
* - all angles in deg
|
|
|
|
* - distances in meters
|
|
|
|
* - altitude above WGS-84 elipsoid
|
|
|
|
*
|
|
|
|
* @see The GNU Public License (GPL) Version 3
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef COORDINATECONVERSIONS_H_
|
|
|
|
#define COORDINATECONVERSIONS_H_
|
|
|
|
|
2013-05-18 14:17:26 +02:00
|
|
|
// ****** convert Lat,Lon,Alt to ECEF ************
|
2013-06-30 18:49:29 +02:00
|
|
|
void LLA2ECEF(int32_t LLAi[3], double ECEF[3]);
|
2010-09-21 21:29:35 +02:00
|
|
|
|
2013-05-18 14:17:26 +02:00
|
|
|
// ****** convert ECEF to Lat,Lon,Alt (ITERATIVE!) *********
|
2013-06-05 20:40:49 +02:00
|
|
|
uint16_t ECEF2LLA(double ECEF[3], float LLA[3]);
|
2010-09-21 21:29:35 +02:00
|
|
|
|
2013-06-30 18:49:29 +02:00
|
|
|
void RneFromLLA(int32_t LLAi[3], float Rne[3][3]);
|
2010-09-21 21:29:35 +02:00
|
|
|
|
2013-05-18 14:17:26 +02:00
|
|
|
// ****** find rotation matrix from rotation vector
|
2011-04-10 20:33:30 +02:00
|
|
|
void Rv2Rot(float Rv[3], float R[3][3]);
|
|
|
|
|
2013-05-18 14:17:26 +02:00
|
|
|
// ****** find roll, pitch, yaw from quaternion ********
|
2011-03-02 02:25:34 +01:00
|
|
|
void Quaternion2RPY(const float q[4], float rpy[3]);
|
2010-09-21 21:29:35 +02:00
|
|
|
|
2013-05-18 14:17:26 +02:00
|
|
|
// ****** find quaternion from roll, pitch, yaw ********
|
2011-03-02 02:25:34 +01:00
|
|
|
void RPY2Quaternion(const float rpy[3], float q[4]);
|
2010-09-21 21:29:35 +02:00
|
|
|
|
2013-05-18 14:17:26 +02:00
|
|
|
// ** Find Rbe, that rotates a vector from earth fixed to body frame, from quaternion **
|
2010-09-21 21:29:35 +02:00
|
|
|
void Quaternion2R(float q[4], float Rbe[3][3]);
|
|
|
|
|
2013-05-18 14:17:26 +02:00
|
|
|
// ****** Express LLA in a local NED Base Frame ********
|
2013-06-30 18:49:29 +02:00
|
|
|
void LLA2Base(int32_t LLAi[3], double BaseECEF[3], float Rne[3][3], float NED[3]);
|
2010-09-21 21:29:35 +02:00
|
|
|
|
2013-05-18 14:17:26 +02:00
|
|
|
// ****** Express ECEF in a local NED Base Frame ********
|
2013-06-30 18:49:29 +02:00
|
|
|
void ECEF2Base(double ECEF[3], double BaseECEF[3], float Rne[3][3], float NED[3]);
|
2010-09-21 21:29:35 +02:00
|
|
|
|
2013-05-18 14:17:26 +02:00
|
|
|
// ****** convert Rotation Matrix to Quaternion ********
|
|
|
|
// ****** if R converts from e to b, q is rotation from e to b ****
|
2010-11-24 02:27:43 +01:00
|
|
|
void R2Quaternion(float R[3][3], float q[4]);
|
|
|
|
|
2013-05-18 14:17:26 +02:00
|
|
|
// ****** Rotation Matrix from Two Vector Directions ********
|
|
|
|
// ****** given two vector directions (v1 and v2) known in two frames (b and e) find Rbe ***
|
|
|
|
// ****** solution is approximate if can't be exact ***
|
2010-11-24 02:27:43 +01:00
|
|
|
uint8_t RotFrom2Vectors(const float v1b[3], const float v1e[3], const float v2b[3], const float v2e[3], float Rbe[3][3]);
|
|
|
|
|
2013-05-18 14:17:26 +02:00
|
|
|
// ****** Vector Cross Product ********
|
2010-11-24 02:27:43 +01:00
|
|
|
void CrossProduct(const float v1[3], const float v2[3], float result[3]);
|
|
|
|
|
2013-05-18 14:17:26 +02:00
|
|
|
// ****** Vector Magnitude ********
|
2010-11-24 02:27:43 +01:00
|
|
|
float VectorMagnitude(const float v[3]);
|
|
|
|
|
2011-03-02 02:25:34 +01:00
|
|
|
void quat_inverse(float q[4]);
|
|
|
|
void quat_copy(const float q[4], float qnew[4]);
|
|
|
|
void quat_mult(const float q1[4], const float q2[4], float qout[4]);
|
2011-04-15 08:37:16 +02:00
|
|
|
void rot_mult(float R[3][3], const float vec[3], float vec_out[3]);
|
2014-05-25 11:28:43 +02:00
|
|
|
/**
|
|
|
|
* matrix_mult_3x3f - perform a multiplication between two 3x3 float matrices
|
|
|
|
* result = a*b
|
|
|
|
* @param a
|
|
|
|
* @param b
|
|
|
|
* @param result
|
|
|
|
*/
|
|
|
|
inline void matrix_mult_3x3f(float a[3][3], float b[3][3], float result[3][3])
|
|
|
|
{
|
|
|
|
result[0][0] = a[0][0] * b[0][0] + a[1][0] * b[0][1] + a[2][0] * b[0][2];
|
|
|
|
result[0][1] = a[0][1] * b[0][0] + a[1][1] * b[0][1] + a[2][1] * b[0][2];
|
|
|
|
result[0][2] = a[0][2] * b[0][0] + a[1][2] * b[0][1] + a[2][2] * b[0][2];
|
|
|
|
|
|
|
|
result[1][0] = a[0][0] * b[1][0] + a[1][0] * b[1][1] + a[2][0] * b[1][2];
|
|
|
|
result[1][1] = a[0][1] * b[1][0] + a[1][1] * b[1][1] + a[2][1] * b[1][2];
|
|
|
|
result[1][2] = a[0][2] * b[1][0] + a[1][2] * b[1][1] + a[2][2] * b[1][2];
|
|
|
|
|
|
|
|
result[2][0] = a[0][0] * b[2][0] + a[1][0] * b[2][1] + a[2][0] * b[2][2];
|
|
|
|
result[2][1] = a[0][1] * b[2][0] + a[1][1] * b[2][1] + a[2][1] * b[2][2];
|
|
|
|
result[2][2] = a[0][2] * b[2][0] + a[1][2] * b[2][1] + a[2][2] * b[2][2];
|
|
|
|
}
|
|
|
|
|
2010-11-24 02:27:43 +01:00
|
|
|
|
2010-09-21 21:29:35 +02:00
|
|
|
#endif // COORDINATECONVERSIONS_H_
|