function block for RefBox
以前作った,RefBox と通信するView2 のプログラムを更新してView2 のFunction Block にします.
ファイル構成としては,llsf-refbox/bin/llsf-view2-var.sh に変数の中身を出力するとともに,view2send.txt にenum 的な数字で出力しています.
前者は,view2_HOGEHOGE,後者はsendData.HOGEHOGE に保存.
まずは,その頃とのdiffを確認.
wataru@ubuntu:~/lab/btr2018/llsf-refbox/src$ diff tools/llsf-fake-robot.cpp tools.view2/llsf-fake-robot.cpp
43,44d42
< #include <utils/system/console_colors.h>
< #include <utils/misc/string_split.h>
54d51
< #include <msgs/RingInfo.pb.h>
167,179c164,166
< std::list<std::string> rings;
< for (int j = 0; j < o.ring_colors_size(); ++j) {
< rings.push_back(llsf_msgs::RingColor_Name(o.ring_colors(j)));;
< }
<
< printf(" %u (%s): %s%u%s/%s%u%s/%u of %s|%s|%s from %02u:%02u to %02u:%02u at gate %u\n", o.id(),
< llsf_msgs::Order::Complexity_Name(o.complexity()).c_str(),
< c_cyan, o.quantity_delivered_cyan(), c_normal,
< c_purple, o.quantity_delivered_magenta(), c_normal,
< o.quantity_requested(),
< llsf_msgs::BaseColor_Name(o.base_color()).c_str(),
< str_join(rings, "-").c_str(),
< llsf_msgs::CapColor_Name(o.cap_color()).c_str(),
---
> printf(" %u: %u/%u of %s from %02u:%02u to %02u:%02u at gate %s\n", o.id(),
> o.quantity_delivered(), o.quantity_requested(),
> llsf_msgs::Order::ProductType_Name(o.product()).c_str(),
181c168
< o.delivery_gate());
---
> llsf_msgs::Order::DeliveryGate_Name(o.delivery_gate()).c_str());
204,207c191,194
< for (int i = 0; i < ei->zones_size(); ++i) {
< const ExplorationZone &zm = ei->zones(i);
< printf(" Zone %s of team %s\n",
< Zone_Name(zm.zone()).c_str(), Team_Name(zm.team_color()).c_str());
---
> for (int i = 0; i < ei->machines_size(); ++i) {
> const ExplorationMachine &em = ei->machines(i);
> printf(" Machine %s at (%f, %f, %f)\n", em.name().c_str(),
> em.pose().x(), em.pose().y(), em.pose().ori());
217c204
< printf(" %-3s|%2s|%s (%s) @ (%f, %f, %f)\n",
---
> printf(" %-3s|%2s|%s @ (%f, %f, %f)\n",
220d206
< m.state().c_str(),
262,273d247
<
< std::shared_ptr<RingInfo> rgi;
< if ((rgi = std::dynamic_pointer_cast<RingInfo>(msg))) {
< printf("RingInfo received:\n");
< for (int i = 0; i < rgi->rings_size(); ++i) {
< const Ring &r = rgi->rings(i);
< printf(" %s %u\n",
< RingColor_Name(r.ring_color()).c_str(),
< r.raw_material());
< }
< }
<
364d337
< message_register.add_message_type<RingInfo>();
wataru@ubuntu:~/lab/btr2018/llsf-refbox/src$ diff tools/llsf-fake-robot.cpp tools.view2/llsf-fake-robot.cpp
43,44d42
< #include <utils/system/console_colors.h>
< #include <utils/misc/string_split.h>
54d51
< #include <msgs/RingInfo.pb.h>
167,179c164,166
< std::list<std::string> rings;
< for (int j = 0; j < o.ring_colors_size(); ++j) {
< rings.push_back(llsf_msgs::RingColor_Name(o.ring_colors(j)));;
< }
<
< printf(" %u (%s): %s%u%s/%s%u%s/%u of %s|%s|%s from %02u:%02u to %02u:%02u at gate %u\n", o.id(),
< llsf_msgs::Order::Complexity_Name(o.complexity()).c_str(),
< c_cyan, o.quantity_delivered_cyan(), c_normal,
< c_purple, o.quantity_delivered_magenta(), c_normal,
< o.quantity_requested(),
< llsf_msgs::BaseColor_Name(o.base_color()).c_str(),
< str_join(rings, "-").c_str(),
< llsf_msgs::CapColor_Name(o.cap_color()).c_str(),
---
> printf(" %u: %u/%u of %s from %02u:%02u to %02u:%02u at gate %s\n", o.id(),
> o.quantity_delivered(), o.quantity_requested(),
> llsf_msgs::Order::ProductType_Name(o.product()).c_str(),
181c168
< o.delivery_gate());
---
> llsf_msgs::Order::DeliveryGate_Name(o.delivery_gate()).c_str());
204,207c191,194
< for (int i = 0; i < ei->zones_size(); ++i) {
< const ExplorationZone &zm = ei->zones(i);
< printf(" Zone %s of team %s\n",
< Zone_Name(zm.zone()).c_str(), Team_Name(zm.team_color()).c_str());
---
> for (int i = 0; i < ei->machines_size(); ++i) {
> const ExplorationMachine &em = ei->machines(i);
> printf(" Machine %s at (%f, %f, %f)\n", em.name().c_str(),
> em.pose().x(), em.pose().y(), em.pose().ori());
217c204
< printf(" %-3s|%2s|%s (%s) @ (%f, %f, %f)\n",
---
> printf(" %-3s|%2s|%s @ (%f, %f, %f)\n",
220d206
< m.state().c_str(),
262,273d247
<
< std::shared_ptr<RingInfo> rgi;
< if ((rgi = std::dynamic_pointer_cast<RingInfo>(msg))) {
< printf("RingInfo received:\n");
< for (int i = 0; i < rgi->rings_size(); ++i) {
< const Ring &r = rgi->rings(i);
< printf(" %s %u\n",
< RingColor_Name(r.ring_color()).c_str(),
< r.raw_material());
< }
< }
<
364d337
< message_register.add_message_type<RingInfo>();
wataru@ubuntu:~/lab/btr2018/llsf-refbox/src$ diff tools/llsf-report-machine.cpp tools.view2/llsf-report-machine.cpp
7d6
< * 2017 Tobias Neumann
50d48
< #include <boost/lexical_cast.hpp>
58,68c56,58
< bool send_rotation_ = false;
< unsigned int machine_rotation_;
< bool send_zone_ = false;
< llsf_msgs::Zone machine_zone_;
< std::string team_name_;
< Team team_color_;
< ProtobufBroadcastPeer *peer_public_ = NULL;
< ProtobufBroadcastPeer *peer_team_ = NULL;
< bool crypto_setup_ = false;
<
< llsfrb::Configuration *config_;
---
> std::string machine_type_;
> Team team_;
> ProtobufBroadcastPeer *peer_ = NULL;
96,138d85
< std::shared_ptr<GameState> gs;
< if ((gs = std::dynamic_pointer_cast<GameState>(msg))) {
< int hour = gs->game_time().sec() / 3600;
< int min = (gs->game_time().sec() - hour * 3600) / 60;
< int sec = gs->game_time().sec() - hour * 3600 - min * 60;
<
< #if __WORDSIZE == 64
< printf("GameState received: %02i:%02i:%02i.%02ld %s %s %u:%u points, %s vs. %s\n",
< #else
< printf("GameState received: %02i:%02i:%02i.%02lld %s %s %u:%u points, %s vs. %s\n",
< #endif
< hour, min, sec, gs->game_time().nsec() / 1000000,
< llsf_msgs::GameState::Phase_Name(gs->phase()).c_str(),
< llsf_msgs::GameState::State_Name(gs->state()).c_str(),
< gs->points_cyan(), gs->points_magenta(),
< gs->team_cyan().c_str(), gs->team_magenta().c_str());
<
< if (team_name_ == gs->team_cyan() || team_name_ == gs->team_magenta()) {
< if (team_name_ == gs->team_cyan() && team_color_ != CYAN) {
< printf("WARNING: sending as magenta, but our team is announced as cyan by refbox!\n");
< } else if (team_name_ == gs->team_magenta() && team_color_ != MAGENTA) {
< printf("WARNING: sending as cyan, but our team is announced as magenta by refbox!\n");
< }
< if (! crypto_setup_) {
< crypto_setup_ = true;
<
< std::string crypto_key = "", cipher = "aes-128-cbc";
< try {
< crypto_key = config_->get_string(("/llsfrb/game/crypto-keys/" + team_name_).c_str());
< printf("Set crypto key to %s (cipher %s)\n", crypto_key.c_str(), cipher.c_str());
< peer_team_->setup_crypto(crypto_key, cipher);
< } catch (Exception &e) {
< printf("No encryption key configured for team, not enabling crypto");
< }
< }
< } else if (crypto_setup_) {
< printf("Our team is not set, training game? Disabling crypto.\n");
< crypto_setup_ = false;
< peer_team_->setup_crypto("", "");
< }
< }
<
<
142,144c89
< printf("Announcing machine: Zone: %s rotation %u\n",
< send_zone_ ? Zone_Name(machine_zone_).c_str() : "*NO*",
< send_rotation_ ? machine_rotation_ : -1);
---
> printf("Announcing machine type\n");
146c91
< report.set_team_color(team_color_);
---
> report.set_team_color(team_);
149,151c94,95
< if (send_rotation_) entry->set_rotation(machine_rotation_);
< if (send_zone_) entry->set_zone(machine_zone_);
< peer_team_->send(report);
---
> entry->set_type(machine_type_);
> peer_->send(report);
157,158c101,102
< if (mrinfo->team_color() == team_color_) {
< printf("Reported machines (%s):", llsf_msgs::Team_Name(team_color_).c_str());
---
> if (mrinfo->team_color() == team_) {
> printf("Reported machines (%s):", llsf_msgs::Team_Name(team_).c_str());
170c114
< ArgumentParser argp(argc, argv, "T:r:z:");
---
> ArgumentParser argp(argc, argv, "T:");
172,179c116,120
< if (argp.num_items() != 2 || (! argp.has_arg("t") && ! argp.has_arg("z"))) {
< printf("Usage: %s [-T team] [-t <type>] [-z <zone>] <team-name> <machine-name>\n"
< "\n"
< "-T team Select team to send for, CYAN (default) or MAGENTA\n"
< "-r rotation Rotation to report for machine\n"
< "-z zone Zone to report for machine\n\n"
< "You must supply at least one of type and zone, or both.\n",
< argv[0]);
---
> if (argp.num_items() != 2) {
> printf("Usage: %s [-T team] <machine-name> <machine-type>\n"
> "\n"
> "-T team Select team to send for, CYAN (default) or MAGENTA\n",
> argv[0]);
183,184c124,125
< team_name_ = argp.items()[0];
< machine_name_ = argp.items()[1];
---
> machine_name_ = argp.items()[0];
> machine_type_ = argp.items()[1];
186,197c127,128
< if (argp.has_arg("r")) {
< machine_rotation_ = boost::lexical_cast<unsigned int>(argp.arg("r"));
< send_rotation_ = true;
< }
<
< if (argp.has_arg("z")) {
< if (! llsf_msgs::Zone_Parse(argp.arg("z"), &machine_zone_)) {
< printf("Invalid zone\n");
< exit(2);
< }
< send_zone_ = true;
< }
---
> llsfrb::Configuration *config = new llsfrb::YamlConfiguration(CONFDIR);
> config->load("config.yaml");
198a130,139
> if (config->exists("/llsfrb/comm/peer-send-port") &&
> config->exists("/llsfrb/comm/peer-recv-port") )
> {
> peer_ = new ProtobufBroadcastPeer(config->get_string("/llsfrb/comm/peer-host"),
> config->get_uint("/llsfrb/comm/peer-recv-port"),
> config->get_uint("/llsfrb/comm/peer-send-port"));
> } else {
> peer_ = new ProtobufBroadcastPeer(config->get_string("/llsfrb/comm/peer-host"),
> config->get_uint("/llsfrb/comm/peer-port"));
> }
200c141
< team_color_ = CYAN;
---
> team_ = CYAN;
204c145
< team_color_ = CYAN;
---
> team_ = CYAN;
206c147
< team_color_ = MAGENTA;
---
> team_ = MAGENTA;
212,224c153
< config_ = new llsfrb::YamlConfiguration(CONFDIR);
< config_->load("config.yaml");
<
< if (config_->exists("/llsfrb/comm/public-peer/send-port") &&
< config_->exists("/llsfrb/comm/public-peer/recv-port") )
< {
< peer_public_ = new ProtobufBroadcastPeer(config_->get_string("/llsfrb/comm/public-peer/host"),
< config_->get_uint("/llsfrb/comm/public-peer/recv-port"),
< config_->get_uint("/llsfrb/comm/public-peer/send-port"));
< } else {
< peer_public_ = new ProtobufBroadcastPeer(config_->get_string("/llsfrb/comm/public-peer/host"),
< config_->get_uint("/llsfrb/comm/public-peer/port"));
< }
---
> boost::asio::io_service io_service;
226c155
< MessageRegister & message_register = peer_public_->message_register();
---
> MessageRegister & message_register = peer_->message_register();
232,250d160
< std::string cfg_prefix =
< std::string("/llsfrb/comm/") +
< ((team_color_ == CYAN) ? "cyan" : "magenta") + "-peer/";
<
< if (config_->exists((cfg_prefix + "send-port").c_str()) &&
< config_->exists((cfg_prefix + "recv-port").c_str()) )
< {
< peer_team_ = new ProtobufBroadcastPeer(config_->get_string((cfg_prefix + "host").c_str()),
< config_->get_uint((cfg_prefix + "recv-port").c_str()),
< config_->get_uint((cfg_prefix + "send-port").c_str()),
< &message_register /*, crypto_key, cipher*/);
< } else {
< peer_team_ = new ProtobufBroadcastPeer(config_->get_string((cfg_prefix + "host").c_str()),
< config_->get_uint((cfg_prefix + "port").c_str()),
< &message_register/*, crypto_key, cipher*/);
< }
<
< boost::asio::io_service io_service;
<
253,259c163,165
< peer_public_->signal_received().connect(handle_message);
< peer_public_->signal_recv_error().connect(handle_recv_error);
< peer_public_->signal_send_error().connect(handle_send_error);
<
< peer_team_->signal_received().connect(handle_message);
< peer_team_->signal_recv_error().connect(handle_recv_error);
< peer_team_->signal_send_error().connect(handle_send_error);
---
> peer_->signal_received().connect(handle_message);
> peer_->signal_recv_error().connect(handle_recv_error);
> peer_->signal_send_error().connect(handle_send_error);
274,276c180,181
< delete peer_public_;
< delete peer_team_;
< delete config_;
---
> delete peer_;
> delete config;
コメントを残す