走行距離拘束のない曲線加速の軌道を生成するクラス
[詳解]
#include <accel_curve.h>
|
| AccelCurve (const float j_max, const float a_max, const float v_start, const float v_end) |
| 初期化付きのコンストラクタ [詳解]
|
|
| AccelCurve () |
| とりあえずインスタンス化を行う空のコンストラクタ [詳解]
|
|
void | reset (const float j_max, const float a_max, const float v_start, const float v_end) |
| 引数の拘束条件から曲線を生成する関数 [詳解]
|
|
float | j (const float t) const |
| 任意の時刻 t [s] における躍度 j [m/s/s/s] を返す関数 [詳解]
|
|
float | a (const float t) const |
| 任意の時刻 t [s] における加速度 a [m/s/s] を返す関数 [詳解]
|
|
float | v (const float t) const |
| 任意の時刻 t [s] における速度 v [m/s] を返す関数 [詳解]
|
|
float | x (const float t) const |
| 任意の時刻 t [s] における位置 x [m] を返す関数 [詳解]
|
|
float | t_end () const |
| 終点時刻 [s] [詳解]
|
|
float | v_end () const |
| 終点速度 [m/s] [詳解]
|
|
float | x_end () const |
| 終点位置 [m] [詳解]
|
|
float | t_0 () const |
| 曲線加速の開始時刻 [s] [詳解]
|
|
float | t_1 () const |
| 等加速度直線運動の開始時刻 [s] [詳解]
|
|
float | t_2 () const |
| 等加速度直線運動の終了時刻 [s] [詳解]
|
|
float | t_3 () const |
| 曲線加速の終了時刻 [s] [詳解]
|
|
const std::array< float, 4 > | getTimeStamps () const |
| 境界のタイムスタンプをまとめて取得する関数 [詳解]
|
|
void | printCsv (std::ostream &os, const float t_interval=1e-3f) const |
| std::ostream に軌道のcsvを出力する関数 [詳解]
|
|
|
static float | calcReachableVelocityEnd (const float j_max, const float a_max, const float vs, const float vt, const float d) |
| 走行距離の拘束から達しうる終点速度を算出する関数 [詳解]
|
|
static float | calcReachableVelocityMax (const float j_max, const float a_max, const float vs, const float ve, const float d) |
| 走行距離の拘束から達しうる最大速度を算出する関数 [詳解]
|
|
static float | calcDistanceFromVelocityStartToEnd (const float j_max, const float a_max, const float v_start, const float v_end) |
| 速度差の拘束から達しうる変位を算出する関数 [詳解]
|
|
走行距離拘束のない曲線加速の軌道を生成するクラス
- 引数の拘束に従って加速曲線を生成する
- 始点速度と終点速度を滑らかにつなぐ
- 移動距離の拘束はない
- 始点速度および終点速度は、正でも負でも可
◆ AccelCurve() [1/2]
ctrl::AccelCurve::AccelCurve |
( |
const float |
j_max, |
|
|
const float |
a_max, |
|
|
const float |
v_start, |
|
|
const float |
v_end |
|
) |
| |
|
inline |
初期化付きのコンストラクタ
- 引数
-
[in] | j_max | 最大躍度の大きさ [m/s/s/s], 正であること |
[in] | a_max | 最大加速度の大きさ [m/s/s], 正であること |
[in] | v_start | 始点速度 [m/s] |
[in] | v_end | 終点速度 [m/s] |
void reset(const float j_max, const float a_max, const float v_start, const float v_end)
引数の拘束条件から曲線を生成する関数
Definition: accel_curve.h:92
float v_end() const
終点速度 [m/s]
Definition: accel_curve.h:202
◆ AccelCurve() [2/2]
ctrl::AccelCurve::AccelCurve |
( |
| ) |
|
|
inline |
とりあえずインスタンス化を行う空のコンストラクタ
- 注意
- 別途 reset() により初期化すること。
float x3
位置定数 [m]
Definition: accel_curve.h:369
float am
加速度定数 [m/s/s]
Definition: accel_curve.h:366
float t2
Definition: accel_curve.h:367
float t1
Definition: accel_curve.h:367
float x0
Definition: accel_curve.h:369
float v1
Definition: accel_curve.h:368
float jm
躍度定数 [m/s/s/s]
Definition: accel_curve.h:365
float v2
Definition: accel_curve.h:368
float t3
時刻定数 [s]
Definition: accel_curve.h:367
float v3
速度定数 [m/s]
Definition: accel_curve.h:368
float v0
Definition: accel_curve.h:368
float x2
Definition: accel_curve.h:369
float x1
Definition: accel_curve.h:369
float t0
Definition: accel_curve.h:367
◆ a()
float ctrl::AccelCurve::a |
( |
const float |
t | ) |
const |
|
inline |
任意の時刻 t [s] における加速度 a [m/s/s] を返す関数
- 引数
-
- 戻り値
- 加速度 [m/s/s]
153 return jm * (t -
t0);
157 return -
jm * (t -
t3);
◆ calcDistanceFromVelocityStartToEnd()
static float ctrl::AccelCurve::calcDistanceFromVelocityStartToEnd |
( |
const float |
j_max, |
|
|
const float |
a_max, |
|
|
const float |
v_start, |
|
|
const float |
v_end |
|
) |
| |
|
inlinestatic |
速度差の拘束から達しうる変位を算出する関数
- 引数
-
[in] | j_max | 最大躍度の大きさ [m/s/s/s], 正であること |
[in] | a_max | 最大加速度の大きさ [m/s/s], 正であること |
[in] | v_start | 始点速度 [m/s] |
[in] | v_end | 終点速度 [m/s] |
- 戻り値
- d 変位 [m]
350 const auto ve_minus_vs =
v_end - v_start;
352 const auto am = (ve_minus_vs > 0) ? a_max : -a_max;
353 const auto jm = (ve_minus_vs > 0) ? j_max : -j_max;
355 const auto tc = a_max / j_max;
357 const auto tm = ve_minus_vs /
am - tc;
360 (tm > 0) ? (tc + tm + tc) : (2 * std::sqrt(ve_minus_vs /
jm));
361 return (v_start +
v_end) / 2 * t_all;
◆ calcReachableVelocityEnd()
static float ctrl::AccelCurve::calcReachableVelocityEnd |
( |
const float |
j_max, |
|
|
const float |
a_max, |
|
|
const float |
vs, |
|
|
const float |
vt, |
|
|
const float |
d |
|
) |
| |
|
inlinestatic |
走行距離の拘束から達しうる終点速度を算出する関数
- 引数
-
[in] | j_max | 最大躍度の大きさ [m/s/s/s], 正であること |
[in] | a_max | 最大加速度の大きさ [m/s/s], 正であること |
[in] | vs | 始点速度 [m/s] |
[in] | vt | 目標速度 [m/s] |
[in] | d | 走行距離 [m] |
- 戻り値
- ve 終点速度 [m/s]
267 const auto tc = a_max / j_max;
269 const auto am = (vt > vs) ? a_max : -a_max;
270 const auto jm = (vt > vs) ? j_max : -j_max;
272 const auto d_triangle = (vs +
am * tc / 2) * tc;
273 const auto v_triangle =
jm /
am * d - vs;
276 if (d * v_triangle > 0 && std::abs(d) > std::abs(d_triangle)) {
278 ctrl_logd <<
"v: curve - straight - curve" << std::endl;
280 const auto amtc =
am * tc;
281 const auto D = amtc * amtc - 4 * (amtc * vs - vs * vs - 2 *
am * d);
282 const auto sqrtD = std::sqrt(D);
283 return (-amtc + (d > 0 ? sqrtD : -sqrtD)) / 2;
288 const auto a = std::abs(vs);
289 const auto b = (d > 0 ? 1 : -1) *
jm * d * d;
290 const auto aaa_27 =
a *
a *
a / 27;
291 const auto cr = 8 * aaa_27 + b / 2;
292 const auto ci_b = 8 * aaa_27 / b + 1.0f / 4;
295 ctrl_logd <<
"v: curve - curve (accel)" << std::endl;
296 const auto c = std::cbrt(cr + std::abs(b) * std::sqrt(ci_b));
297 return (d > 0 ? 1 : -1) * (c + 4 *
a *
a / c / 9 -
a / 3);
300 ctrl_logd <<
"v: curve - curve (decel)" << std::endl;
301 const auto ci = std::abs(b) * std::sqrt(-ci_b);
302 const auto r = std::hypot(cr, ci);
303 const auto th = std::atan2(ci, cr);
304 return (d > 0 ? 1 : -1) * (2 * std::cbrt(r) * std::cos(th / 3) -
a / 3);
#define ctrl_logd
Definition: accel_curve.h:48
float a(const float t) const
任意の時刻 t [s] における加速度 a [m/s/s] を返す関数
Definition: accel_curve.h:149
◆ calcReachableVelocityMax()
static float ctrl::AccelCurve::calcReachableVelocityMax |
( |
const float |
j_max, |
|
|
const float |
a_max, |
|
|
const float |
vs, |
|
|
const float |
ve, |
|
|
const float |
d |
|
) |
| |
|
inlinestatic |
走行距離の拘束から達しうる最大速度を算出する関数
- 引数
-
[in] | j_max | 最大躍度の大きさ [m/s/s/s], 正であること |
[in] | a_max | 最大加速度の大きさ [m/s/s], 正であること |
[in] | vs | 始点速度 [m/s] |
[in] | ve | 終点速度 [m/s] |
[in] | d | 走行距離 [m] |
- 戻り値
- vm 最大速度 [m/s]
320 const auto tc = a_max / j_max;
321 const auto am = (d > 0) ? a_max : -a_max;
323 const auto amtc =
am * tc;
324 const auto D = amtc * amtc - 2 * (vs + ve) * amtc + 4 *
am * d +
325 2 * (vs * vs + ve * ve);
328 ctrl_loge <<
"Error! D = " << D <<
" < 0" << std::endl;
331 ctrl_loge <<
"Invalid Input! vs: " << vs <<
", ve: " << ve << std::endl;
334 const auto sqrtD = std::sqrt(D);
335 return (-amtc + (d > 0 ? sqrtD : -sqrtD)) / 2;
#define ctrl_loge
Definition: accel_curve.h:28
◆ getTimeStamps()
const std::array<float, 4> ctrl::AccelCurve::getTimeStamps |
( |
| ) |
const |
|
inline |
◆ j()
float ctrl::AccelCurve::j |
( |
const float |
t | ) |
const |
|
inline |
任意の時刻 t [s] における躍度 j [m/s/s/s] を返す関数
- 引数
-
- 戻り値
- 躍度 [m/s/s/s]
◆ printCsv()
void ctrl::AccelCurve::printCsv |
( |
std::ostream & |
os, |
|
|
const float |
t_interval = 1e-3f |
|
) |
| const |
|
inline |
std::ostream に軌道のcsvを出力する関数
233 for (
float t =
t0; t <
t_end(); t += t_interval) {
234 os << t <<
"," <<
j(t) <<
"," <<
a(t) <<
"," <<
v(t) <<
"," <<
x(t)
float x(const float t) const
任意の時刻 t [s] における位置 x [m] を返す関数
Definition: accel_curve.h:183
float t_end() const
終点時刻 [s]
Definition: accel_curve.h:198
float j(const float t) const
任意の時刻 t [s] における躍度 j [m/s/s/s] を返す関数
Definition: accel_curve.h:132
float v(const float t) const
任意の時刻 t [s] における速度 v [m/s] を返す関数
Definition: accel_curve.h:166
◆ reset()
void ctrl::AccelCurve::reset |
( |
const float |
j_max, |
|
|
const float |
a_max, |
|
|
const float |
v_start, |
|
|
const float |
v_end |
|
) |
| |
|
inline |
引数の拘束条件から曲線を生成する関数
この関数によってもれなくすべての変数が初期化される。
- 引数
-
[in] | j_max | 最大躍度の大きさ [m/s/s/s], 正であること |
[in] | a_max | 最大加速度の大きさ [m/s/s], 正であること |
[in] | v_start | 始点速度 [m/s] |
[in] | v_end | 終点速度 [m/s] |
95 am = (
v_end > v_start) ? a_max : -a_max;
96 jm = (
v_end > v_start) ? j_max : -j_max;
103 const auto tc = a_max / j_max;
105 const auto tm = (
v3 -
v0) /
am - tc;
114 x1 =
x0 +
v0 * tc +
am * tc * tc / 6;
119 const auto tcp = std::sqrt((
v3 -
v0) /
jm);
123 x1 =
x2 =
x0 +
v1 * tcp +
jm * tcp * tcp * tcp / 6;
◆ t_0()
float ctrl::AccelCurve::t_0 |
( |
| ) |
const |
|
inline |
◆ t_1()
float ctrl::AccelCurve::t_1 |
( |
| ) |
const |
|
inline |
◆ t_2()
float ctrl::AccelCurve::t_2 |
( |
| ) |
const |
|
inline |
◆ t_3()
float ctrl::AccelCurve::t_3 |
( |
| ) |
const |
|
inline |
◆ t_end()
float ctrl::AccelCurve::t_end |
( |
| ) |
const |
|
inline |
◆ v()
float ctrl::AccelCurve::v |
( |
const float |
t | ) |
const |
|
inline |
任意の時刻 t [s] における速度 v [m/s] を返す関数
- 引数
-
- 戻り値
- 速度 [m/s]
170 return v0 +
jm / 2 * (t -
t0) * (t -
t0);
172 return v1 +
am * (t -
t1);
174 return v3 -
jm / 2 * (t -
t3) * (t -
t3);
◆ v_end()
float ctrl::AccelCurve::v_end |
( |
| ) |
const |
|
inline |
◆ x()
float ctrl::AccelCurve::x |
( |
const float |
t | ) |
const |
|
inline |
任意の時刻 t [s] における位置 x [m] を返す関数
- 引数
-
- 戻り値
- 位置 [m]
185 return x0 +
v0 * (t -
t0);
187 return x0 +
v0 * (t -
t0) +
jm / 6 * (t -
t0) * (t -
t0) * (t -
t0);
189 return x1 +
v1 * (t -
t1) +
am / 2 * (t -
t1) * (t -
t1);
191 return x3 +
v3 * (t -
t3) -
jm / 6 * (t -
t3) * (t -
t3) * (t -
t3);
193 return x3 +
v3 * (t -
t3);
◆ x_end()
float ctrl::AccelCurve::x_end |
( |
| ) |
const |
|
inline |
◆ operator<<
std::ostream& operator<< |
( |
std::ostream & |
os, |
|
|
const AccelCurve & |
obj |
|
) |
| |
|
friend |
情報の表示
243 os <<
"\tvs: " << obj.v0;
244 os <<
"\tve: " << obj.v3;
245 os <<
"\tt0: " << obj.t0;
246 os <<
"\tt1: " << obj.t1;
247 os <<
"\tt2: " << obj.t2;
248 os <<
"\tt3: " << obj.t3;
249 os <<
"\td: " << obj.x3 - obj.x0;
◆ am
float ctrl::AccelCurve::am |
|
protected |
◆ jm
float ctrl::AccelCurve::jm |
|
protected |
◆ t0
float ctrl::AccelCurve::t0 |
|
protected |
◆ t1
float ctrl::AccelCurve::t1 |
|
protected |
◆ t2
float ctrl::AccelCurve::t2 |
|
protected |
◆ t3
float ctrl::AccelCurve::t3 |
|
protected |
◆ v0
float ctrl::AccelCurve::v0 |
|
protected |
◆ v1
float ctrl::AccelCurve::v1 |
|
protected |
◆ v2
float ctrl::AccelCurve::v2 |
|
protected |
◆ v3
float ctrl::AccelCurve::v3 |
|
protected |
◆ x0
float ctrl::AccelCurve::x0 |
|
protected |
◆ x1
float ctrl::AccelCurve::x1 |
|
protected |
◆ x2
float ctrl::AccelCurve::x2 |
|
protected |
◆ x3
float ctrl::AccelCurve::x3 |
|
protected |
このクラス詳解は次のファイルから抽出されました: