GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
node_initializer.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
8#include "node_initializer.h"
9
10#include "divided_map_state.h"
11#include "leg_state.h"
12#include "math_rot_converter.h"
13#include "math_util.h"
14#include "phantomx_mk2_const.h"
15
16namespace designlab {
17
19 HexapodMove move)
20 : pos_(pos), posture_(posture), move_(move) {}
21
24
25 // 脚状態.
27 enums::DiscreteComPos::kCenterBack, {true, true, true, true, true, true},
31
32 const float base_z = 0.0f; // 地面のZ座標.
33 [[maybe_unused]] const float com_z =
34 pos_.z + base_z; // ロボットの重心のZ座標.
35
36 for (int i = 0; i < HexapodConst::kLegNum; i++) {
37 res.leg_pos[i] = res.leg_reference_pos[i] = {
39 160.f * sin(PhantomXMkIIConst::kCoxaDefaultAngle[i]), -com_z};
40 }
41
43
44 // 座標をランダマイズする.
45 // res.center_of_mass_global_coord.x +=
46 // math_util::GenerateRandomNumber(-30.f, 30.f);
47 // res.center_of_mass_global_coord.y +=
48 // math_util::GenerateRandomNumber(-30.f, 30.f);
49
50 // 15 deg
51 // res.leg_pos[0].z -= 20.0f;
52 // res.leg_pos[5].z -= 20.0f;
53 // res.leg_pos[1].z -= 80.0f;
54 // res.leg_pos[4].z -= 80.0f;
55 // res.leg_pos[2].z -= 135.0f;
56 // res.leg_pos[3].z -= 135.0f;
57
58 // 10 deg
59 // res.leg_pos[0].z -= 32.0f;
60 // res.leg_pos[5].z -= 32.0f;
61 // res.leg_pos[1].z -= 74.0f;
62 // res.leg_pos[4].z -= 74.0f;
63 // res.leg_pos[2].z -= 116.0f;
64 // res.leg_pos[3].z -= 116.0f;
65
66 // 5 deg
67 // res.leg_pos[0].z -= 10.0f;
68 // res.leg_pos[5].z -= 10.0f;
69 // res.leg_pos[1].z -= 34.0f;
70 // res.leg_pos[4].z -= 34.0f;
71 // res.leg_pos[2].z -= 57.0f;
72 // res.leg_pos[3].z -= 57.0f;
73
74 // ロールピッチヨーで回転を表現する.ロボットの重心を中心にして回転する.
75 const auto posture = EulerXYZ{math_util::ConvertDegToRad(posture_.x_angle),
78
79 res.posture = ToQuaternion(posture);
80
81 res.next_move = move_;
82 res.parent_index = -1;
83 res.depth = 0;
84
85 return res;
86}
87
89 const MapState map) const {
90 DividedMapState divided_map_state;
91 divided_map_state.Init(map, node.center_of_mass_global_coord);
92
93 // ロボットの重心
94 const float map_z = divided_map_state.GetTopZ(
96 divided_map_state.GetDividedMapIndexY(
98
99 RobotStateNode res = node;
102 node.center_of_mass_global_coord.y, map_z + 30),
103 true);
104
105 return res;
106}
107
108} // namespace designlab
マップを格子状に分割して管理するクラス.
constexpr int GetDividedMapIndexX(const float pos_x) const noexcept
指定した座標を DividedMap のインデックスに変換する. 範囲外の値を指定した場合でも,値を丸めずに返す. そのため,IsInMap で範囲内に存在するかどうかを確認する必要がある.
void Init(const MapState &map_state, const Vector3 global_robot_com)
マップのデータを初期化する. ロボットの重心座標を中心にマップのデータを格子状に分割し, その中に存在する脚設置可能点を集める.
constexpr int GetDividedMapIndexY(const float pos_y) const noexcept
指定した座標を DividedMap のインデックスに変換する. 範囲外の値を指定した場合でも,値を丸めずに返す. そのため,IsInMap で範囲内に存在するかどうかを確認する必要がある.
float GetTopZ(int x_index, int y_index) const
格子状に切り分けられたマップから,最も高いZ座標を返す.
static constexpr int kLegNum
マップを表すクラス.
Definition map_state.h:29
RobotStateNode InitNode() const
ノードの初期化を行う.
NodeInitializer(const Vector3 &pos, const EulerXYZ &posture, HexapodMove move)
RobotStateNode InitNodeForTerrain(const RobotStateNode &node, const MapState map) const
地形に適した初期姿勢を設定する.
static constexpr std::array< float, kPhantomXLegNum > kCoxaDefaultAngle
第1関節の初期角度[rad]
@ kCenterBack
重心が中央後方にある.逆三角径.
LegStateBit MakeLegStateBit(const enums::DiscreteComPos discrete_com_pos, const std::array< bool, HexapodConst::kLegNum > &is_ground, const std::array< DiscreteLegPos, HexapodConst::kLegNum > &discretized_leg_pos)
脚状態を作成して返す関数.脚状態は重心パターン, 脚の接地・遊脚,離散化した脚位置のデータが含まれる.
Definition leg_state.cpp:14
constexpr T ConvertDegToRad(const T deg) noexcept
角度を [deg] から [rad] に変換する関数.
Definition math_util.h:119
@ kCenter
現在の位置にある.
Quaternion ToQuaternion(const RotationMatrix3x3 &rot)
回転角行列からクォータニオンへの変換.
HexapodMove
ロボットが次にどの動作をするのかを表す列挙体.
XYZオイラー角を用いた回転を表す構造体.
Definition math_euler.h:30
float x_angle
X 軸周りの回転 [rad]
Definition math_euler.h:99
float y_angle
Y 軸周りの回転 [rad]
Definition math_euler.h:100
float z_angle
Z 軸周りの回転 [rad]
Definition math_euler.h:101
グラフ構造のためのノード(頂点).
std::array< Vector3, HexapodConst::kLegNum > leg_pos
[4 * 3 * 6 = 72 byte] 脚先の座標.(coxa(脚の付け根)を原点とする)
leg_func::LegStateBit leg_state
[4 byte] 脚状態,重心パターンを bitで表す.旧名 leg_con.
Vector3 center_of_mass_global_coord
[4 * 3 = 12byte] グローバル座標系における重心の位置.旧名 GCOM
Quaternion posture
[4 * 4 = 16byte] 姿勢を表すクォータニオン.
std::array< Vector3, HexapodConst::kLegNum > leg_reference_pos
int depth
[4 byte] 自身の深さ.一番上の親が深さ0となる.
void ChangeGlobalCenterOfMass(const Vector3 &new_com, bool do_change_leg_base_pos)
重心位置を変更する関数.
3次元の位置ベクトルを表す構造体.
float x
ロボットの正面方向に正.
float z
ロボットの上向きに正.
float y
ロボットの左向きに正.