GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
robot_state_node.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_ROBOT_STATE_NODE_H_
9#define DESIGNLAB_ROBOT_STATE_NODE_H_
10
11#include <array>
12#include <memory>
13#include <string>
14
15#include <magic_enum.hpp>
16
17#include "array_util.h"
18#include "hexapod_next_move.h"
20#include "leg_state.h"
21#include "math_quaternion.h"
22#include "math_vector3.h"
23#include "robot_operation.h"
24
25
26namespace designlab
27{
28
46struct RobotStateNode final
47{
48 static constexpr int kNoParentIndex = -1;
49
50 constexpr RobotStateNode() :
51 leg_state(0),
53 Vector3{},
54 Vector3{},
55 Vector3{},
56 Vector3{},
57 Vector3{},
58 Vector3{}
59 )
60 },
63 posture{},
66 depth(0)
67 {
68 }
69
70 constexpr RobotStateNode(
71 const leg_func::LegStateBit& state,
72 const std::array<Vector3, HexapodConst::kLegNum>& pos,
73 const std::array<Vector3, HexapodConst::kLegNum>& ref_pos,
74 const Vector3& com,
75 const Quaternion& q,
76 const HexapodMove move,
77 const int parent,
78 const int d) :
79 leg_state(state),
80 leg_pos(pos),
81 leg_reference_pos(ref_pos),
83 posture(q),
84 next_move(move),
85 parent_index(parent),
86 depth(d)
87 {
88 }
89
90 RobotStateNode(const RobotStateNode& other) = default;
91 RobotStateNode(RobotStateNode&& other) noexcept = default;
92 RobotStateNode& operator=(const RobotStateNode& other) = default;
93 ~RobotStateNode() = default;
94
103 bool do_change_leg_base_pos);
104
108 void ChangePosture(
109 const std::shared_ptr<const IHexapodCoordinateConverter>& converter_ptr,
110 const designlab::Quaternion& new_posture);
111
114 inline void ChangeLootNode()
115 {
116 depth = 0;
119 }
120
125 constexpr void ChangeToNextNode(
126 const int parent_index_,
127 const HexapodMove next_move_)
128 {
129 ++depth;
130 parent_index = parent_index_;
131 next_move = next_move_;
132 }
133
137 constexpr bool IsLootNode() const
138 {
139 return (parent_index < 0) && (depth == 0);
140 }
141
145 std::string ToString() const;
146
150 std::string ToCsvString() const;
151
155 static RobotStateNode FromString(const std::string& str);
156
157
159 constexpr bool operator == (const RobotStateNode& other) const
160 {
161 if (next_move != other.next_move) { return false; }
162
163 if (leg_state != other.leg_state) { return false; }
164
165 for (int i = 0; i < HexapodConst::kLegNum; i++)
166 {
167 if (leg_pos[i] != other.leg_pos[i]) { return false; }
168
169 // if (leg_reference_pos[i] != other.leg_reference_pos[i])
170 // {
171 // return false;
172 // }
173 }
174
176 {
177 return false;
178 }
179
180 if (posture != other.posture) { return false; }
181
182 return true;
183 }
184
185 constexpr bool operator != (const RobotStateNode& other)
186 {
187 return !(*this == other);
188 }
189
190
193
195 std::array<Vector3, HexapodConst::kLegNum> leg_pos;
196
199 std::array<Vector3, HexapodConst::kLegNum> leg_reference_pos;
200
203
206
207
211
215
217 int depth;
218};
219
220
221template <class Char>
222std::basic_ostream<Char>& operator <<(
223 std::basic_ostream<Char>& os, const RobotStateNode& value)
224{
225 os << value.leg_state.to_string() << ",";
226
227 for (int i = 0; i < HexapodConst::kLegNum; i++)
228 {
229 os << value.leg_pos[i] << ",";
230 }
231
232 for (int i = 0; i < HexapodConst::kLegNum; i++)
233 {
234 os << value.leg_reference_pos[i] << ",";
235 }
236
237 os << value.center_of_mass_global_coord << ",";
238 os << value.posture << ",";
239 os << magic_enum::enum_name(value.next_move) << ",";
240 os << value.parent_index << ",";
241 os << value.depth;
242
243 return os;
244}
245
246} // namespace designlab
247
248
249#endif // DESIGNLAB_ROBOT_STATE_NODE_H_
static constexpr int kLegNum
std::bitset< kLegStateBitNum > LegStateBit
脚状態を保存する型.28bitのビット型.
Definition leg_state.h:56
constexpr std::array< T, sizeof...(Args)> MakeArray(Args &&... args)
std::arrayを作成する関数. この関数を作成したモチベーションとしては, std::arrayを constexprで初期化する際に苦戦したため. この関数を使うことで,std::arr...
Definition array_util.h:23
HexapodMove
ロボットが次にどの動作をするのかを表す列挙体.
@ kComUpDown
重心の上下移動.
std::basic_ostream< Char > & operator<<(std::basic_ostream< Char > &os, const EulerXYZ &r)
出力ストリーム.Csv形式で出力する.カンマ区切り.単位は [rad].
Definition math_euler.h:117
クォータニオンを表す構造体.
void Normalize() noexcept
自身を正規化する.ノルムが1になる.
グラフ構造のためのノード(頂点).旧名 LNODE
constexpr bool IsLootNode() const
自身が根ノードであるか判定する.
std::array< Vector3, HexapodConst::kLegNum > leg_pos
[4 * 3 * 6 = 72 byte] 脚先の座標.(coxa(脚の付け根)を原点とする)
constexpr bool operator==(const RobotStateNode &other) const
比較演算子
RobotStateNode(RobotStateNode &&other) noexcept=default
void ChangeGlobalCenterOfMass(const designlab::Vector3 &new_com, bool do_change_leg_base_pos)
重心位置を変更する関数.
leg_func::LegStateBit leg_state
[4 byte] 脚状態,重心パターンを bitで表す.旧名 leg_con.
std::string ToCsvString() const
ノードの情報を csv形式の文字列に変換する関数. カンマ区切りで出力する.
static RobotStateNode FromString(const std::string &str)
文字列をノードの情報に変換する関数.
void ChangeLootNode()
自身を根ノードに変更する関数. depthを0に,parent_numを-1に初期化する.
constexpr void ChangeToNextNode(const int parent_index_, const HexapodMove next_move_)
次の動作を設定する関数. 深さを一つ深くして,親と次の動作を設定する.
void ChangePosture(const std::shared_ptr< const IHexapodCoordinateConverter > &converter_ptr, const designlab::Quaternion &new_posture)
クォータニオンを変更し,胴体を回転させる関数.
Vector3 center_of_mass_global_coord
[4 * 3 = 12byte] グローバル座標系における重心の位置.旧名 GCOM
std::string ToString() const
ノードの情報を文字列に変換する関数. デバッグ用に詳細な情報を出力する.
constexpr bool operator!=(const RobotStateNode &other)
RobotStateNode(const RobotStateNode &other)=default
Quaternion posture
[4 * 4 = 16byte] 姿勢を表すクォータニオン.
static constexpr int kNoParentIndex
親がいないことを表す値.
RobotStateNode & operator=(const RobotStateNode &other)=default
std::array< Vector3, HexapodConst::kLegNum > leg_reference_pos
int depth
[4 byte] 自身の深さ.一番上の親が深さ0となる.
constexpr RobotStateNode(const leg_func::LegStateBit &state, const std::array< Vector3, HexapodConst::kLegNum > &pos, const std::array< Vector3, HexapodConst::kLegNum > &ref_pos, const Vector3 &com, const Quaternion &q, const HexapodMove move, const int parent, const int d)
3次元の位置ベクトルを表す構造体.