ARCS6 AR6-REV.24062600
読み取り中…
検索中…
一致する文字列を見つけられません
TransferFunction.hh
[詳解]
1
10//
11// Copyright (C) 2011-2022 Yokokura, Yuki
12// This program is free software;
13// you can redistribute it and/or modify it under the terms of the FreeBSD License.
14// For details, see the License.txt file.
15
16#ifndef TRANSFERFUNCTION
17#define TRANSFERFUNCTION
18
19#include <cassert>
20#include "Matrix.hh"
21#include "StateSpaceSystem.hh"
22
23// ARCS組込み用マクロ
24#ifdef ARCS_IN
25 // ARCSに組み込まれる場合
26 #include "ARCSassert.hh"
27 #include "ARCSeventlog.hh"
28#else
29 // ARCSに組み込まれない場合
30 #define arcs_assert(a) (assert(a))
31 #define PassedLog()
32 #define EventLog(a)
33 #define EventLogVar(a)
34#endif
35
36namespace ARCS { // ARCS名前空間
40template <size_t N, size_t D>
42 public:
45 : Sys()
46 {
47 PassedLog();
48 }
49
54 TransferFunction(const Matrix<1,N+1>& Num, const Matrix<1,D+1>& Den, const double SmplTime)
55 : Sys()
56 {
57 static_assert(N <= D); // プロパーかどうかのチェック
58 SetCoefficients(Num, Den, SmplTime);// 伝達関数の係数にセット
59 PassedLog();
60 }
61
65 : Sys(r.Sys)
66 {
67
68 }
69
74
79 void SetCoefficients(const Matrix<1,N+1>& Num, const Matrix<1,D+1>& Den, const double SmplTime){
80 // 分母の最上位係数を1に変形
81 const Matrix<1,N+1> b_n = Num/Den[1];
82 const Matrix<1,D+1> a_d = Den/Den[1];
83
84 // 可制御正準系の連続系状態空間モデルの作成
85 // A行列の生成
86 Matrix<D,D> A; // 連続系A行列
87 for(size_t i = 1; i < D; ++i){
88 A.SetElement(i + 1, i, 1);
89 }
90 for(size_t i = 1; i <= D; ++i){
91 A.SetElement(i, D, -a_d[D + 2 - i]);
92 }
93
94 // B行列の生成
95 Matrix<1,D> b; // 連続系bベクトル
96 b[D] = 1;
97
98 // C行列とD行列の生成
99 if constexpr(N != D){
100 // 直達項が無い,相対次数が1以上の場合
101 // C行列のみ生成
102 Matrix<D,1> c; // cベクトル
103 for(size_t i = 1; i <= N + 1; ++i){
104 c.SetElement(i, 1, b_n[N + 2 - i]);
105 }
106
107 // 状態空間モデルに設定
108 Sys.SetContinuous(A, b, c, SmplTime);
109 }else{
110 // 直達項が有る,相対次数が0の場合
111
112 // C行列の生成
113 Matrix<D,1> c; // cベクトル
114 for(size_t i = 1; i <= D; ++i){
115 c.SetElement(i, 1, b_n[D + 2 - i] - a_d[D + 2 - i]*b_n[1]);
116 }
117
118 // D行列の生成
119 Matrix<1,1> d; // dベクトル
120 d[1] = b_n[1];
121
122 // 状態空間モデルに設定
123 Sys.SetContinuous(A, b, c, d, SmplTime);
124 }
125 }
126
129 double GetResponse(const double u){
130 return Sys.GetNextResponse(u); // 1サンプル遅れの無い[k+1]の応答を即時に返す
131 }
132
135 double GetStrictResponse(const double u){
136 return Sys.GetResponse(u); // 1サンプル遅れの有る[k]の厳密な応答を返す
137 }
138
139 private:
140 TransferFunction(const TransferFunction&) = delete;
141 const TransferFunction& operator=(const TransferFunction&) = delete;
143};
144}
145
146#endif
147
ARCS イベントログクラス
#define PassedLog()
イベントログ用マクロ(ファイルと行番号のみ記録版)
Definition ARCSeventlog.hh:26
ARCS用ASSERTクラス
行列/ベクトル計算クラス(テンプレート版)
状態空間表現によるシステムクラス
行列/ベクトル計算クラス(テンプレート版)
Definition Matrix.hh:44
constexpr void SetElement(size_t n, size_t m, TT val)
指定した要素番号に値を設定する関数
Definition Matrix.hh:480
状態空間表現によるシステムクラス
Definition StateSpaceSystem.hh:40
void SetContinuous(const Matrix< N, N > &A, const Matrix< I, N > &B, const Matrix< N, O > &C, const double Ts)
連続系のA行列,B行列,C行列を設定して離散化する関数
Definition StateSpaceSystem.hh:92
double GetNextResponse(const double uin)
状態空間モデルの応答を計算して取得する関数(次の時刻の出力ベクトルを即時に返す版)(SISOでスカラーで返す版)
Definition StateSpaceSystem.hh:283
double GetResponse(const double uin)
状態空間モデルの応答を計算して取得する関数(SISOでスカラーで返す版)
Definition StateSpaceSystem.hh:239
伝達関数クラス
Definition TransferFunction.hh:41
double GetStrictResponse(const double u)
入力信号に対する伝達関数の厳密な応答を返す関数(1サンプル遅れ有り)
Definition TransferFunction.hh:135
TransferFunction(const Matrix< 1, N+1 > &Num, const Matrix< 1, D+1 > &Den, const double SmplTime)
コンストラクタ
Definition TransferFunction.hh:54
~TransferFunction()
デストラクタ
Definition TransferFunction.hh:71
double GetResponse(const double u)
入力信号に対する伝達関数の応答を返す関数(1サンプル遅れ無し)
Definition TransferFunction.hh:129
TransferFunction(TransferFunction &&r)
ムーブコンストラクタ
Definition TransferFunction.hh:64
TransferFunction(void)
空コンストラクタ
Definition TransferFunction.hh:44
void SetCoefficients(const Matrix< 1, N+1 > &Num, const Matrix< 1, D+1 > &Den, const double SmplTime)
伝達関数の係数を設定する関数
Definition TransferFunction.hh:79