13#include <boost/thread.hpp>
24 broker_ptr_(broker_ptr)
26 InitializeDirectory();
49 "Please put the file in the directory. \"./" + kResultFileDirectoryPath +
"\"",
kSystem);
56 std::vector<RobotStateNode> graph;
61 RemoveDoNotMoveNode(&graph);
62 MergeContinuousMove(&graph);
63 DivideSwingAndStance(&graph);
66 broker_ptr_->graph.SetData(graph);
67 broker_ptr_->map_state.SetData(map_state);
68 broker_ptr_->simulation_end_index.SetData({ graph.size() - 1 });
95void SystemMainRobotControl::RemoveDoNotMoveNode(std::vector<RobotStateNode>* graph_ptr)
98 std::optional<RobotStateNode> prev_pos = std::nullopt;
100 for (
auto itr = graph_ptr->begin(); itr != graph_ptr->end();)
102 if (prev_pos.has_value() && itr->leg_pos == prev_pos->leg_pos)
104 itr = graph_ptr->erase(itr);
114void SystemMainRobotControl::MergeContinuousMove(std::vector<RobotStateNode>* graph_ptr)
117 std::optional<RobotStateNode> prev_pos = std::nullopt;
119 bool prv_is_body_move =
false;
121 for (
auto itr = graph_ptr->begin(); itr != graph_ptr->end();)
123 if (prev_pos.has_value() &&
124 (*itr).center_of_mass_global_coord != prev_pos.value().center_of_mass_global_coord &&
125 (*itr).center_of_mass_global_coord.z == prev_pos.value().center_of_mass_global_coord.z)
129 if (prv_is_body_move)
132 itr = graph_ptr->erase(itr);
133 prv_is_body_move =
false;
137 prv_is_body_move =
true;
143 prv_is_body_move =
false;
150void SystemMainRobotControl::DivideSwingAndStance(std::vector<RobotStateNode>* graph_ptr)
153 std::optional<RobotStateNode> prev_pos = std::nullopt;
155 for (
auto itr = graph_ptr->begin(); itr != graph_ptr->end(); ++itr)
158 if (!prev_pos.has_value())
165 int swing_leg_num = 0;
166 int stance_leg_num = 0;
182 if (swing_leg_num > 0 && stance_leg_num > 0)
184 RobotStateNode stance_node = prev_pos.value();
192 stance_node.leg_pos[i] = (*itr).leg_pos[i];
200 itr = graph_ptr->insert(itr, stance_node);
207void SystemMainRobotControl::InitializeDirectory()
210 if (!std::filesystem::exists(kResultFileDirectoryPath))
212 std::filesystem::create_directory(kResultFileDirectoryPath);
static void Output(const std::string &str, OutputDetail detail)
コマンドラインに文字を出力する関数. SetOutputLimit() で設定した出力の許可範囲内であれば出力される. 必ず SetOutputLimit() を呼び出してから使うこと.
static void WaitAnyKey(const std::string &str="Waiting for input.")
入力待ちをする関数. 出力される文字列は,必ず OutputDetail::kSystem で出力される.
static void OutputNewLine(int num, OutputDetail detail)
コマンドラインで改行をする関数.
static void OutputTitle(const std::string &title_name, bool output_copy_right=false)
コマンドラインにこのソフトのタイトルを出力する関数. 出力される文字列は,必ず OutputDetail::kSystem で出力される.
static void OutputHorizontalLine(const std::string &line_visual, OutputDetail detail)
コマンドラインに水平線を出力する関数.
static bool InputYesNo(const std::string &str="Are you sure?")
yesかnoを入力させる関数.返り値で yes なら true,noなら falseを返す. 出力される文字列は,必ず OutputDetail::kSystem で出力される.
bool SelectFile(const std::string &path, int max_depth, const std::string &extension, const std::string keyword, std::string *output) const
ディレクトリの中から,ファイルを一つ選択する.
static constexpr int kLegNum
static const std::string kNodeListName
ノードリストのファイル名 (プログラムの読み込み用)
bool ImportNodeListAndMapState(const std::string &file_path, std::vector< RobotStateNode > *node_list, MapState *map_state) const
ノードリストとマップの状態をファイルから読み込む.
SystemMainRobotControl(const std::shared_ptr< GraphicDataBroker > &broker_ptr)
void Main() override
主要な処理を行う関数.
bool IsGrounded(const LegStateBit &leg_state, const int leg_index)
脚番号 leg_index 0 ~ 5 に応じて,その脚が接地しているかを調べる. 脚は右前脚を0番として,時計回りに0,1,2,3,4,5となる.左前足が5番.
void ChangeGround(const int leg_index, const bool is_ground, LegStateBit *leg_state)
脚の接地・遊脚情報を変更する.
OutputDetail
コマンドラインに文字を出力する際に,その詳細を指定するための列挙体.
@ kSystem
システムメッセージ,常に出力する.