10#include <boost/thread.hpp>
24 const std::shared_ptr<GraphicDataBroker>& broker_ptr,
25 const std::shared_ptr<const ApplicationSettingRecord> setting_ptr,
26 const std::shared_ptr<const IHexapodJointCalculator> joint_calculator,
27 const std::shared_ptr<const IHexapodCoordinateConverter> converter)
28 : broker_ptr_(broker_ptr),
29 joint_calculator_(joint_calculator),
30 converter_(converter) {}
52 std::vector<RobotStateNode> graph;
61 broker_ptr_->graph.SetData(graph);
62 broker_ptr_->map_state.SetData(map_state);
63 broker_ptr_->simulation_end_index.SetData({graph.size() - 1});
87void SystemMainResultViewer::OutputErrorLegPos(
88 const std::string& file,
const std::vector<RobotStateNode>& nodes) {
92 std::string file_name = file.substr(0, file.size() - 4);
94 const std::string output_path = file_name +
"_error_leg_pos.txt";
99 if (std::filesystem::exists(output_path)) {
100 std::filesystem::remove(output_path);
104 std::vector<Vector2> error_leg_pos;
106 for (
int i = 0; i < nodes.size(); i++) {
108 HexapodJointState joint_state =
109 joint_calculator_->CalculateJointState(j, nodes[i].leg_pos[j]);
111 if (!joint_calculator_->IsValidJointState(j, nodes[i].leg_pos[j],
113 const auto length = nodes[i].leg_pos[j].ProjectedXY().GetLength();
115 error_leg_pos.push_back({length, nodes[i].leg_pos[j].z});
121 std::vector<Vector2> error_first;
122 std::vector<Vector2> error_second;
123 std::vector<Vector2> error_end;
125 for (
int i = 0; i < nodes.size() - 1; i++) {
128 HexapodJointState current_joint_state =
129 joint_calculator_->CalculateJointState(j, nodes[i].leg_pos[j]);
130 HexapodJointState next_joint_state =
131 joint_calculator_->CalculateJointState(j, nodes[i + 1].leg_pos[j]);
133 if (!joint_calculator_->IsValidJointState(j, nodes[i].leg_pos[j],
134 current_joint_state) &&
135 !joint_calculator_->IsValidJointState(j, nodes[i + 1].leg_pos[j],
141 InterpolatedNodeCreator creator(converter_);
143 std::vector<RobotStateNode> interpolated_nodes =
144 creator.CreateInterpolatedNode(nodes[i], nodes[i + 1]);
149 for (
int k = 0; k < interpolated_nodes.size(); k++) {
150 HexapodJointState joint_state = joint_calculator_->CalculateJointState(
151 j, interpolated_nodes[k].leg_pos[j]);
153 if (!joint_calculator_->IsValidJointState(
154 j, interpolated_nodes[k].leg_pos[j], joint_state)) {
163 const auto length = nodes[i].leg_pos[j].ProjectedXY().GetLength();
164 error_first.push_back({length, nodes[i].leg_pos[j].z});
166 const auto length3 = nodes[i + 1].leg_pos[j].ProjectedXY().GetLength();
167 error_end.push_back({length3, nodes[i + 1].leg_pos[j].z});
170 if (length < length3) {
171 second = Vector2{error_first.back().x, error_end.back().y};
173 second = Vector2{error_end.back().x, error_first.back().y};
176 error_second.push_back(second);
184 std::ofstream ofs(output_path);
187 ofs <<
" x_position += [";
189 for (
int i = 0; i < error_leg_pos.size(); i++) {
190 ofs << error_leg_pos[i].x <<
", ";
193 ofs <<
"]" << std::endl;
194 ofs <<
" z_position += [";
196 for (
int i = 0; i < error_leg_pos.size(); i++) {
197 ofs << error_leg_pos[i].y <<
", ";
200 ofs <<
"]" << std::endl;
205 ofs <<
" x_position_first += [";
207 for (
int i = 0; i < error_leg_pos.size(); i++) {
208 ofs << error_first[i].x <<
", ";
211 ofs <<
"]" << std::endl;
212 ofs <<
" z_position_first += [";
214 for (
int i = 0; i < error_leg_pos.size(); i++) {
215 ofs << error_first[i].y <<
", ";
218 ofs <<
"]" << std::endl;
222 ofs <<
" x_position_second += [";
224 for (
int i = 0; i < error_leg_pos.size(); i++) {
225 ofs << error_second[i].x <<
", ";
228 ofs <<
"]" << std::endl;
229 ofs <<
" z_position_second += [";
231 for (
int i = 0; i < error_leg_pos.size(); i++) {
232 ofs << error_second[i].y <<
", ";
235 ofs <<
"]" << std::endl;
239 ofs <<
" x_position_end += [";
241 for (
int i = 0; i < error_leg_pos.size(); i++) {
242 ofs << error_end[i].x <<
", ";
245 ofs <<
"]" << std::endl;
246 ofs <<
" z_position_end += [";
248 for (
int i = 0; i < error_leg_pos.size(); i++) {
249 ofs << error_end[i].y <<
", ";
252 ofs <<
"]" << std::endl;
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
主要な処理を行う関数.
void OutputHorizontalLine(const std::string &line_visual, OutputDetail detail)
コマンドラインに水平線を出力する関数.
void WaitAnyKey(const std::string &str="Waiting for input.")
入力待ちをする関数. 出力される文字列は, 必ず OutputDetail::kSystem で出力される.
void OutputNewLine(int num, OutputDetail detail)
コマンドラインで改行をする関数.
void OutputTitle(const std::string &title_name, bool output_copy_right=false)
コマンドラインにこのソフトのタイトルを出力する関数. 出力される文字列は,必ず OutputDetail::kSystem で出力される.
void Output(const std::string &str, OutputDetail detail)
コマンドラインに文字を出力する関数. SetOutputLimit 関数で設定した出力の許可範囲内であれば出力される.
bool InputYesNo(const std::string &str="Are you sure?")
yesかnoを入力させる関数.返り値で yes なら true, no なら false を返す. 出力される文字列は,必ず OutputDetail::kSystem で出力される.
OutputDetail
コマンドラインに文字を出力する際に,その詳細を指定するための列挙体.
@ kSystem
システムメッセージ,常に出力する.