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
14namespace {
16
17// -π~πの範囲に収める.
18float NormalizeAngle(float angle) {
19 while (angle > std::numbers::pi_v<float>) {
20 angle -= 2 * std::numbers::pi_v<float>;
21 }
22
23 while (angle < -std::numbers::pi_v<float>) {
24 angle += 2 * std::numbers::pi_v<float>;
25 }
26
27 return angle;
28}
29
30} // namespace
31
32namespace designlab {
33
34RobotOperatorForPath::RobotOperatorForPath(const std::vector<Vector3>& path)
35 : global_route_(path), most_near_index_(0) {}
36
45
47 using enum RobotOperationType;
48
49 if ((global_route_[most_near_index_].ProjectedXY() -
51 .GetLength() < 150.f) {
52 most_near_index_++;
53 }
54
55 if (most_near_index_ > 0 &&
56 (global_route_[most_near_index_ - 1].ProjectedXY() -
58 .GetLength() < 150.f) {
59 // 旋回によって,most_near_index_の方を向く.
60 const auto diff = global_route_[most_near_index_].ProjectedXY() -
62
63 const float angle = atan2(diff.y, diff.x);
64 const float euler_z_angle = ToEulerXYZ(node.posture).z_angle;
65 const float rot_dif = NormalizeAngle(angle - euler_z_angle);
66
67 if (abs(rot_dif) > kAllowableAngleError) {
68 RobotOperation operation;
70 operation.spot_turn_last_posture =
72
73 return operation;
74 }
75 }
76
77 // if (most_near_index_ >= global_route_.size())
78 //{
79 // most_near_index_ = 0;
80 // }
81
82 // const auto diff = global_route_[most_near_index_].ProjectedXY() -
83 // node.center_of_mass_global_coord.ProjectedXY();
84
85 // const float angle = atan2(diff.y, diff.x);
86 // const float euler_z_angle =
87 // NormalizeAngle(ToEulerXYZ(node.posture).z_angle); const float rot_dif =
88 // angle - euler_z_angle;
89
90 // if (abs(rot_dif) > kAllowableAngleError)
91 //{
92 // RobotOperation operation;
93 // operation.operation_type = kSpotTurnLastPosture;
94 // operation.spot_turn_last_posture_ = Quaternion::MakeByAngleAxis(angle,
95 // Vector3::GetUpVec());
96
97 // return operation;
98 //}
99
100 RobotOperation operation_straight;
101
102 operation_straight.operation_type = kStraightMoveVector;
103
104 if (most_near_index_ == 0) {
105 operation_straight.straight_move_vector =
106 (global_route_[most_near_index_] - node.center_of_mass_global_coord)
107 .GetNormalized();
108 } else {
109 operation_straight.straight_move_vector =
110 (global_route_[most_near_index_] - global_route_[most_near_index_ - 1])
111 .GetNormalized();
112 }
113
114 return operation_straight;
115}
116
117} // 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:101
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
旋回時の回転軸.右ねじの回転.
グラフ構造のためのノード(頂点).
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平面に射影したベクトルを返す.