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 <vector>
12
13#include "map_state.h"
14#include "math_vector3.h"
15
16
17namespace designlab
18{
19
31class DividedMapState final
32{
33public:
35 static constexpr int kDividedMapPointNum{ 4 };
36
39
40 static constexpr int kDividedNum{ 15 };
41
43 static constexpr float kDividedMapMaxX{ kDividedAreaLength * kDividedNum / 2.0f };
44
46 static constexpr float kDividedMapMinX{ -kDividedMapMaxX };
47
49 static constexpr float kDividedMapMaxY{ kDividedAreaLength * kDividedNum / 2.0f };
50
52 static constexpr float kDividedMapMinY{ -kDividedMapMaxY };
53
54
56 explicit DividedMapState(float min_z = MapState::kMapMinZ);
57
63 void Init(const MapState& map_state, const Vector3 global_robot_com);
64
66 void Clear();
67
73 constexpr bool IsInMap(const float x, const float y) const
74 {
75 if (x < global_robot_com_.x + kDividedMapMinX ||
76 global_robot_com_.x + kDividedMapMaxX < x)
77 {
78 return false;
79 }
80
81 if (y < global_robot_com_.y + kDividedMapMinY ||
82 global_robot_com_.y + kDividedMapMaxY < y)
83 {
84 return false;
85 }
86
87 return true;
88 }
89
94 constexpr bool IsInMap(const Vector3& pos) const noexcept
95 {
96 return IsInMap(pos.x, pos.y);
97 }
98
105 constexpr int GetDividedMapIndexX(const float pos_x) const noexcept
106 {
107 return static_cast<int>(
108 (pos_x - global_robot_com_.x - kDividedMapMinX) *
109 static_cast<float>(kDividedNum) / (kDividedMapMaxX - kDividedMapMinX));
110 }
111
118 constexpr int GetDividedMapIndexY(const float pos_y) const noexcept
119 {
120 return static_cast<int>(
121 (pos_y - global_robot_com_.y - kDividedMapMinY) *
122 static_cast<float>(kDividedNum) / (kDividedMapMaxY - kDividedMapMinY));
123 }
124
126 static constexpr int ClampDividedMapIndex(const int index) noexcept
127 {
128 if (index < 0) { return 0; }
129 if (kDividedNum <= index) { return kDividedNum - 1; }
130
131 return index;
132 }
133
139 int GetPointNum(int x_index, int y_index) const;
140
147 Vector3 GetPointPos(int x_index, int y_index, int divided_map_index) const;
148
154 void GetPointVector(int x_index, int y_index, std::vector<Vector3>* point_vec) const;
155
160 float GetTopZ(int x_index, int y_index) const;
161
162 float GetMapMinZ() const noexcept { return kMapMinZ; }
163
164private:
170 constexpr int GetDividedMapIndex(const int x_index, const int y_index) const noexcept
171 {
172 return x_index * kDividedNum + y_index;
173 }
174
179 constexpr bool IsValidIndex(const int index) const noexcept
180 {
181 if (index < 0 || kDividedNum <= index)
182 {
183 return false;
184 }
185
186 return true;
187 }
188
189 const float kMapMinZ;
190
191 Vector3 global_robot_com_;
192
194 std::vector<std::vector<Vector3> > divided_map_point_;
195
197 std::vector<float> divided_map_top_z_;
198
199
200 static_assert(kDividedMapPointNum > 0,
201 "kDividedMapPointNum は正の整数である必要があります.");
202
203 static_assert(kDividedAreaLength > 0.0f,
204 "kDividedAreaLengthは正の実数である必要があります.");
205
206 static_assert(kDividedNum > 0,
207 "kDividedNum は正の整数である必要があります.");
208
209 static_assert(kDividedMapMaxX > kDividedMapMinX,
210 " kDividedMapMaxX は kDividedMapMinX より大きい必要があります.");
211
212 static_assert(kDividedMapMaxY > kDividedMapMinY,
213 "kDividedMapMaxY は kDividedMapMinY より大きい必要があります.");
214};
215
216} // namespace designlab
217
218
219#endif // DESIGNLAB_DIVIDED_MAP_STATE_H_
マップを格子状に分割して管理するクラス.
constexpr bool IsInMap(const Vector3 &pos) const noexcept
指定した座標がマップの範囲内に存在するかどうかを返す.
constexpr int GetDividedMapIndexX(const float pos_x) const noexcept
指定した座標を DividedMap のインデックスに変換する. 範囲外の値を指定した場合でも,値を丸めずに返す. そのため,IsInMap で範囲内に存在するかどうかを確認する必要がある.
static constexpr float kDividedAreaLength
static constexpr float kDividedMapMaxX
マップの最大のX座標.
Vector3 GetPointPos(int x_index, int y_index, int divided_map_index) const
格子状に切り分けられたマップから,脚設置可能点の実際の座標を取得する. 範囲外の値を指定した場合は,(0,0,0)を返す.
void Init(const MapState &map_state, const Vector3 global_robot_com)
マップのデータを初期化する. ロボットの重心座標を中心にマップのデータを格子状に分割し, その中に存在する脚設置可能点を集める.
constexpr bool IsInMap(const float x, const float y) const
指定した座標がマップの範囲内に存在するかどうかを返す.
static constexpr float kDividedMapMinX
マップの最小のX座標.
static constexpr float kDividedMapMinY
マップの最小のY座標.
void Clear()
マップのデータを消去する.
static constexpr int kDividedMapPointNum
< 1つのマスに存在する脚設置可能点の数は kDividedMapPointNum × kDividedMapPointNum 個.
constexpr int GetDividedMapIndexY(const float pos_y) const noexcept
指定した座標を DividedMap のインデックスに変換する. 範囲外の値を指定した場合でも,値を丸めずに返す. そのため,IsInMap で範囲内に存在するかどうかを確認する必要がある.
int GetPointNum(int x_index, int y_index) const
格子状に切り分けられたマップから,脚設置可能点の数を取得する. 範囲外の値を指定した場合は,0を返す.
float GetTopZ(int x_index, int y_index) const
格子状に切り分けられたマップから,最も高いZ座標を返す.
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:32
static constexpr float kMapPointDistance
z軸から(上から)みたとき,格子点状に分けられた脚接地可能点の間隔 [mm].
Definition map_state.h:92
static constexpr float kMapMinZ
マップの最低のZ座標
Definition map_state.h:93
3次元の位置ベクトルを表す構造体.
float x
ロボットの正面方向に正.
float y
ロボットの左向きに正.