GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
leg_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_LEG_STATE_H_
9#define DESIGNLAB_LEG_STATE_H_
10
11#include <array>
12#include <bitset>
13#include <vector>
14
15#include "discrete_com_pos.h"
16#include "discrete_leg_pos.h"
17#include "hexapod_const.h"
18
19
42namespace designlab::leg_func
43{
44
45// 使用する型の定義
46
48constexpr int kLegPosBitNum = 4;
49
50constexpr int kComPosBitNum = 4;
51
54
56using LegStateBit = std::bitset<kLegStateBitNum>;
57
59using LegGroundedBit = std::bitset<HexapodConst::kLegNum>;
60
61
62
63// ビットをマスクするための定数
64
66constexpr LegStateBit kLegPosMaskBit(0b0111);
67
69constexpr LegStateBit kLegStateMaskBit(0b1111);
70
71
74
77
78
79
88 enums::DiscreteComPos discrete_com_pos,
89 const std::array<bool, HexapodConst::kLegNum>& is_ground,
90 const std::array<enums::DiscreteLegPos, HexapodConst::kLegNum>& leg_pos);
91
92
99bool IsGrounded(const LegStateBit& leg_state_bit, int leg_index);
100
106
110int GetGroundedLegNum(const LegStateBit& leg_state);
111
115int GetLiftedLegNum(const LegStateBit& leg_state);
116
121 const LegStateBit& leg_state, std::vector<int>* res_index);
122
126void GetLiftedLegIndexByVector(const LegStateBit& leg_state, std::vector<int>* res_index);
127
128
133enums::DiscreteLegPos GetDiscreteLegPos(const LegStateBit& leg_state, int leg_index);
134
139
140
147void ChangeLegState(int leg_index, enums::DiscreteLegPos new_discretized_leg_pos,
148 bool is_ground, LegStateBit* leg_state);
149
154void ChangeDiscreteLegPos(int leg_index, enums::DiscreteLegPos new_discretized_leg_pos,
155 LegStateBit* leg_state);
156
162void ChangeGround(int leg_index, bool is_ground, LegStateBit* leg_state);
163
168void ChangeAllLegGround(const LegGroundedBit& is_ground_list, LegStateBit* leg_state);
169
174void ChangeDiscreteComPos(enums::DiscreteComPos new_com_pattern, LegStateBit* leg_state);
175
176
177} // namespace designlab::leg_func
178
179
180#endif // DESIGNLAB_LEG_STATE_H_
static constexpr int kLegNum
DiscreteLegPos
離散化された脚位置を表す列挙体. 先行研究では 1~7の int型の数値で表現されているが, 可読性を上げるために列挙体にした. 離散化された脚位置は 3bit (0 ~ 7)の範囲で表現される...
このプログラムでは脚状態をビット(28bit)の情報で表す. そのデータを処理するための関数.
Definition leg_state.cpp:13
constexpr LegStateBit kLegPosMaskBit(0b0111)
脚位置は4bitの下位三桁で管理されるので,そこをマスクする.
void ChangeDiscreteLegPos(const int leg_index, const enums::DiscreteLegPos new_discretized_leg_pos, LegStateBit *leg_state)
脚の状態を変更する.遊脚を表すビットはそのまま.
int GetGroundedLegNum(const LegStateBit &leg_state)
接地している脚の本数を返す関数.
Definition leg_state.cpp:81
std::bitset< HexapodConst::kLegNum > LegGroundedBit
脚の遊脚・接地を表す型.6bitのビット型.接地が 1 遊脚が 0.
Definition leg_state.h:59
constexpr LegStateBit kLegStateMaskBit(0b1111)
脚状態は4bitで管理されるので,そこをマスクする.
bool IsGrounded(const LegStateBit &leg_state, const int leg_index)
脚番号 leg_index 0 ~ 5 に応じて,その脚が接地しているかを調べる. 脚は右前脚を0番として,時計回りに0,1,2,3,4,5となる.左前足が5番.
Definition leg_state.cpp:43
constexpr int kComPosBitNum
重心パターンを表すビット数.
Definition leg_state.h:50
constexpr int kShiftToComNum
重心パターンを保存するビットまで行くために,どれだけビットをシフトするか.
Definition leg_state.h:73
int GetLiftedLegNum(const LegStateBit &leg_state)
遊脚している脚の本数を返す関数.
Definition leg_state.cpp:98
constexpr LegStateBit kComStateMaskBit
重心パターンを保存するビットをマスクするビット.
Definition leg_state.h:76
constexpr int kLegStateBitNum
脚状態を保存するビット数.28bit.
Definition leg_state.h:53
enums::DiscreteComPos GetDiscreteComPos(const LegStateBit &leg_state)
現在の脚状態から重心パターンを取得する.
void ChangeDiscreteComPos(const enums::DiscreteComPos new_com_pattern, LegStateBit *leg_state)
重心のデータを変更する.
void ChangeGround(const int leg_index, const bool is_ground, LegStateBit *leg_state)
脚の接地・遊脚情報を変更する.
void GetLiftedLegIndexByVector(const LegStateBit &leg_state, std::vector< int > *res_index)
遊脚している脚の脚番号0~5を,引数_res_numberで参照渡しする関数.
enums::DiscreteLegPos GetDiscreteLegPos(const LegStateBit &leg_state, const int leg_index)
脚状態を取得する.
LegGroundedBit GetLegGroundedBit(const LegStateBit &leg_state)
脚が接地しているなら1,遊脚を0としたビット列で遊脚・接地脚の状態を返す. 例えば 0 番脚のみが遊脚しているなら 0b111 110 を返す.
Definition leg_state.cpp:62
constexpr int kLegPosBitNum
脚位置を表すビット数.離散化された脚位置は3bit,遊脚・接地は1bit.あわせて4bit.
Definition leg_state.h:48
void GetGroundedLegIndexByVector(const LegStateBit &leg_state, std::vector< int > *res_index)
接地している脚の脚番号0~5を,引数で参照渡しする関数.
void ChangeAllLegGround(const LegGroundedBit &is_ground_list, LegStateBit *leg_state)
全ての脚の接地・遊脚情報を変更する.
LegStateBit MakeLegStateBit(const enums::DiscreteComPos discrete_com_pos, const std::array< bool, HexapodConst::kLegNum > &is_ground, const std::array< enums::DiscreteLegPos, HexapodConst::kLegNum > &discretized_leg_pos)
脚状態を作成して返す関数.脚状態は重心パターン, 脚の接地・遊脚,離散化した脚位置のデータが含まれる.
Definition leg_state.cpp:15
std::bitset< kLegStateBitNum > LegStateBit
脚状態を保存する型.28bitのビット型.
Definition leg_state.h:56
void ChangeLegState(const int leg_index, const enums::DiscreteLegPos new_discretized_leg_pos, const bool is_ground, LegStateBit *leg_state)
脚の情報を変更する.