ARCS6 AR6-REV.24062600
読み取り中…
検索中…
一致する文字列を見つけられません
DisturbanceObsrv.hh
[詳解]
1
9//
10// Copyright (C) 2011-2022 Yokokura, Yuki
11// This program is free software;
12// you can redistribute it and/or modify it under the terms of the FreeBSD License.
13// For details, see the License.txt file.
14
15#ifndef DISTURBANCEOBSRV
16#define DISTURBANCEOBSRV
17
18#include <array>
19#include "Matrix.hh"
20#include "Discret.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名前空間
38 enum class DObType {
39 FULL_0TH,
41 };
42
46 template <DObType T, size_t N = 1>
48 public:
54 DisturbanceObsrv(const double TrqConst, const double Inertia, const double Bandwidth, const double SmplTime)
55 : u(), tdis(), uVec(), tdisVec(), DOb(), DObVec()
56 {
57 SetStateSpaceModel(TrqConst, Inertia, Bandwidth, SmplTime, DOb); // 状態空間モデルに設定
58 PassedLog();
59 }
60
66 DisturbanceObsrv(const Matrix<1,N>& TrqConst, const Matrix<1,N>& Inertia, const Matrix<1,N>& Bandwidth, const double SmplTime)
67 : u(), tdis(), uVec(), tdisVec(), DOb(), DObVec()
68 {
69 // オブザーバの個数(=ベクトルの長さ)分だけ回す
70 for(size_t i = 1; i <= N; ++i){
71 SetStateSpaceModel(TrqConst[i], Inertia[i], Bandwidth[i], SmplTime, DObVec.at(i-1)); // 状態空間モデルに設定
72 }
73 PassedLog();
74 }
75
78 : u(), tdis(), uVec(), tdisVec(), DOb(r.DOb), DObVec(r.DObVec)
79 {
80
81 }
82
87
91 double GetDistTorque(const double Current, const double MotorSpeed){
92 // 入力ベクトルの設定
93 u.Set(
94 Current,
95 MotorSpeed
96 );
97
98 // 状態空間モデルで外乱を推定
99 tdis = DOb.GetNextResponses(u);
100
101 return tdis[1]; // 推定外乱を返す
102 }
103
107 Matrix<1,N> GetDistTorque(const Matrix<1,N>& Current, const Matrix<1,N>& MotorSpeed){
108 Matrix<1,N> ret;
109 // オブザーバの個数(=ベクトルの長さ)分だけ回す
110 for(size_t i = 1; i <= N; ++i){
111 // 入力ベクトルの設定
112 uVec.at(i-1).Set(
113 Current[i],
114 MotorSpeed[i]
115 );
116
117 // 状態空間モデルで外乱を推定
118 tdisVec.at(i-1) = DObVec.at(i-1).GetNextResponses(uVec.at(i-1));
119 ret[i] = tdisVec.at(i-1)[1]; // [1×1]のN個の行列を[1×N]の縦ベクトルに変換
120 }
121 return ret;
122 }
123
126 if constexpr(N == 1){
127 // スカラー版のとき
128 DOb.ClearStateVector(); // 状態ベクトルをクリア
129 }else{
130 // ベクトル版のとき
131 // ベクトルの長さだけ回す
132 for(size_t i = 0; i < N; ++i){
133 DObVec[i].ClearStateVector(); // 状態ベクトルをクリア
134 }
135 }
136 }
137
138 private:
139 DisturbanceObsrv(const DisturbanceObsrv&) = delete;
140 const DisturbanceObsrv& operator=(const DisturbanceObsrv&) = delete;
141
143 static constexpr size_t GetOrder(void){
144 if constexpr(T == DObType::FULL_0TH) return 2;
145 if constexpr(T == DObType::FULL_1ST) return 3;
146 return 0;
147 }
148
149 Matrix<1,2> u;
150 Matrix<1,1> tdis;
151 std::array<Matrix<1,2>, N> uVec;
152 std::array<Matrix<1,1>, N> tdisVec;
153
154 // 外乱オブザーバの本体
155 StateSpaceSystem<GetOrder(), 2, 1> DOb;
156 std::array<StateSpaceSystem<GetOrder(), 2, 1>, N> DObVec;
157
164 void SetStateSpaceModel(const double Ktn, const double Jmn, const double gdis, const double Ts,
165 StateSpaceSystem<GetOrder(), 2, 1>& DObSys
166 ){
167 // オブザーバゲインの設定
168 const double l1 = -gdis; // -gdis [rad/s] の重根設定
169 const double l2 = -gdis; // -gdis [rad/s] の重根設定
170 const double l3 = -gdis; // -gdis [rad/s] の重根設定
171
172 // オブザーバの構成によって状態方程式を変える
173
174 // 同一次元0次オブザーバの場合
175 if constexpr(T == DObType::FULL_0TH){
176 // 連続系A行列の設定
177 const Matrix<2,2> A = {
178 l1 + l2, -1.0/Jmn,
179 Jmn*l1*l2, 0
180 };
181
182 // 連続系B行列の設定
183 const Matrix<2,2> B = {
184 Ktn/Jmn, - l1 - l2,
185 0, -Jmn*l1*l2
186 };
187
188 // C行列の設定
189 const Matrix<2,1> c = {
190 0, 1
191 };
192
193 DObSys.SetContinuous(A, B, c, Ts); // 状態空間モデルに設定
194 }
195
196 // 同一次元1次オブザーバの場合
197 if constexpr(T == DObType::FULL_1ST){
198 // 連続系のA行列
199 const Matrix<3,3> A = {
200 l1 + l2 + l3 , -1.0/Jmn, 0,
201 Jmn*(l1*l2 + l2*l3 + l3*l1), 0 , 1,
202 -Jmn*l1*l2*l3 , 0 , 0
203 };
204
205 // 連続系のB行列
206 const Matrix<2,3> B = {
207 Ktn/Jmn, -( l1 + l2 + l3 ),
208 0 , -Jmn*( l1*l2 + l2*l3 + l3*l1 ),
209 0 , Jmn*l1*l2*l3
210 };
211
212 // C行列
213 const Matrix<3,1> c = {
214 0, 1, 0
215 };
216
217 DObSys.SetContinuous(A, B, c, Ts); // 状態空間モデルに設定
218 }
219 }
220
221 };
222}
223
224#endif
225
ARCS イベントログクラス
#define PassedLog()
イベントログ用マクロ(ファイルと行番号のみ記録版)
Definition ARCSeventlog.hh:26
ARCS用ASSERTクラス
行列/ベクトル計算クラス(テンプレート版)
離散化クラス(テンプレート版) !!!注意喚起:このクラスは将来的に廃止予定です。代わりに、ArcsControlDiscretizeを使用して下さい。
DObType
外乱オブザーバのタイプの定義
Definition DisturbanceObsrv.hh:38
@ FULL_1ST
同一次元1次外乱オブザーバ
@ FULL_0TH
同一次元0次外乱オブザーバ
状態空間表現によるシステムクラス
外乱オブザーバクラス
Definition DisturbanceObsrv.hh:47
DisturbanceObsrv(DisturbanceObsrv &&r)
ムーブコンストラクタ
Definition DisturbanceObsrv.hh:77
DisturbanceObsrv(const double TrqConst, const double Inertia, const double Bandwidth, const double SmplTime)
コンストラクタ(スカラー版)
Definition DisturbanceObsrv.hh:54
void ClearStateVector(void)
状態ベクトルをクリアする関数
Definition DisturbanceObsrv.hh:125
Matrix< 1, N > GetDistTorque(const Matrix< 1, N > &Current, const Matrix< 1, N > &MotorSpeed)
外乱トルクを推定する関数(ベクトル版)
Definition DisturbanceObsrv.hh:107
DisturbanceObsrv(const Matrix< 1, N > &TrqConst, const Matrix< 1, N > &Inertia, const Matrix< 1, N > &Bandwidth, const double SmplTime)
コンストラクタ(ベクトル版)
Definition DisturbanceObsrv.hh:66
~DisturbanceObsrv()
デストラクタ
Definition DisturbanceObsrv.hh:84
double GetDistTorque(const double Current, const double MotorSpeed)
外乱トルクを推定する関数(スカラー版)
Definition DisturbanceObsrv.hh:91
行列/ベクトル計算クラス(テンプレート版)
Definition Matrix.hh:44
constexpr void Set(const T1 &u1, const T2 &... u2)
行列要素に値を設定する関数
Definition Matrix.hh:385
void GetNextResponses(const Matrix< 1, I > &uin, Matrix< 1, O > &yout)
状態空間モデルの応答を計算して取得する関数(次の時刻の出力ベクトルを即時に返す版)
Definition StateSpaceSystem.hh:265
void ClearStateVector(void)
状態ベクトルをクリアする関数
Definition StateSpaceSystem.hh:306