GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
gait_pattern_graph_tree.h
[詳解]
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#ifndef DESIGNLAB_GAIT_PATTERN_GRAPH_TREE_H_
9#define DESIGNLAB_GAIT_PATTERN_GRAPH_TREE_H_
10
11#include <vector>
12
13#include "cassert_define.h"
14#include "robot_state_node.h"
15
16namespace designlab {
17
22 public:
24
28 explicit inline GaitPatternGraphTree(const int graph_max_size)
29 : graph_size_(0), kGraphMaxSize(graph_max_size) {
30 nodes_.resize(graph_max_size);
31 }
32
35 [[nodiscard]] constexpr int GetGraphSize() const { return graph_size_; }
36
40 [[nodiscard]] constexpr bool IsEmpty() const { return graph_size_ == 0; }
41
48 [[nodiscard]] constexpr bool HasRoot() const { return graph_size_ != 0; }
49
56 [[nodiscard]] constexpr int GetRootIndex() const { return 0; }
57
60 [[nodiscard]] inline const RobotStateNode& GetRootNode() const {
61 return nodes_[0];
62 }
63
68 [[nodiscard]] inline const RobotStateNode& GetNode(const int index) const {
69 assert(0 <= index);
70 assert(index < graph_size_);
71 return nodes_[index];
72 }
73
80 [[nodiscard]] const RobotStateNode& GetParentNode(const int index,
81 const int depth) const;
82
89 [[nodiscard]] const int GetParentNodeIndex(const int index,
90 const int depth) const;
91
101 inline void AddNode(const RobotStateNode& node) {
102 assert(graph_size_ < kGraphMaxSize);
103
104 nodes_[graph_size_++] = node;
105
106 assert(nodes_[graph_size_ - 1].IsLootNode() ||
107 0 <= nodes_[graph_size_ - 1].parent_index);
108
109 assert(nodes_[graph_size_ - 1].parent_index < graph_size_);
110
111 assert(nodes_[graph_size_ - 1].IsLootNode() ||
112 nodes_[graph_size_ - 1].depth - 1 ==
113 nodes_[nodes_[graph_size_ - 1].parent_index].depth);
114 }
115
117 constexpr void Reset() { graph_size_ = 0; }
118
123 [[nodiscard]] std::vector<float> GetCoMVerticalTrajectory(
124 const int index) const {
125 assert(0 <= index);
126 assert(index < graph_size_);
127 std::vector<float> com_vertical_trajectory_reverse;
128
129 // 現在のノードから根ノードまでの重心の上下移動軌跡を取得する.
130 for (int i = index; i != -1; i = nodes_[i].parent_index) {
131 if (com_vertical_trajectory_reverse.empty() ||
132 com_vertical_trajectory_reverse.back() !=
133 nodes_[i].center_of_mass_global_coord.z) {
134 com_vertical_trajectory_reverse.push_back(
135 nodes_[i].center_of_mass_global_coord.z);
136 }
137 }
138
139 // 根ノードから現在のノードまでの重心の上下移動軌跡を取得する.
140 std::vector<float> com_vertical_trajectory(
141 com_vertical_trajectory_reverse.size());
142 for (int i = 0; i < com_vertical_trajectory_reverse.size(); ++i) {
143 com_vertical_trajectory[i] = com_vertical_trajectory_reverse
144 [com_vertical_trajectory_reverse.size() - 1 - i];
145 }
146
147 return com_vertical_trajectory;
148 }
149
150 private:
151 std::vector<RobotStateNode> nodes_;
152
155 int graph_size_;
156
157 const int kGraphMaxSize;
158};
159
160} // namespace designlab
161
162#endif // DESIGNLAB_GAIT_PATTERN_GRAPH_TREE_H_
RobotStateNode 構造体をノードとする木構造のグラフのクラス.
constexpr void Reset()
グラフをリセットする.
constexpr bool IsEmpty() const
グラフが空かどうかを返す.
const RobotStateNode & GetRootNode() const
グラフの根ノードの参照を返す.
const int GetParentNodeIndex(const int index, const int depth) const
指定したノードの親ノードの参照を返す.depthは親ノードの深さを指定する.
constexpr int GetRootIndex() const
グラフの根ノードのインデックスを返す. ノードがない場合を考慮していないため, HasRoot()で根ノードを持つかどうかを確認すること. 一番最初に追加されたノードは必ず根ノードになるため,...
std::vector< float > GetCoMVerticalTrajectory(const int index) const
指定したノードの重心の上下移動軌跡を返す.
const RobotStateNode & GetParentNode(const int index, const int depth) const
指定したノードの親ノードの参照を返す.depthは親ノードの深さを指定する.
GaitPatternGraphTree(const int graph_max_size)
コンストラクタ. ノード数の最大値を指定する.
void AddNode(const RobotStateNode &node)
ノードを追加する. 追加するノードは親ノードのインデックスと,depthの指定が適切にされている必要がある. これらが適切にされていない場合,アサーションに引っかかる....
const RobotStateNode & GetNode(const int index) const
グラフのノードの参照を返す.
constexpr bool HasRoot() const
グラフが根ノードを持つかどうかを返す. 根ノードとは,親を持たないノードのこと. 一番最初に追加するノードは必ず根になるため, 根を持つかどうかはノードの総数が0でないかどうかで判定できる.
constexpr int GetGraphSize() const
グラフのノードの総数を返す.
グラフ構造のためのノード(頂点).