MicroMouse Control Module  v1.3.2-2-ge2c6882
trajectory_tracker.h
[詳解]
1 
10 #pragma once
11 
12 #include "polar.h"
13 #include "pose.h"
14 #include "state.h"
15 
19 namespace ctrl {
20 
25  public:
29  static constexpr const float kIntegrationPeriodDefault = 1e-3f;
33  static constexpr const float kXiThresholdDefault = 150.0f;
37  struct Gain {
38  float zeta = 1.0f;
39  float omega_n = 15.0f;
40  float low_zeta = 1.0f; //< zeta \in [0,1]
41  float low_b = 1e-3f; //< b > 0
42  };
46  struct Result {
47  float v; //**< @brief 並進速度 [mm/s]
48  float w; //**< @brief 角速度 [rad/s]
49  float dv; //**< @brief 並進加速度 [mm/s/s]
50  float dw; //**< @brief 角加速度 [rad/s/s]
51  };
58  static constexpr float sinc(const float x) {
59  const auto xx = x * x;
60  const auto xxxx = xx * xx;
61  return xxxx * xxxx / 362880 - xxxx * xx / 5040 + xxxx / 120 - xx / 6 + 1;
62  }
63 
64  public:
72  const float xi_threshold = kXiThresholdDefault)
79  void reset(const float vs = 0) { xi = vs; }
90  const Result update(const Pose& est_q, const Polar& est_v, const Polar& est_a,
91  const State& ref_s,
92  const float Ts = kIntegrationPeriodDefault) {
93  return update(est_q, est_v, est_a, ref_s.q, ref_s.dq, ref_s.ddq, ref_s.dddq,
94  Ts);
95  }
109  const Result update(const Pose& est_q, const Polar& est_v, const Polar& est_a,
110  const Pose& ref_q, const Pose& ref_dq,
111  const Pose& ref_ddq, const Pose& ref_dddq,
112  const float Ts = kIntegrationPeriodDefault) {
113  /* Prepare Variable */
114  const float x = est_q.x;
115  const float y = est_q.y;
116  const float theta = est_q.th;
117  const float cos_theta = std::cos(theta);
118  const float sin_theta = std::sin(theta);
119  const float dx = est_v.tra * cos_theta;
120  const float dy = est_v.tra * sin_theta;
121  const float ddx = est_a.tra * cos_theta;
122  const float ddy = est_a.tra * sin_theta;
123  /* Feedback Gain Design */
124  const float zeta = gain.zeta;
125  const float omega_n = gain.omega_n;
126  const float kx = omega_n * omega_n;
127  const float kdx = 2 * zeta * omega_n;
128  const float ky = kx;
129  const float kdy = kdx;
130  /* Determine Reference */
131  const float dddx_r = ref_dddq.x;
132  const float dddy_r = ref_dddq.y;
133  const float ddx_r = ref_ddq.x;
134  const float ddy_r = ref_ddq.y;
135  const float dx_r = ref_dq.x;
136  const float dy_r = ref_dq.y;
137  const float x_r = ref_q.x;
138  const float y_r = ref_q.y;
139  const float th_r = ref_q.th;
140  const float cos_th_r = std::cos(th_r);
141  const float sin_th_r = std::sin(th_r);
142  const float u1 = ddx_r + kdx * (dx_r - dx) + kx * (x_r - x);
143  const float u2 = ddy_r + kdy * (dy_r - dy) + ky * (y_r - y);
144  const float du1 = dddx_r + kdx * (ddx_r - ddx) + kx * (dx_r - dx);
145  const float du2 = dddy_r + kdy * (ddy_r - ddy) + ky * (dy_r - dy);
146  const float d_xi = u1 * cos_th_r + u2 * sin_th_r;
147  /* integral the state(s) */
148  xi += d_xi * Ts;
149  /* determine the output signal */
150  Result res;
151  if (std::abs(xi) < xi_threshold) {
152  const auto b = gain.low_b; //< b > 0
153  const auto zeta = gain.low_zeta; //< zeta \in [0,1]
154  const auto v_d = ref_dq.x * cos_th_r + ref_dq.y * sin_th_r;
155  const auto w_d = ref_dq.th;
156  const auto k1 = 2 * zeta * std::sqrt(w_d * w_d + b * v_d * v_d);
157  const auto k2 = b;
158  const auto k3 = k1;
159  const auto v = v_d * std::cos(th_r - theta) +
160  k1 * (cos_theta * (x_r - x) + sin_theta * (y_r - y));
161  const auto w = w_d +
162  k2 * v_d * sinc(th_r - theta) *
163  (-sin_theta * (x_r - x) + cos_theta * (y_r - y)) +
164  k3 * (th_r - theta);
165  res.v = v;
166  res.w = w;
167  res.dv = ref_ddq.x * cos_th_r + ref_ddq.y * sin_th_r;
168  res.dw = ref_ddq.th;
169  // res.v = ref_dq.x * cos_th_r + ref_dq.y * sin_th_r;
170  // res.w = red_dq.th;
171  // res.dv = ref_ddq.x * cos_th_r + ref_ddq.y * sin_th_r;
172  // res.dw = ref_ddq.th;
173  } else {
174  res.v = xi;
175  res.dv = d_xi;
176  res.w = (u2 * cos_th_r - u1 * sin_th_r) / xi;
177  res.dw = -(2 * d_xi * res.w + du1 * sin_th_r - du2 * cos_th_r) / xi;
178  }
179  return res;
180  }
181 
182  protected:
184  float xi;
185  float xi_threshold;
186 };
187 
188 } // namespace ctrl
独立2輪車の軌道追従フィードバック制御器
Definition: trajectory_tracker.h:24
float xi_threshold
制御則を切り替える閾値
Definition: trajectory_tracker.h:185
TrajectoryTracker(const Gain &gain, const float xi_threshold=kXiThresholdDefault)
コンストラクタ
Definition: trajectory_tracker.h:71
static constexpr const float kXiThresholdDefault
制御則の切り替え閾値のデフォルト値 [mm/s]
Definition: trajectory_tracker.h:33
const Result update(const Pose &est_q, const Polar &est_v, const Polar &est_a, const State &ref_s, const float Ts=kIntegrationPeriodDefault)
制御入力の計算
Definition: trajectory_tracker.h:90
float xi
補助状態変数
Definition: trajectory_tracker.h:184
void reset(const float vs=0)
状態の初期化
Definition: trajectory_tracker.h:79
static constexpr float sinc(const float x)
自作の sinc 関数 sinc(x) := sin(x) / x
Definition: trajectory_tracker.h:58
Gain gain
フィードバックゲイン
Definition: trajectory_tracker.h:183
const Result update(const Pose &est_q, const Polar &est_v, const Polar &est_a, const Pose &ref_q, const Pose &ref_dq, const Pose &ref_ddq, const Pose &ref_dddq, const float Ts=kIntegrationPeriodDefault)
制御入力の計算
Definition: trajectory_tracker.h:109
static constexpr const float kIntegrationPeriodDefault
制御周期(積分周期)のデフォルト値 [s]
Definition: trajectory_tracker.h:29
制御関係の名前空間
Definition: accel_curve.h:54
並進と回転の座標を管理するクラスをもつファイル
平面上の位置姿勢の座標もつファイル。
軌道制御の状態変数
並進と回転の座標
Definition: polar.h:17
float tra
Definition: polar.h:18
位置姿勢の座標
Definition: pose.h:18
float y
y 成分 [m]
Definition: pose.h:20
float x
x 成分 [m]
Definition: pose.h:19
float th
theta 成分 [rad]
Definition: pose.h:21
軌道制御の状態変数
Definition: state.h:20
Pose dq
Definition: state.h:22
Pose q
Definition: state.h:21
Pose dddq
Definition: state.h:24
Pose ddq
Definition: state.h:23
フィードバックゲインを格納する構造体
Definition: trajectory_tracker.h:37
float low_b
Definition: trajectory_tracker.h:41
float low_zeta
Definition: trajectory_tracker.h:40
float omega_n
Definition: trajectory_tracker.h:39
float zeta
Definition: trajectory_tracker.h:38
計算結果を格納する構造体
Definition: trajectory_tracker.h:46
float dw
Definition: trajectory_tracker.h:50
float w
Definition: trajectory_tracker.h:48
float dv
Definition: trajectory_tracker.h:49
float v
Definition: trajectory_tracker.h:47