GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
node_creator_com_up_down.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 <algorithm>
11#include <cfloat>
12
13#include "hexapod_const.h"
14#include "leg_state.h"
15#include "math_util.h"
16#include "phantomx_mk2_const.h"
17
18namespace designlab {
19
21 const DividedMapState& divided_map,
22 const std::shared_ptr<const IHexapodCoordinateConverter>& converter_ptr,
23 const std::shared_ptr<const IHexapodStatePresenter>& presenter_ptr,
24 const std::shared_ptr<const IHexapodPostureValidator>& checker_ptr,
25 HexapodMove next_move)
26 : map_(divided_map),
27 converter_ptr_(converter_ptr),
28 presenter_ptr_(presenter_ptr),
29 checker_ptr_(checker_ptr),
30 next_move_(next_move) {}
31
33 const RobotStateNode& current_node, const int current_num,
34 std::vector<RobotStateNode>* output_graph) const {
35 // 重心を最も高くあげることのできる位置と,最も低く下げることのできる位置を求める.
36
37 // マップの最大z座標を求める.
39 float map_highest_z = -100000;
40
41 if (map_.IsInMap(current_node.center_of_mass_global_coord)) {
42 const int map_index_x =
44 const int map_index_y =
46 map_highest_z = map_.GetTopZ(map_index_x, map_index_y);
47 }
48
49 for (int i = 0; i < HexapodConst::kLegNum; i++) {
50 // 脚の先端の座標を求める.
51 const Vector3 kCoxaVec = converter_ptr_->ConvertRobotToGlobalCoordinate(
52 presenter_ptr_->GetLegBasePosRobotCoordinate(i),
53 current_node.center_of_mass_global_coord, current_node.posture, true);
54
55 if (map_.IsInMap(kCoxaVec)) {
56 const int kCoxaX = map_.GetDividedMapIndexX(kCoxaVec.x);
57 const int kCoxaY = map_.GetDividedMapIndexY(kCoxaVec.y);
58 map_highest_z = (std::max)(map_.GetTopZ(kCoxaX, kCoxaY), map_highest_z);
59 }
60 }
61
62 // ロボットの重心の最も低く下げることのできるz座標と,
63 // 高くあげることができるz座標を求める.どちらもグローバル座標.
64 float highest_body_pos_z =
65 map_highest_z + presenter_ptr_->GetGroundHeightMarginMax();
66 float lowest_body_pos_z =
67 map_highest_z + presenter_ptr_->GetGroundHeightMarginMin();
68
69 // 最も高い地点を修正する.
70
71 for (int i = 0; i < HexapodConst::kLegNum; i++) {
72 // 接地している脚についてのみ考える.
73 if (leg_func::IsGrounded(current_node.leg_state, i)) {
74 // 三平方の定理を使って,脚接地地点から重心位置をどれだけ上げられるか考える.
75 const float edge_c =
77 const float edge_b = current_node.leg_pos[i].ProjectedXY().GetLength() -
79
80 const float edge_a =
81 sqrt(math_util::Squared(edge_c) - math_util::Squared(edge_b));
82
83 // 接地脚の最大重心高さの中から一番小さいものを全体の最大重心位置として記録する._aは脚の接地点からどれだけ上げられるかを表しているので,グローバル座標に変更する.
84 highest_body_pos_z =
85 (std::min)(edge_a + current_node.center_of_mass_global_coord.z +
86 current_node.leg_pos[i].z,
87 highest_body_pos_z);
88 }
89 }
90
91 // ノードを追加する.
92 pushNodeByMaxAndMinPosZ(current_node, current_num, highest_body_pos_z,
93 lowest_body_pos_z, output_graph);
94}
95
96void NodeCreatorComUpDown::pushNodeByMaxAndMinPosZ(
97 const RobotStateNode& current_node, const int current_num, const float high,
98 const float low, std::vector<RobotStateNode>* output_graph) const {
99 // 重心を変化させたものを追加する.変化量が一番少ないノードは削除する.
100
101 // 最大と最小の間を分割する.
102 const float kDivZ = (high - low) / static_cast<float>(kDiscretization);
103
104 // 分割した分新しいノードを追加する.
105 for (int i = 0; i < kDiscretization + 1; ++i) {
106 bool is_valid = true;
107
108 RobotStateNode new_node = current_node;
109
110 // 重心の位置を変更する.
111 Vector3 new_com = current_node.center_of_mass_global_coord;
112 new_com.z = low + kDivZ * i;
113
114 new_node.ChangeGlobalCenterOfMass(new_com, true);
115
116 for (int j = 0; j < HexapodConst::kLegNum; j++) {
117 if (!checker_ptr_->IsLegInRange(j, new_node.leg_pos[j])) {
118 is_valid = false;
119 }
120 }
121
122 // current_numを親とする,新しいノードに変更する
123 new_node.ChangeToNextNode(current_num, next_move_);
124
125 // ノードを追加する.
126 if (is_valid) {
127 (*output_graph).emplace_back(new_node);
128 }
129 }
130
131 // 重心の変化が一切ないものを追加する.
132 RobotStateNode same_node = current_node;
133
134 same_node.ChangeToNextNode(current_num, next_move_);
135
136 (*output_graph).emplace_back(same_node);
137}
138
139} // namespace designlab
マップを格子状に分割して管理するクラス.
constexpr bool IsInMap(const float x, const float y) const noexcept
指定した座標がマップの範囲内に存在するかどうかを返す.
constexpr int GetDividedMapIndexX(const float pos_x) const noexcept
指定した座標を DividedMap のインデックスに変換する. 範囲外の値を指定した場合でも,値を丸めずに返す. そのため,IsInMap で範囲内に存在するかどうかを確認する必要がある.
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
NodeCreatorComUpDown(const DividedMapState &devide_map, const std::shared_ptr< const IHexapodCoordinateConverter > &converter_ptr, const std::shared_ptr< const IHexapodStatePresenter > &presenter_ptr, const std::shared_ptr< const IHexapodPostureValidator > &checker_ptr, HexapodMove next_move)
void Create(const RobotStateNode &current_node, int current_num, std::vector< RobotStateNode > *output_graph) const override
現在のノードから次のノード群を生成する.
static constexpr float kFemurLength
第2関節部の長さ[mm].
static constexpr float kCoxaLength
第1関節部の長さ[mm].
static constexpr float kTibiaLength
第3関節部の長さ[mm].
bool IsGrounded(const LegStateBit &leg_state, const int leg_index)
脚番号 leg_index 0 ~ 5 に応じて,その脚が接地しているかを調べる. 脚は右前脚を0番として,時計回りに0,1,2,3,4,5となる.左前足が5番.
Definition leg_state.cpp:46
constexpr T Squared(const T num) noexcept
2乗した値を返す関数.
Definition math_util.h:55
HexapodMove
ロボットが次にどの動作をするのかを表す列挙体.
グラフ構造のためのノード(頂点).
std::array< Vector3, HexapodConst::kLegNum > leg_pos
[4 * 3 * 6 = 72 byte] 脚先の座標.(coxa(脚の付け根)を原点とする)
leg_func::LegStateBit leg_state
[4 byte] 脚状態,重心パターンを bitで表す.旧名 leg_con.
constexpr void ChangeToNextNode(const int parent_index_, const HexapodMove next_move_)
次の動作を設定する関数. 深さを一つ深くして,親と次の動作を設定する.
Vector3 center_of_mass_global_coord
[4 * 3 = 12byte] グローバル座標系における重心の位置.旧名 GCOM
Quaternion posture
[4 * 4 = 16byte] 姿勢を表すクォータニオン.
void ChangeGlobalCenterOfMass(const Vector3 &new_com, bool do_change_leg_base_pos)
重心位置を変更する関数.
3次元の位置ベクトルを表す構造体.
float x
ロボットの正面方向に正.
float z
ロボットの上向きに正.
float y
ロボットの左向きに正.