GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
divided_map_state.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_DIVIDED_MAP_STATE_H_
9#define DESIGNLAB_DIVIDED_MAP_STATE_H_
10
11#include <string>
12#include <vector>
13
14#include "map_state.h"
15#include "math_vector3.h"
16#include "my_expected.h"
17
18namespace designlab {
19
31class DividedMapState final {
32 public:
35 static constexpr int kDividedMapPointNum{4};
36
40
41 static constexpr int kDividedNum{15};
42
45 2.0f};
46
48 static constexpr float kDividedMapMinX{-kDividedMapMaxX};
49
52 2.0f};
53
55 static constexpr float kDividedMapMinY{-kDividedMapMaxY};
56
58 explicit DividedMapState(float min_z = MapState::kMapMinZ);
59
65 void Init(const MapState& map_state, const Vector3 global_robot_com);
66
68 void Clear();
69
75 constexpr bool IsInMap(const float x, const float y) const noexcept {
76 if (x < global_robot_com_.x + kDividedMapMinX ||
77 global_robot_com_.x + kDividedMapMaxX < x) {
78 return false;
79 }
80
81 if (y < global_robot_com_.y + kDividedMapMinY ||
82 global_robot_com_.y + kDividedMapMaxY < y) {
83 return false;
84 }
85
86 return true;
87 }
88
93 constexpr bool IsInMap(const Vector3& pos) const noexcept {
94 return IsInMap(pos.x, pos.y);
95 }
96
103 constexpr int GetDividedMapIndexX(const float pos_x) const noexcept {
104 return static_cast<int>((pos_x - global_robot_com_.x - kDividedMapMinX) *
105 static_cast<float>(kDividedNum) /
107 }
108
115 constexpr int GetDividedMapIndexY(const float pos_y) const noexcept {
116 return static_cast<int>((pos_y - global_robot_com_.y - kDividedMapMinY) *
117 static_cast<float>(kDividedNum) /
119 }
120
122 static constexpr int ClampDividedMapIndex(const int index) noexcept {
123 if (index < 0) {
124 return 0;
125 }
126 if (kDividedNum <= index) {
127 return kDividedNum - 1;
128 }
129
130 return index;
131 }
132
138 nostd::expected<int, std::string> GetPointNum(int x_index, int y_index) const;
139
148 int x_index, int y_index, int divided_map_index) const;
149
155 void GetPointVector(int x_index, int y_index,
156 std::vector<Vector3>* point_vec) const;
157
162 float GetTopZ(int x_index, int y_index) const;
163
164 float GetMapMinZ() const noexcept { return kMapMinZ; }
165
166 private:
173 constexpr int GetDividedMapIndex(const int x_index,
174 const int y_index) const noexcept {
175 return x_index * kDividedNum + y_index;
176 }
177
182 constexpr bool IsValidIndex(const int index) const noexcept {
183 if (index < 0 || kDividedNum <= index) {
184 return false;
185 }
186
187 return true;
188 }
189
190 const float kMapMinZ;
191
192 Vector3 global_robot_com_;
193
195 std::vector<std::vector<Vector3>> divided_map_point_;
196
199 std::vector<float> divided_map_top_z_;
200
201 static_assert(kDividedMapPointNum > 0,
202 "kDividedMapPointNum は正の整数である必要があります.");
203
204 static_assert(kDividedAreaLength > 0.0f,
205 "kDividedAreaLengthは正の実数である必要があります.");
206
207 static_assert(kDividedNum > 0, "kDividedNum は正の整数である必要があります.");
208
209 static_assert(
211 " kDividedMapMaxX は kDividedMapMinX より大きい必要があります.");
212
213 static_assert(kDividedMapMaxY > kDividedMapMinY,
214 "kDividedMapMaxY は kDividedMapMinY より大きい必要があります.");
215};
216
217} // namespace designlab
218
219#endif // DESIGNLAB_DIVIDED_MAP_STATE_H_
マップを格子状に分割して管理するクラス.
constexpr bool IsInMap(const Vector3 &pos) const noexcept
指定した座標がマップの範囲内に存在するかどうかを返す.
constexpr bool IsInMap(const float x, const float y) const noexcept
指定した座標がマップの範囲内に存在するかどうかを返す.
constexpr int GetDividedMapIndexX(const float pos_x) const noexcept
指定した座標を DividedMap のインデックスに変換する. 範囲外の値を指定した場合でも,値を丸めずに返す. そのため,IsInMap で範囲内に存在するかどうかを確認する必要がある.
nostd::expected< Vector3, std::string > GetPointPos(int x_index, int y_index, int divided_map_index) const
格子状に切り分けられたマップから,脚設置可能点の実際の座標を取得する. 範囲外の値を指定した場合は, unexpected を返す.
static constexpr float kDividedAreaLength
static constexpr float kDividedMapMaxX
マップの最大のX座標.
void Init(const MapState &map_state, const Vector3 global_robot_com)
マップのデータを初期化する. ロボットの重心座標を中心にマップのデータを格子状に分割し, その中に存在する脚設置可能点を集める.
static constexpr float kDividedMapMinX
マップの最小のX座標.
static constexpr float kDividedMapMinY
マップの最小のY座標.
void Clear()
マップのデータを消去する.
static constexpr int kDividedMapPointNum
1つのマスの一辺の長さ.
constexpr int GetDividedMapIndexY(const float pos_y) const noexcept
指定した座標を DividedMap のインデックスに変換する. 範囲外の値を指定した場合でも,値を丸めずに返す. そのため,IsInMap で範囲内に存在するかどうかを確認する必要がある.
float GetTopZ(int x_index, int y_index) const
格子状に切り分けられたマップから,最も高いZ座標を返す.
nostd::expected< int, std::string > GetPointNum(int x_index, int y_index) const
格子状に切り分けられたマップから,脚設置可能点の数を取得する. 範囲外の値を指定した場合は, unexpected を返す.
void GetPointVector(int x_index, int y_index, std::vector< Vector3 > *point_vec) const
格子状に切り分けられたマップから,脚設置可能点の vector を取得する 範囲外の値を指定した場合は,空の vector を返す.
static constexpr int ClampDividedMapIndex(const int index) noexcept
指定した座標がマップのインデックスの範囲内になるように丸める.
float GetMapMinZ() const noexcept
static constexpr float kDividedMapMaxY
マップの最大のY座標.
static constexpr int kDividedNum
格子の数.
マップを表すクラス.
Definition map_state.h:29
static constexpr float kMapPointDistance
z軸から(上から)みたとき,格子点状に分けられた脚接地可能点の間隔 [mm].
Definition map_state.h:79
static constexpr float kMapMinZ
マップの最低のZ座標
Definition map_state.h:80
自作の expected クラス
Definition my_expected.h:46
3次元の位置ベクトルを表す構造体.
float x
ロボットの正面方向に正.
float y
ロボットの左向きに正.