14#include <boost/thread.hpp>
27 const std::shared_ptr<GraphicDataBroker>& broker_ptr,
28 const std::shared_ptr<const ApplicationSettingRecord> setting_ptr,
29 const std::shared_ptr<const IHexapodJointCalculator> joint_calculator,
30 const std::shared_ptr<const IHexapodCoordinateConverter> converter) :
31 broker_ptr_(broker_ptr),
32 joint_calculator_(joint_calculator),
59 std::vector<RobotStateNode> graph;
68 broker_ptr_->graph.SetData(graph);
69 broker_ptr_->map_state.SetData(map_state);
70 broker_ptr_->simulation_end_index.SetData({ graph.size() - 1 });
97void SystemMainResultViewer::OutputErrorLegPos(
const std::string& file,
const std::vector<RobotStateNode>& nodes)
102 std::string file_name = file.substr(0, file.size() - 4);
104 const std::string output_path = file_name +
"_error_leg_pos.txt";
109 if (std::filesystem::exists(output_path))
111 std::filesystem::remove(output_path);
115 std::vector<Vector2> error_leg_pos;
117 for (
int i = 0; i < nodes.size(); i++)
121 HexapodJointState joint_state = joint_calculator_->CalculateJointState(j, nodes[i].leg_pos[j]);
123 if (!joint_calculator_->IsValidJointState(j, nodes[i].leg_pos[j], joint_state))
125 const auto length = nodes[i].leg_pos[j].ProjectedXY().GetLength();
127 error_leg_pos.push_back({ length, nodes[i].leg_pos[j].z });
133 std::vector<Vector2> error_first;
134 std::vector<Vector2> error_second;
135 std::vector<Vector2> error_end;
137 for (
int i = 0; i < nodes.size() - 1; i++)
142 HexapodJointState current_joint_state = joint_calculator_->CalculateJointState(j, nodes[i].leg_pos[j]);
143 HexapodJointState next_joint_state = joint_calculator_->CalculateJointState(j, nodes[i + 1].leg_pos[j]);
145 if (!joint_calculator_->IsValidJointState(j, nodes[i].leg_pos[j], current_joint_state) &&
146 !joint_calculator_->IsValidJointState(j, nodes[i + 1].leg_pos[j], next_joint_state))
152 InterpolatedNodeCreator creator(converter_);
154 std::vector<RobotStateNode> interpolated_nodes = creator.CreateInterpolatedNode(nodes[i], nodes[i + 1]);
159 for (
int k = 0; k < interpolated_nodes.size(); k++)
161 HexapodJointState joint_state = joint_calculator_->CalculateJointState(j, interpolated_nodes[k].leg_pos[j]);
163 if (!joint_calculator_->IsValidJointState(j, interpolated_nodes[k].leg_pos[j], joint_state))
174 const auto length = nodes[i].leg_pos[j].ProjectedXY().GetLength();
175 error_first.push_back({ length, nodes[i].leg_pos[j].z });
177 const auto length3 = nodes[i + 1].leg_pos[j].ProjectedXY().GetLength();
178 error_end.push_back({ length3, nodes[i + 1].leg_pos[j].z });
181 if (length < length3)
183 second = Vector2{ error_first.back().x, error_end.back().y };
187 second = Vector2{ error_end.back().x, error_first.back().y };
190 error_second.push_back(second);
198 std::ofstream ofs(output_path);
201 ofs <<
" x_position += [";
203 for (
int i = 0; i < error_leg_pos.size(); i++)
205 ofs << error_leg_pos[i].x <<
", ";
208 ofs <<
"]" << std::endl;
209 ofs <<
" z_position += [";
211 for (
int i = 0; i < error_leg_pos.size(); i++)
213 ofs << error_leg_pos[i].y <<
", ";
216 ofs <<
"]" << std::endl;
221 ofs <<
" x_position_first += [";
223 for (
int i = 0; i < error_leg_pos.size(); i++)
225 ofs << error_first[i].x <<
", ";
228 ofs <<
"]" << std::endl;
229 ofs <<
" z_position_first += [";
231 for (
int i = 0; i < error_leg_pos.size(); i++)
233 ofs << error_first[i].y <<
", ";
236 ofs <<
"]" << std::endl;
240 ofs <<
" x_position_second += [";
242 for (
int i = 0; i < error_leg_pos.size(); i++)
244 ofs << error_second[i].x <<
", ";
247 ofs <<
"]" << std::endl;
248 ofs <<
" z_position_second += [";
250 for (
int i = 0; i < error_leg_pos.size(); i++)
252 ofs << error_second[i].y <<
", ";
255 ofs <<
"]" << std::endl;
259 ofs <<
" x_position_end += [";
261 for (
int i = 0; i < error_leg_pos.size(); i++)
263 ofs << error_end[i].x <<
", ";
266 ofs <<
"]" << std::endl;
267 ofs <<
" z_position_end += [";
269 for (
int i = 0; i < error_leg_pos.size(); i++)
271 ofs << error_end[i].y <<
", ";
274 ofs <<
"]" << std::endl;
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
ノードリストのファイル名 (プログラムの読み込み用)
static const std::string kDirectoryPath
出力先ディレクトリ(フォルダ)名.
bool ImportNodeListAndMapState(const std::string &file_path, std::vector< RobotStateNode > *node_list, MapState *map_state) const
ノードリストとマップの状態をファイルから読み込む.
SystemMainResultViewer(const std::shared_ptr< GraphicDataBroker > &broker_ptr, const std::shared_ptr< const ApplicationSettingRecord > setting_ptr, const std::shared_ptr< const IHexapodJointCalculator > joint_calculator, const std::shared_ptr< const IHexapodCoordinateConverter > converter)
void Main() override
主要な処理を行う関数.
OutputDetail
コマンドラインに文字を出力する際に,その詳細を指定するための列挙体.
@ kSystem
システムメッセージ,常に出力する.