GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
robot_operator_for_gpg.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 <format>
11#include <iostream>
12#include <numbers>
13
14#include "cmdio_util.h"
15#include "math_rot_converter.h"
16
17
18namespace
19{
20
21// -π~πの範囲に収める
22float NormalizeAngle(float angle)
23{
24 while (angle > std::numbers::pi_v<float>)
25 {
26 angle -= std::numbers::pi_v<float>;
27 }
28
29 while (angle < -std::numbers::pi_v<float>)
30 {
31 angle += std::numbers::pi_v<float>;
32 }
33
34 return angle;
35}
36
37} // namespace
38
39
40namespace designlab
41{
42
44 {4910,630,40},
45{4890,630,40},
46{4870,630,40},
47{4850,630,40},
48{4830,650,40},
49{4810,650,40},
50{4790,630,40},
51{4770,630,40},
52{4750,650,40},
53{4730,650,40},
54{4710,630,40},
55{4690,650,40},
56{4670,650,40},
57{4650,650,40},
58{4630,650,40},
59{4610,650,40},
60{4590,650,40},
61{4570,650,40},
62{4550,650,40},
63{4530,650,40},
64{4510,650,40},
65{4490,650,40},
66{4470,650,40},
67{4450,650,40},
68{4430,650,40},
69{4410,650,40},
70{4390,650,40},
71{4370,650,40},
72{4350,630,40},
73{4330,630,40},
74{4310,630,40},
75{4290,630,40},
76{4270,630,40},
77{4250,650,40},
78{4230,650,40},
79{4210,650,40},
80{4190,650,40},
81{4170,650,40},
82{4150,630,40},
83{4130,630,40},
84{4110,630,40},
85{4090,630,40},
86{4070,650,40},
87{4050,650,40},
88{4030,650,40},
89{4010,650,40},
90{3990,650,40},
91{3970,650,40},
92{3950,650,40},
93{3930,650,40},
94{3910,650,40},
95{3890,650,40},
96{3870,650,40},
97{3850,630,40},
98{3830,630,40},
99{3810,630,40},
100{3790,630,40},
101{3770,630,40},
102{3750,630,40},
103{3730,650,40},
104{3710,650,40},
105{3690,650,40},
106{3670,650,40},
107{3650,650,40},
108{3630,650,40},
109{3610,650,40},
110{3590,650,40},
111{3570,650,40},
112{3550,650,40},
113{3530,650,40},
114{3510,630,40},
115{3490,630,40},
116{3470,630,40},
117{3450,630,40},
118{3430,630,40},
119{3410,630,40},
120{3390,630,40},
121{3370,630,40},
122{3350,630,40},
123{3330,630,40},
124{3310,630,40},
125{3290,630,40},
126{3270,630,40},
127{3250,630,40},
128{3230,630,40},
129{3210,630,40},
130{3190,630,40},
131{3170,630,40},
132{3150,610,40},
133{3130,590,40},
134{3110,570,40},
135{3090,570,40},
136{3070,570,40},
137{3050,550,40},
138{3030,530,40},
139{3010,530,40},
140{2990,510,40},
141{2970,490,40},
142{2950,470,40},
143{2930,450,40},
144{2910,430,40},
145
146}
147{
148}
149
150RobotOperation RobotOperatorForGpg::Init() const
151{
152 return RobotOperation();
153}
154
155RobotOperation RobotOperatorForGpg::Update(const RobotStateNode& node)
156{
157 using enum OutputDetail;
158 using enum RobotOperationType;
159
160 // まず,現在の重心位置から最も近い点を探す.
161 int most_near_index = 0;
162 float min_distance = 100000.f;
163
164 for (int i = 0; i < global_route_.size(); ++i)
165 {
166 const float now_distance = global_route_[i].ProjectedXY().GetDistanceFrom(node.center_of_mass_global_coord.ProjectedXY());
167
168 if (min_distance > now_distance)
169 {
170 min_distance = now_distance;
171
172 most_near_index = i;
173 }
174 }
175
176 CmdIOUtil::Output(std::format("most_near_index : {}", most_near_index), kDebug);
177
178 // 次の地点への角度を計算する.
179 const float euler_z_angle = NormalizeAngle(ToEulerXYZ(node.posture).z_angle);
180 const Vector3 diff_vector = global_route_[most_near_index - 1] - global_route_[most_near_index];
181 const float target_angle = NormalizeAngle(atan2(diff_vector.y, diff_vector.x));
182 const float rot_dif = target_angle - euler_z_angle;
183
184 CmdIOUtil::Output(std::format("target_angle : {} / now_angle : {}",
185 math_util::ConvertRadToDeg(target_angle),
186 math_util::ConvertRadToDeg(euler_z_angle)),
187 kDebug);
188
189 if (abs(rot_dif) > kAllowableAngleError)
190 {
191 RobotOperation operation;
193 operation.spot_turn_last_posture = Quaternion::MakeByAngleAxis(target_angle, Vector3::GetUpVec());
194
195 CmdIOUtil::Output(std::format("target_angle : {} / now_angle : {}",
196 math_util::ConvertRadToDeg(target_angle),
197 math_util::ConvertRadToDeg(euler_z_angle)),
198 kDebug);
199
200 return operation;
201 }
202
203 const int loop_num = 10;
204 Vector3 target_vector;
205
206 for (int i = 0; i < loop_num; i++)
207 {
208 if (most_near_index - i < 0)
209 {
210 break;
211 }
212
213 target_vector += (global_route_[most_near_index - i] - node.center_of_mass_global_coord) *
214 static_cast<float>(i + 1);
215 }
216
217 CmdIOUtil::Output(std::format("target_vector : {}", target_vector.ToString()), kDebug);
218
219 RobotOperation operation;
221 operation.straight_move_vector = Vector3(target_vector.x, target_vector.y, 0).GetNormalized();
222
223 return operation;
224}
225
226} // namespace designlab
RobotOperationType
Robotをどのように動かすかを表す列挙体.
@ kStraightMoveVector
直線移動をさせる(移動したい方向をベクトルで示す)
@ kSpotTurnLastPosture
その場で旋回させる(最終的な姿勢 Posture を示す)
OutputDetail
コマンドラインに文字を出力する際に,その詳細を指定するための列挙体.
@ kDebug
デバッグ時のみ出力,一番優先度が低い.
EulerXYZ ToEulerXYZ(const RotationMatrix3x3 &rot)
回転角行列からXYZオイラー角への変換.
float z_angle
Z 軸周りの回転 [rad]
Definition math_euler.h:111
探索において目標となる座標や角度,評価する値についてまとめた構造体.
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] 姿勢を表すクォータニオン.
3次元の位置ベクトルを表す構造体.
float x
ロボットの正面方向に正.
Vector3 GetNormalized() const noexcept
単位ベクトルを返す. normalizeとは,ベクトルを正規化(単位ベクトルに変換)する操作を表す. 絶対値が0のベクトルの場合,そのまま0ベクトルを返す.
constexpr Vector2 ProjectedXY() const noexcept
XY平面に射影したベクトルを返す.
std::string ToString() const
このベクトルを文字列にして返す. (x, y, z) の形式,小数点以下3桁まで.
float y
ロボットの左向きに正.