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
16
17namespace designlab
18{
19
24{
25public:
27
31 explicit inline GaitPatternGraphTree(const int graph_max_size) :
32 graph_size_(0),
33 kGraphMaxSize(graph_max_size)
34 {
35 nodes_.resize(graph_max_size);
36 }
37
40 [[nodiscard]] constexpr int GetGraphSize() const { return graph_size_; }
41
45 [[nodiscard]] constexpr bool IsEmpty() const { return graph_size_ == 0; }
46
53 [[nodiscard]] constexpr bool HasRoot() const
54 {
55 return graph_size_ != 0;
56 }
57
64 [[nodiscard]] constexpr int GetRootIndex() const
65 {
66 return 0;
67 }
68
71 [[nodiscard]] inline const RobotStateNode& GetRootNode() const
72 {
73 return nodes_[0];
74 }
75
80 [[nodiscard]] inline const RobotStateNode& GetNode(const int index) const
81 {
82 assert(0 <= index);
83 assert(index < graph_size_);
84 return nodes_[index];
85 }
86
92 [[nodiscard]] const RobotStateNode& GetParentNode(const int index, const int depth) const;
93
99 [[nodiscard]] const int GetParentNodeIndex(const int index, const int depth) const;
100
107 inline void AddNode(const RobotStateNode& node)
108 {
109 assert(graph_size_ < kGraphMaxSize);
110
111 nodes_[graph_size_++] = node;
112
113 assert(nodes_[graph_size_ - 1].IsLootNode() ||
114 0 <= nodes_[graph_size_ - 1].parent_index);
115
116 assert(nodes_[graph_size_ - 1].parent_index < graph_size_);
117
118 assert(nodes_[graph_size_ - 1].IsLootNode() ||
119 nodes_[graph_size_ - 1].depth - 1 == nodes_[nodes_[graph_size_ - 1].parent_index].depth);
120 }
121
123 constexpr void Reset() { graph_size_ = 0; }
124
129 [[nodiscard]]
130 std::vector<float> GetCoMVerticalTrajectory(const int index) const
131 {
132 assert(0 <= index);
133 assert(index < graph_size_);
134 std::vector<float> com_vertical_trajectory_reverse;
135
136 // 現在のノードから根ノードまでの重心の上下移動軌跡を取得する.
137 for (int i = index; i != -1; i = nodes_[i].parent_index)
138 {
139 if (com_vertical_trajectory_reverse.empty() ||
140 com_vertical_trajectory_reverse.back() != nodes_[i].center_of_mass_global_coord.z)
141 {
142 com_vertical_trajectory_reverse.push_back(nodes_[i].center_of_mass_global_coord.z);
143 }
144 }
145
146 // 根ノードから現在のノードまでの重心の上下移動軌跡を取得する.
147 std::vector<float> com_vertical_trajectory(com_vertical_trajectory_reverse.size());
148 for (int i = 0; i < com_vertical_trajectory_reverse.size(); ++i)
149 {
150 com_vertical_trajectory[i] = com_vertical_trajectory_reverse[com_vertical_trajectory_reverse.size() - 1 - i];
151 }
152
153 return com_vertical_trajectory;
154 }
155
156private:
157 std::vector<RobotStateNode> nodes_;
158
161 int graph_size_;
162
163 const int kGraphMaxSize;
164};
165
166} // namespace designlab
167
168
169#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
グラフのノードの総数を返す.
グラフ構造のためのノード(頂点).旧名 LNODE