GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
robot_operator_for_path.cpp
[詳解]
1
3
4// Copyright(c) 2023-2025 Design Engineering Laboratory, Saitama University
5// Released under the MIT license
6// https://opensource.org/licenses/mit-license.php
7
9
10#include <numbers>
11
12#include "math_rot_converter.h"
13
14
15namespace
16{
18
19// -π~πの範囲に収める.
20float NormalizeAngle(float angle)
21{
22 while (angle > std::numbers::pi_v<float>)
23 {
24 angle -= 2 * std::numbers::pi_v<float>;
25 }
26
27 while (angle < -std::numbers::pi_v<float>)
28 {
29 angle += 2 * std::numbers::pi_v<float>;
30 }
31
32 return angle;
33}
34
35} // namespace
36
37
38namespace designlab
39{
40
41RobotOperatorForPath::RobotOperatorForPath(const std::vector<Vector3>& path) :
42 global_route_(path),
43 most_near_index_(0)
44{
45}
46
56
58{
59 using enum RobotOperationType;
60
61 if ((global_route_[most_near_index_].ProjectedXY() - node.center_of_mass_global_coord.ProjectedXY()).GetLength() < 150.f)
62 {
63 most_near_index_++;
64 }
65
66 if (most_near_index_ > 0 &&
67 (global_route_[most_near_index_ - 1].ProjectedXY() - node.center_of_mass_global_coord.ProjectedXY()).GetLength() < 150.f)
68 {
69 // 旋回によって,most_near_index_の方を向く.
70 const auto diff = global_route_[most_near_index_].ProjectedXY() -
72
73 const float angle = atan2(diff.y, diff.x);
74 const float euler_z_angle = ToEulerXYZ(node.posture).z_angle;
75 const float rot_dif = NormalizeAngle(angle - euler_z_angle);
76
77 if (abs(rot_dif) > kAllowableAngleError)
78 {
79 RobotOperation operation;
82
83 return operation;
84 }
85 }
86
87 //if (most_near_index_ >= global_route_.size())
88 //{
89 // most_near_index_ = 0;
90 //}
91
92 //const auto diff = global_route_[most_near_index_].ProjectedXY() -
93 // node.center_of_mass_global_coord.ProjectedXY();
94
95 //const float angle = atan2(diff.y, diff.x);
96 //const float euler_z_angle = NormalizeAngle(ToEulerXYZ(node.posture).z_angle);
97 //const float rot_dif = angle - euler_z_angle;
98
99 //if (abs(rot_dif) > kAllowableAngleError)
100 //{
101 // RobotOperation operation;
102 // operation.operation_type = kSpotTurnLastPosture;
103 // operation.spot_turn_last_posture_ = Quaternion::MakeByAngleAxis(angle, Vector3::GetUpVec());
104
105 // return operation;
106 //}
107
108 RobotOperation operation_straight;
109
110 operation_straight.operation_type = kStraightMoveVector;
111
112 if (most_near_index_ == 0)
113 {
114 operation_straight.straight_move_vector = (global_route_[most_near_index_] - node.center_of_mass_global_coord).GetNormalized();
115 }
116 else
117 {
118 operation_straight.straight_move_vector = (global_route_[most_near_index_] - global_route_[most_near_index_ - 1]).GetNormalized();
119 }
120
121 return operation_straight;
122}
123
124} // namespace designlab
RobotOperation Update(const RobotStateNode &node) override
ロボットの動作を更新する.
RobotOperation Init() const override
ロボットの動作を初期化する.
RobotOperatorForPath(const std::vector< Vector3 > &path)
RobotOperationType
Robotをどのように動かすかを表す列挙体.
@ kStraightMoveVector
直線移動をさせる(移動したい方向をベクトルで示す)
@ kSpotTurnLastPosture
その場で旋回させる(最終的な姿勢 Posture を示す)
EulerXYZ ToEulerXYZ(const RotationMatrix3x3 &rot)
回転角行列からXYZオイラー角への変換.
float z_angle
Z 軸周りの回転 [rad]
Definition math_euler.h:111
static Quaternion MakeByAngleAxis(float rad_angle, const Vector3 &axis)
回転軸と回転角からクォータニオンを作成する. q = cos(θ/2) * w + sin(θ/2) * { v.x + v.y + v.z } となる. ノルムは必ず1になる.
探索において目標となる座標や角度,評価する値についてまとめた構造体.
Vector3 straight_move_vector
< 目標方向.正規化されたベクトル.
RobotOperationType operation_type
Quaternion spot_turn_last_posture
旋回時の回転軸.右ねじの回転.
グラフ構造のためのノード(頂点).旧名 LNODE
Vector3 center_of_mass_global_coord
[4 * 3 = 12byte] グローバル座標系における重心の位置.旧名 GCOM
Quaternion posture
[4 * 4 = 16byte] 姿勢を表すクォータニオン.
static constexpr Vector3 GetUpVec() noexcept
上に進む単位ベクトルを返す. 静的な関数なので,Vector3::GetUpVec() と呼び出せる.
static constexpr Vector3 GetFrontVec() noexcept
正面に進む単位ベクトルを返す. 静的な関数なので,Vector3::GetFrontVec() と呼び出せる.
constexpr Vector2 ProjectedXY() const noexcept
XY平面に射影したベクトルを返す.