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 <magic_enum.hpp>
13#include <memory>
14#include <string>
15
16#include "hexapod_next_move.h"
18#include "leg_state.h"
19#include "make_array.h"
20#include "math_quaternion.h"
21#include "math_vector3.h"
22
23namespace designlab {
24
39struct RobotStateNode final {
40 static constexpr int kNoParentIndex = -1;
41
52
53 constexpr RobotStateNode(
54 const leg_func::LegStateBit& state,
55 const std::array<Vector3, HexapodConst::kLegNum>& pos,
56 const std::array<Vector3, HexapodConst::kLegNum>& ref_pos,
57 const Vector3& com, const Quaternion& q, const HexapodMove move,
58 const int parent, const int d)
59 : leg_state(state),
60 leg_pos(pos),
61 leg_reference_pos(ref_pos),
63 posture(q),
64 next_move(move),
65 parent_index(parent),
66 depth(d) {}
67
68 RobotStateNode(const RobotStateNode& other) = default;
69 RobotStateNode(RobotStateNode&& other) noexcept = default;
70 RobotStateNode& operator=(const RobotStateNode& other) = default;
71 ~RobotStateNode() = default;
72
80 void ChangeGlobalCenterOfMass(const Vector3& new_com,
81 bool do_change_leg_base_pos);
82
86 void ChangePosture(
87 const std::shared_ptr<const IHexapodCoordinateConverter>& converter_ptr,
88 const Quaternion& new_posture);
89
92 inline void ChangeLootNode() {
93 depth = 0;
96 }
97
102 constexpr void ChangeToNextNode(const int parent_index_,
103 const HexapodMove next_move_) {
104 ++depth;
105 parent_index = parent_index_;
106 next_move = next_move_;
107 }
108
112 constexpr bool IsLootNode() const {
113 return (parent_index < 0) && (depth == 0);
114 }
115
119 std::string ToString() const;
120
124 std::string ToCsvString() const;
125
129 static RobotStateNode FromString(const std::string& str);
130
132 constexpr bool operator==(const RobotStateNode& other) const {
133 if (next_move != other.next_move) {
134 return false;
135 }
136
137 if (leg_state != other.leg_state) {
138 return false;
139 }
140
141 for (int i = 0; i < HexapodConst::kLegNum; i++) {
142 if (leg_pos[i] != other.leg_pos[i]) {
143 return false;
144 }
145
146 // if (leg_reference_pos[i] != other.leg_reference_pos[i])
147 // {
148 // return false;
149 // }
150 }
151
153 return false;
154 }
155
156 if (posture != other.posture) {
157 return false;
158 }
159
160 return true;
161 }
162
163 constexpr bool operator!=(const RobotStateNode& other) {
164 return !(*this == other);
165 }
166
169
171 std::array<Vector3, HexapodConst::kLegNum> leg_pos;
172
175 std::array<Vector3, HexapodConst::kLegNum> leg_reference_pos;
176
179
182
186
190
192 int depth;
193};
194
195template <class Char>
196std::basic_ostream<Char>& operator<<(std::basic_ostream<Char>& os,
197 const RobotStateNode& value) {
198 os << value.leg_state.to_string() << ",";
199
200 for (int i = 0; i < HexapodConst::kLegNum; i++) {
201 os << value.leg_pos[i] << ",";
202 }
203
204 for (int i = 0; i < HexapodConst::kLegNum; i++) {
205 os << value.leg_reference_pos[i] << ",";
206 }
207
208 os << value.center_of_mass_global_coord << ",";
209 os << value.posture << ",";
210 os << magic_enum::enum_name(value.next_move) << ",";
211 os << value.parent_index << ",";
212 os << value.depth;
213
214 return os;
215}
216
217} // namespace designlab
218
219#endif // DESIGNLAB_ROBOT_STATE_NODE_H_
static constexpr int kLegNum
std::bitset< kLegStateBitNum > LegStateBit
脚状態を保存する型.28bitのビット型.
Definition leg_state.h:55
HexapodMove
ロボットが次にどの動作をするのかを表す列挙体.
@ kComUpDown
重心の上下移動.
std::basic_ostream< Char > & operator<<(std::basic_ostream< Char > &os, const EulerXYZ &r)
出力ストリーム.Csv形式で出力する.カンマ区切り.単位は [rad].
Definition math_euler.h:106
クォータニオンを表す構造体.
void Normalize() noexcept
自身を正規化する.ノルムが1になる.
グラフ構造のためのノード(頂点).
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
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_)
次の動作を設定する関数. 深さを一つ深くして,親と次の動作を設定する.
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
void ChangePosture(const std::shared_ptr< const IHexapodCoordinateConverter > &converter_ptr, const Quaternion &new_posture)
クォータニオンを変更し,胴体を回転させる関数.
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となる.
void ChangeGlobalCenterOfMass(const Vector3 &new_com, bool do_change_leg_base_pos)
重心位置を変更する関数.
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次元の位置ベクトルを表す構造体.