22 const int window_x,
const int window_y,
23 const std::shared_ptr<const IHexapodCoordinateConverter>& converter_ptr,
24 const std::shared_ptr<const IHexapodJointCalculator>& calculator_ptr,
25 const std::shared_ptr<const IHexapodPostureValidator>& checker_ptr) :
29 converter_ptr_(converter_ptr),
30 calculator_ptr_(calculator_ptr),
31 checker_ptr_(checker_ptr)
33 assert(converter_ptr_ !=
nullptr);
34 assert(calculator_ptr_ !=
nullptr);
35 assert(checker_ptr_ !=
nullptr);
37 const int button_distance = 10;
38 const int button_size = 60;
40 const int button_range = button_size + button_distance;
44 button_.push_back(std::make_unique<SimpleButton>(
45 "Toggle\nMode", left_pos_x, top_pos_y, button_size, button_size));
46 button_.back()->SetActivateFunction(
47 [
this]() {auto_update_flag_ = !auto_update_flag_; });
49 button_.push_back(std::make_unique<SimpleButton>(
50 "Update", left_pos_x, top_pos_y + button_range, button_size, button_size));
51 button_.back()->SetActivateFunction(
52 [
this]() { serial_communication_.
SetWriteData(GetSerialData()); });
54 const int close_button_size = 28;
55 const int close_button_x =
gui_left_pos_x_ + kWidth - close_button_size / 2 - 2;
56 const int close_button_y =
gui_top_pos_y_ + close_button_size / 2 + 2;
58 button_.push_back(std::make_unique<SimpleButton>(
59 "×", close_button_x, close_button_y, close_button_size, close_button_size));
63 serial_communication_thread_ptr_ =
64 std::make_unique<boost::thread>(
70 if (serial_communication_thread_ptr_)
74 serial_communication_thread_ptr_->join();
88 if (auto_update_flag_ && counter_ % 120 == 0)
112void DxlibGuiRobotControl::DrawString()
const
114 const unsigned int str_color = GetColor(54, 54, 54);
116 const int text_interval_y = 20;
122 if (serial_communication_.
IsEnd())
124 DrawFormatStringToHandle(
gui_left_pos_x_ + 10, text_top_y + text_interval_y * (text_line++), str_color,
font_handle_,
"スレッドは終了しています.");
128 DrawFormatStringToHandle(
gui_left_pos_x_ + 10, text_top_y + text_interval_y * (text_line++), str_color,
font_handle_,
"スレッドは実行中です.");
132 const std::vector<std::string> read_data = serial_communication_.
GetAllReadData();
133 DrawFormatStringToHandle(
gui_left_pos_x_ + 10, text_top_y + text_interval_y * (text_line++), str_color,
font_handle_,
"受信したデータの数: %d", read_data.size());
136 int display_num = 20;
138 for (
auto i = read_data.rbegin(); i != read_data.rend(); ++i)
140 std::string str =
"[" + std::to_string(
static_cast<int>(read_data.size()) - (10 - display_num)) +
"] ";
143 DrawFormatStringToHandle(
gui_left_pos_x_ + 10, text_top_y + text_interval_y * (text_line++), str_color,
font_handle_,
"%s", str.c_str());
145 if (--display_num <= 0)
152bool DxlibGuiRobotControl::IsInWindow()
const
158std::string DxlibGuiRobotControl::GetSerialData()
const
163 std::uint8_t send_data[64] = {};
167 const std::uint32_t leg_x = abs(
static_cast<int>(node_.
leg_pos[i].x));
169 send_data[i * 8 + 0] =
static_cast<std::uint8_t
>(leg_x & 0x000000ff);
170 send_data[i * 8 + 1] =
static_cast<std::uint8_t
>((leg_x & 0x0000ff00) >> 8);
172 const std::uint32_t leg_y = abs(
static_cast<int>(node_.
leg_pos[i].y));
174 send_data[i * 8 + 2] =
static_cast<std::uint8_t
>(leg_y & 0x000000ff);
175 send_data[i * 8 + 3] =
static_cast<std::uint8_t
>((leg_y & 0x0000ff00) >> 8);
178 float leg_z_pos = node_.
leg_pos[i].z;
179 if (-30 >= leg_z_pos && leg_z_pos >= -45) { leg_z_pos = -45; }
180 const std::uint32_t leg_z = abs(
static_cast<int>(leg_z_pos));
182 send_data[i * 8 + 4] =
static_cast<std::uint8_t
>(leg_z & 0x000000ff);
183 send_data[i * 8 + 5] =
static_cast<std::uint8_t
>((leg_z & 0x0000ff00) >> 8);
191 send_data[already_sent_data_num + i] = 0;
195 send_data[already_sent_data_num + i] |= 0x01;
200 send_data[already_sent_data_num + i] |= 0x02;
205 send_data[already_sent_data_num + i] |= 0x04;
212 for (
size_t i = 0; i < 64; i++)
214 str +=
static_cast<char>(send_data[i]);
void DrawBackground(const std::string &str) const
int gui_left_pos_x_
GUIの左端の位置.
int gui_top_pos_y_
GUIの上端の位置.
void SetVisible(bool visible) override
GUIの表示を行うかどうかを設定する.
int font_handle_
フォントハンドル.
std::vector< std::unique_ptr< SimpleButton > > button_
ボタンのリスト.
void Draw() const override
GUIの描画.
void Update() override
GUIの更新,毎フレーム実行すること.
DxlibGuiRobotControl()=delete
デフォルトコンストラクタは生成できない.
static constexpr int kLegNum
void SetWriteData(const std::string &str)
指定した文字列をシリアル通信で送信する. この時,排他制御を行う.
void EndThread()
シリアル通信のスレッドを終了する.
std::vector< std::string > GetAllReadData() const
シリアル通信で受信した文字列を全て取得する. この時,排他制御を行う.
std::array< Vector3, HexapodConst::kLegNum > leg_pos
[4 * 3 * 6 = 72 byte] 脚先の座標.(coxa(脚の付け根)を原点とする)