MicroMouse Control Module  v1.3.2-2-ge2c6882
slalom.h
[詳解]
1 
8 #pragma once
9 
10 #include <ctrl/accel_designer.h>
11 #include <ctrl/pose.h>
12 #include <ctrl/state.h>
13 
14 #include <array>
15 #include <cmath>
16 #include <ostream>
17 
21 namespace ctrl {
22 
26 namespace slalom {
27 
31 static constexpr float dddth_max_default = 1200 * M_PI;
35 static constexpr float ddth_max_default = 36 * M_PI;
39 static constexpr float dth_max_default = 3 * M_PI;
40 
48 struct Shape {
51  float straight_prev;
52  float straight_post;
53  float v_ref;
54  float dddth_max;
55  float ddth_max;
56  float dth_max;
58  public:
71  Shape(const Pose& total, const float y_curve_end, const float x_adv = 0,
72  const float dddth_max = dddth_max_default,
73  const float ddth_max = ddth_max_default,
74  const float dth_max = dth_max_default)
75  : total(total),
78  dth_max(dth_max) {
79  /* 生成準備 */
80  const float Ts = 1.5e-3f; //< シミュレーションの積分周期
81  float v = 600.0f; //< 初期値
82  State s; //< シミュレーションの状態
83  AccelDesigner ad;
84  ad.reset(dddth_max, ddth_max, dth_max, 0, 0, total.th);
85  /* 複数回行って精度を高める */
86  for (int i = 0; i < 3; ++i) {
87  s.q.x = s.q.y = 0;
88  /* シミュレーション */
89  float t = 0;
90  while (t + Ts < ad.t_end()) integrate(ad, s, v, t, Ts), t += Ts;
91  integrate(ad, s, v, t, ad.t_end() - t); //< 残りの半端分を積分
92  /* 結果を用いて更新 */
93  v *= y_curve_end / s.q.y;
94  }
95  curve = s.q;
96  v_ref = v;
97  const float sin_th = std::sin(total.th);
98  const float cos_th = std::cos(total.th);
99  /* 前後の直線の長さを決定 */
100  if (std::abs(sin_th) < 1e-3f) {
101  /* 180度ターン */
102  straight_prev = x_adv;
103  straight_post = x_adv;
104  curve = total;
105  } else {
106  /* 180度ターン以外 */
107  straight_prev = total.x - s.q.x - cos_th / sin_th * (total.y - s.q.y);
108  straight_post = 1 / sin_th * (total.y - s.q.y);
109  }
110  }
123  Shape(const Pose& total, const Pose& curve, float straight_prev,
124  const float straight_post, const float v_ref, const float dddth_max,
125  const float ddth_max, const float dth_max)
126  : total(total),
127  curve(curve),
130  v_ref(v_ref),
133  dth_max(dth_max) {}
144  static void integrate(const AccelDesigner& ad, State& s, const float v,
145  const float t, const float Ts, const float k_slip = 0) {
146  /* Calculation */
147  const std::array<float, 3> th{{ad.x(t), ad.x(t + Ts / 2), ad.x(t + Ts)}};
148  const std::array<float, 3> w{{ad.v(t), ad.v(t + Ts / 2), ad.v(t + Ts)}};
149  std::array<float, 3> cos_th;
150  std::array<float, 3> sin_th;
151  for (int i = 0; i < 3; ++i) {
152  const auto th_slip = std::atan(-k_slip * v * w[i]);
153  cos_th[i] = std::cos(th[i] + th_slip);
154  sin_th[i] = std::sin(th[i] + th_slip);
155  }
156  /* Runge-Kutta Integral */
157  s.q.x += v * Ts * (cos_th[0] + 4 * cos_th[1] + cos_th[2]) / 6;
158  s.q.y += v * Ts * (sin_th[0] + 4 * sin_th[1] + sin_th[2]) / 6;
159  /* Result */
160  s.dq.x = v * cos_th[2];
161  s.dq.y = v * sin_th[2];
162  s.q.th = ad.x(t + Ts);
163  s.dq.th = ad.v(t + Ts);
164  s.ddq.th = ad.a(t + Ts);
165  s.dddq.th = ad.j(t + Ts);
166  s.ddq.x = -s.dq.y * s.dq.th;
167  s.ddq.y = +s.dq.x * s.dq.th;
168  s.dddq.x = -s.ddq.y * s.dq.th - s.dq.y * s.ddq.th;
169  s.dddq.y = +s.ddq.x * s.dq.th + s.dq.x * s.ddq.th;
170  }
174  friend std::ostream& operator<<(std::ostream& os, const Shape& obj) {
175  os << "Slalom Shape" << std::endl;
176  os << "\ttotal:\t" << obj.total << std::endl;
177  os << "\tcurve:\t" << obj.curve << std::endl;
178  os << "\tv_ref:\t" << obj.v_ref << std::endl;
179  os << "\tstraight_prev:\t" << obj.straight_prev << std::endl;
180  os << "\tstraight_post:\t" << obj.straight_post << std::endl;
181  auto end = Pose(obj.straight_prev) + obj.curve +
182  Pose(obj.straight_post).rotate(obj.curve.th);
183  os << "\tintegral error:\t" << obj.total - end << std::endl;
184  return os;
185  }
186 };
187 
188 } // namespace slalom
189 } // namespace ctrl
距離の拘束を満たす加減速走行軌道を生成するクラスを保持するファイル
拘束条件を満たす曲線加減速の軌道を生成するクラス
Definition: accel_designer.h:33
float j(const float t) const
任意の時刻 t [s] における躍度 j [m/s/s/s] を返す関数
Definition: accel_designer.h:167
float a(const float t) const
任意の時刻 t [s] における加速度 a [m/s/s] を返す関数
Definition: accel_designer.h:178
float t_end() const
終点時刻 [s]
Definition: accel_designer.h:209
float x(const float t) const
任意の時刻 t [s] における位置 x [m] を返す関数
Definition: accel_designer.h:200
float v(const float t) const
任意の時刻 t [s] における速度 v [m/s] を返す関数
Definition: accel_designer.h:189
void reset(const float j_max, const float a_max, const float v_max, const float v_start, const float v_target, const float dist, const float x_start=0, const float t_start=0)
引数の拘束条件から曲線を生成する関数
Definition: accel_designer.h:70
static constexpr float dth_max_default
最大角速度のデフォルト値 [rad/s]
Definition: slalom.h:39
static constexpr float dddth_max_default
最大角躍度のデフォルト値 [rad/s/s/s]
Definition: slalom.h:31
static constexpr float ddth_max_default
最大角加速度のデフォルト値 [rad/s/s]
Definition: slalom.h:35
制御関係の名前空間
Definition: accel_curve.h:54
平面上の位置姿勢の座標もつファイル。
軌道制御の状態変数
位置姿勢の座標
Definition: pose.h:18
float y
y 成分 [m]
Definition: pose.h:20
Pose rotate(const float angle) const
Definition: pose.h:28
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
slalom::Shape スラロームの形状を表す構造体
Definition: slalom.h:48
float v_ref
カーブ部分の基準速度 [m/s]
Definition: slalom.h:53
Pose total
前後の直線を含めた移動位置姿勢
Definition: slalom.h:49
Pose curve
カーブ部分の移動位置姿勢
Definition: slalom.h:50
static void integrate(const AccelDesigner &ad, State &s, const float v, const float t, const float Ts, const float k_slip=0)
軌道の積分を行う関数。ルンゲクッタ法を使用して数値積分を行う。
Definition: slalom.h:144
float dddth_max
最大角躍度の大きさ [rad/s/s/s]
Definition: slalom.h:54
friend std::ostream & operator<<(std::ostream &os, const Shape &obj)
情報の表示
Definition: slalom.h:174
float ddth_max
最大角加速度の大きさ [rad/s/s]
Definition: slalom.h:55
float straight_prev
カーブ前の直線の距離 [m]
Definition: slalom.h:51
float straight_post
カーブ後の直線の距離 [m]
Definition: slalom.h:52
Shape(const Pose &total, const float y_curve_end, const float x_adv=0, const float dddth_max=dddth_max_default, const float ddth_max=ddth_max_default, const float dth_max=dth_max_default)
拘束条件からスラローム形状を生成するコンストラクタ
Definition: slalom.h:71
float dth_max
最大角速度の大きさ [rad/s]
Definition: slalom.h:56
Shape(const Pose &total, const Pose &curve, float straight_prev, const float straight_post, const float v_ref, const float dddth_max, const float ddth_max, const float dth_max)
生成済みスラローム形状を単に代入するコンストラクタ
Definition: slalom.h:123