慣性航法で用いられる座標変換をプログラムにしました。ECI座標の初期位置を設定した後、ECI,ECEF,NED,機体座標系の変換を行います。行列計算の方法や値の設定などは、ヘッダーファイル内の記述を見れば分かると思います。 また計算結果はTeratermで確認する事が出来ます。 (行列を見る場合はtoString関数、ベクトルを見る場合はtoString_V関数を使用します)

Dependencies:   mbed

Committer:
Joeatsumi
Date:
Wed Jan 30 11:39:03 2019 +0000
Revision:
0:6a28eb668082
Direction cosine matrix and it's calculation.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Joeatsumi 0:6a28eb668082 1 #pragma once
Joeatsumi 0:6a28eb668082 2 #include "mbed.h"
Joeatsumi 0:6a28eb668082 3
Joeatsumi 0:6a28eb668082 4 class Matrix
Joeatsumi 0:6a28eb668082 5 {
Joeatsumi 0:6a28eb668082 6 public:
Joeatsumi 0:6a28eb668082 7 /********** コンストラクタ デストラクタ **********/
Joeatsumi 0:6a28eb668082 8 Matrix(int row, int col);
Joeatsumi 0:6a28eb668082 9 Matrix(int row, int col, float* comps);
Joeatsumi 0:6a28eb668082 10 ~Matrix();
Joeatsumi 0:6a28eb668082 11 Matrix(const Matrix& m);
Joeatsumi 0:6a28eb668082 12
Joeatsumi 0:6a28eb668082 13 /********** メンバ演算子 **********/
Joeatsumi 0:6a28eb668082 14 Matrix operator-() const;
Joeatsumi 0:6a28eb668082 15 Matrix& operator=(const Matrix& m);
Joeatsumi 0:6a28eb668082 16 Matrix& operator+=(const Matrix& m);
Joeatsumi 0:6a28eb668082 17 Matrix& operator-=(const Matrix& m);
Joeatsumi 0:6a28eb668082 18 //Matrix& operator*=(const Matrix& m);
Joeatsumi 0:6a28eb668082 19 Matrix& operator*=(float c);
Joeatsumi 0:6a28eb668082 20 Matrix& operator/=(float c);
Joeatsumi 0:6a28eb668082 21
Joeatsumi 0:6a28eb668082 22 /********** その他関数 **********/
Joeatsumi 0:6a28eb668082 23 /*
Joeatsumi 0:6a28eb668082 24 行列の成分を設定
Joeatsumi 0:6a28eb668082 25 引数:rowNo 行番号
Joeatsumi 0:6a28eb668082 26 colNo 列番号
Joeatsumi 0:6a28eb668082 27 val 設定値
Joeatsumi 0:6a28eb668082 28 */
Joeatsumi 0:6a28eb668082 29 void SetComp(int rowNo, int colNo, float val);
Joeatsumi 0:6a28eb668082 30
Joeatsumi 0:6a28eb668082 31 /*
Joeatsumi 0:6a28eb668082 32 行列の成分を全て設定。全成分を一度に指定する必要がある。
Joeatsumi 0:6a28eb668082 33 引数:pComps 設定値の入ったfloat配列。
Joeatsumi 0:6a28eb668082 34 */
Joeatsumi 0:6a28eb668082 35 void SetComps(float* pComps);
Joeatsumi 0:6a28eb668082 36 /*
Joeatsumi 0:6a28eb668082 37 行列式を計算する。行列が正方行列で無い場合にはエラー。
Joeatsumi 0:6a28eb668082 38 */
Joeatsumi 0:6a28eb668082 39 float Determinant() const;
Joeatsumi 0:6a28eb668082 40
Joeatsumi 0:6a28eb668082 41 /*
Joeatsumi 0:6a28eb668082 42 行列式を計算する。行列が正方行列で無い場合にはエラー。
Joeatsumi 0:6a28eb668082 43 */
Joeatsumi 0:6a28eb668082 44 float det() const;
Joeatsumi 0:6a28eb668082 45
Joeatsumi 0:6a28eb668082 46 /*
Joeatsumi 0:6a28eb668082 47 行列をLU分解する
Joeatsumi 0:6a28eb668082 48 引数:sign (省略可)置換操作の符号を格納するポインタ
Joeatsumi 0:6a28eb668082 49 p (省略可)置換行列を格納する行列のポインタ。(分解する行列と同じ列数の正方行列)
Joeatsumi 0:6a28eb668082 50 返り値:LU分解後の行列。下三角要素がL、対角・上三角要素がUに対応する。
Joeatsumi 0:6a28eb668082 51 */
Joeatsumi 0:6a28eb668082 52 Matrix LU_Decompose(int* sign = 0, Matrix * p = 0) const;
Joeatsumi 0:6a28eb668082 53
Joeatsumi 0:6a28eb668082 54 /*
Joeatsumi 0:6a28eb668082 55 逆行列を生成する
Joeatsumi 0:6a28eb668082 56 返り値で逆行列が存在するか否かを判断
Joeatsumi 0:6a28eb668082 57 引数:逆行列を格納する行列
Joeatsumi 0:6a28eb668082 58 返り値:逆行列が存在するか否か
Joeatsumi 0:6a28eb668082 59 */
Joeatsumi 0:6a28eb668082 60 float Inverse(Matrix& invm) const;
Joeatsumi 0:6a28eb668082 61
Joeatsumi 0:6a28eb668082 62 /*
Joeatsumi 0:6a28eb668082 63 転置行列を生成する
Joeatsumi 0:6a28eb668082 64 返り値:転置行列
Joeatsumi 0:6a28eb668082 65 */
Joeatsumi 0:6a28eb668082 66 Matrix Transpose() const;
Joeatsumi 0:6a28eb668082 67
Joeatsumi 0:6a28eb668082 68 /*
Joeatsumi 0:6a28eb668082 69 行列の行の入れ替えを行う
Joeatsumi 0:6a28eb668082 70 引数:rowNo1 行番号1
Joeatsumi 0:6a28eb668082 71 rowNo2 行番号2
Joeatsumi 0:6a28eb668082 72 */
Joeatsumi 0:6a28eb668082 73 void SwapRow(int rowNo1, int rowNo2);
Joeatsumi 0:6a28eb668082 74 /*
Joeatsumi 0:6a28eb668082 75 行列の列の入れ替えを行う
Joeatsumi 0:6a28eb668082 76 引数:colNo1 列番号1
Joeatsumi 0:6a28eb668082 77 colNo2 列番号2
Joeatsumi 0:6a28eb668082 78 */
Joeatsumi 0:6a28eb668082 79 void SwapCol(int colNo1, int colNo2);
Joeatsumi 0:6a28eb668082 80
Joeatsumi 0:6a28eb668082 81 /********** インライン関数 **********/
Joeatsumi 0:6a28eb668082 82 inline int GetRow() const {
Joeatsumi 0:6a28eb668082 83 return row;
Joeatsumi 0:6a28eb668082 84 }
Joeatsumi 0:6a28eb668082 85
Joeatsumi 0:6a28eb668082 86 inline int GetCol() const {
Joeatsumi 0:6a28eb668082 87 return col;
Joeatsumi 0:6a28eb668082 88 }
Joeatsumi 0:6a28eb668082 89
Joeatsumi 0:6a28eb668082 90 inline const float* GetpComponents() const {
Joeatsumi 0:6a28eb668082 91 return (const float*)components;
Joeatsumi 0:6a28eb668082 92 }
Joeatsumi 0:6a28eb668082 93
Joeatsumi 0:6a28eb668082 94 inline float GetComp(int rowNo, int colNo) const {
Joeatsumi 0:6a28eb668082 95 if (rowNo > row || colNo > col) error("Index Out of Bounds Error !!");
Joeatsumi 0:6a28eb668082 96 return components[(rowNo-1)*col + (colNo-1)];
Joeatsumi 0:6a28eb668082 97 }
Joeatsumi 0:6a28eb668082 98
Joeatsumi 0:6a28eb668082 99 private:
Joeatsumi 0:6a28eb668082 100 int row;
Joeatsumi 0:6a28eb668082 101 int col;
Joeatsumi 0:6a28eb668082 102 float* components;
Joeatsumi 0:6a28eb668082 103
Joeatsumi 0:6a28eb668082 104 /*
Joeatsumi 0:6a28eb668082 105 行列の成分の中で無視できるほど小さい値を0と置き換える(掃除する)
Joeatsumi 0:6a28eb668082 106 */
Joeatsumi 0:6a28eb668082 107 void CleanUp();
Joeatsumi 0:6a28eb668082 108
Joeatsumi 0:6a28eb668082 109 };
Joeatsumi 0:6a28eb668082 110
Joeatsumi 0:6a28eb668082 111 // グローバル演算子
Joeatsumi 0:6a28eb668082 112 Matrix operator+(const Matrix& lhm, const Matrix& rhm);
Joeatsumi 0:6a28eb668082 113 Matrix operator-(const Matrix& lhm, const Matrix& rhm);
Joeatsumi 0:6a28eb668082 114 Matrix operator*(const Matrix& lhm, const Matrix& rhm);
Joeatsumi 0:6a28eb668082 115