12#include <boost/dynamic_bitset.hpp>
25 const std::shared_ptr<const IHexapodCoordinateConverter>& converter_ptr,
26 const std::shared_ptr<const IHexapodStatePresenter>& presenter_ptr,
27 const std::shared_ptr<const IHexapodPostureValidator>& checker_ptr,
31 converter_ptr_(converter_ptr),
32 presenter_ptr_(presenter_ptr),
33 checker_ptr_(checker_ptr),
36 assert(converter_ptr_ !=
nullptr);
37 assert(presenter_ptr_ !=
nullptr);
38 assert(checker_ptr_ !=
nullptr);
42 int current_node_index,
43 std::vector<RobotStateNode>* output_graph)
const
51 is_able_leg_ground_pattern.set();
71 is_groundable_leg[i] =
true;
72 ground_pos[i] = current_node.
leg_pos[i];
79 if (IsGroundableLeg(i, current_node, &res_ground_pos))
81 is_groundable_leg[i] =
true;
82 ground_pos[i] = res_ground_pos;
86 is_groundable_leg[i] =
false;
97 if (is_able_leg_ground_pattern[i])
114 if (new_is_ground[j])
116 res_node.
leg_pos[j] = ground_pos[j];
122 res_node.
leg_pos[j] = presenter_ptr_->GetFreeLegPosLegCoordinate(j);
131 (*output_graph).push_back(res_node);
137bool NodeCreatorLegUpDown2d::IsGroundableLeg(
int now_leg_num,
139 Vector3* output_ground_pos)
const
145 const Vector3 global_leg_base_pos = converter_ptr_->ConvertLegToGlobalCoordinate(
166 bool is_candidate_pos =
false;
169 for (
int x = min_x_dev; x < max_x_dev; x++)
171 for (
int y = min_y_dev; y < max_y_dev; y++)
175 for (
int n = 0; n < kPosNum; n++)
180 map_point_pos = converter_ptr_->ConvertGlobalToLegCoordinate(
190 new_node.
leg_pos[now_leg_num] = map_point_pos;
194 if (is_candidate_pos)
213 if (!checker_ptr_->IsLegInRange(now_leg_num, new_node.
leg_pos[now_leg_num]))
219 if (!IsAbleLegPos(new_node, now_leg_num))
225 is_candidate_pos =
true;
226 candidate_pos = map_point_pos;
233 if (!is_candidate_pos) {
return false; }
236 (*output_ground_pos) = candidate_pos;
241bool NodeCreatorLegUpDown2d::IsAbleLegPos(
const RobotStateNode& node,
const int leg_index)
const
246 if ((node.leg_reference_pos[leg_index].ProjectedXY() - node.leg_pos[leg_index].ProjectedXY()).GetSquaredLength() <
math_util::Squared(kLegMargin))
266 if (node.leg_reference_pos[leg_index].ProjectedXY().Cross(node.leg_pos[leg_index].ProjectedXY()) * node.leg_pos[leg_index].ProjectedXY().Cross({ 1, 0 }) > 0)
constexpr int GetDividedMapIndexX(const float pos_x) const noexcept
指定した座標を DividedMap のインデックスに変換する. 範囲外の値を指定した場合でも,値を丸めずに返す. そのため,IsInMap で範囲内に存在するかどうかを確認する必要がある.
Vector3 GetPointPos(int x_index, int y_index, int divided_map_index) const
格子状に切り分けられたマップから,脚設置可能点の実際の座標を取得する. 範囲外の値を指定した場合は,(0,0,0)を返す.
constexpr int GetDividedMapIndexY(const float pos_y) const noexcept
指定した座標を DividedMap のインデックスに変換する. 範囲外の値を指定した場合でも,値を丸めずに返す. そのため,IsInMap で範囲内に存在するかどうかを確認する必要がある.
int GetPointNum(int x_index, int y_index) const
格子状に切り分けられたマップから,脚設置可能点の数を取得する. 範囲外の値を指定した場合は,0を返す.
static constexpr int ClampDividedMapIndex(const int index) noexcept
指定した座標がマップのインデックスの範囲内になるように丸める.
static constexpr int kLegNum
void Create(const RobotStateNode ¤t_node, int current_node_index, std::vector< RobotStateNode > *output_graph) const override
現在のノードから次のノード群を生成する.
NodeCreatorLegUpDown2d(const DividedMapState &devide_map, const std::shared_ptr< const IHexapodCoordinateConverter > &converter_ptr, const std::shared_ptr< const IHexapodStatePresenter > &presenter_ptr, const std::shared_ptr< const IHexapodPostureValidator > &checker_ptr, HexapodMove next_move)
void RemoveLegGroundPatternFromCom(enums::DiscreteComPos discrete_com_pos, boost::dynamic_bitset<> *output)
離散化された重心位置から,その重心位置では取り得ない脚接地パターンを falseにする.
int GetLegGroundPatternNum()
脚の接地パターンの総数を返す.
leg_func::LegGroundedBit GetLegGroundedBitFromLegGroundPatternIndex(const int leg_ground_pattern_index)
脚の接地パターンの番号から,その番号に該当する接地パターンを返す.
void RemoveLegGroundPatternFromNotGroundableLeg(int not_groundable_leg_index, boost::dynamic_bitset<> *output)
接地できない脚番号から, その脚が接地できない場合に取り得ない接地パターンを falseにする.
DiscreteLegPos
離散化された脚位置を表す列挙体. 先行研究では 1~7の int型の数値で表現されているが, 可読性を上げるために列挙体にした. 離散化された脚位置は 3bit (0 ~ 7)の範囲で表現される...
@ kUpperBack
現在の位置より後方かつ上方にある.
@ kUpperFront
現在の位置より前方かつ上方にある.
@ kLowerBack
現在の位置より後方かつ下方にある.
@ kLowerFront
現在の位置より前方かつ下方にある.
std::bitset< HexapodConst::kLegNum > LegGroundedBit
脚の遊脚・接地を表す型.6bitのビット型.接地が 1 遊脚が 0.
bool IsGrounded(const LegStateBit &leg_state, const int leg_index)
脚番号 leg_index 0 ~ 5 に応じて,その脚が接地しているかを調べる. 脚は右前脚を0番として,時計回りに0,1,2,3,4,5となる.左前足が5番.
enums::DiscreteComPos GetDiscreteComPos(const LegStateBit &leg_state)
現在の脚状態から重心パターンを取得する.
void ChangeGround(const int leg_index, const bool is_ground, LegStateBit *leg_state)
脚の接地・遊脚情報を変更する.
enums::DiscreteLegPos GetDiscreteLegPos(const LegStateBit &leg_state, const int leg_index)
脚状態を取得する.
void ChangeAllLegGround(const LegGroundedBit &is_ground_list, LegStateBit *leg_state)
全ての脚の接地・遊脚情報を変更する.
constexpr T Squared(const T num) noexcept
2乗した値を返す関数.
HexapodMove
ロボットが次にどの動作をするのかを表す列挙体.
グラフ構造のためのノード(頂点).旧名 LNODE
std::array< Vector3, HexapodConst::kLegNum > leg_pos
[4 * 3 * 6 = 72 byte] 脚先の座標.(coxa(脚の付け根)を原点とする)
leg_func::LegStateBit leg_state
[4 byte] 脚状態,重心パターンを bitで表す.旧名 leg_con.
constexpr void ChangeToNextNode(const int parent_index_, const HexapodMove next_move_)
次の動作を設定する関数. 深さを一つ深くして,親と次の動作を設定する.
Vector3 center_of_mass_global_coord
[4 * 3 = 12byte] グローバル座標系における重心の位置.旧名 GCOM
Quaternion posture
[4 * 4 = 16byte] 姿勢を表すクォータニオン.
std::array< Vector3, HexapodConst::kLegNum > leg_reference_pos
constexpr float Cross(const Vector2 &other) const noexcept
自分×引数 の外積の結果を返す.
constexpr Vector2 ProjectedXY() const noexcept
XY平面に射影したベクトルを返す.