6 const std::string &schedule_file,
7 const unsigned int &robot_id) : node_(
node), robot_id_(robot_id), enabled_(true)
11 int64_t initial_time = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
12 std::ifstream schedule(schedule_file);
13 if (schedule.is_open())
15 for (std::string line; std::getline(schedule, line);)
17 auto delim0 = line.find(
",");
18 if (robot_id_ == std::stoul(line.substr(0, delim0)))
20 RCLCPP_INFO(node_->get_logger(),
"Simulated rendezvous schedule of robot %s", line.c_str());
21 while (delim0 != std::string::npos)
23 auto delim1 = line.find(
",", delim0 + 1);
25 auto start = std::stoull(line.substr(delim0 + 1, delim1)) + initial_time;
28 delim1 = line.find(
",", delim0);
30 auto end = std::stoull(line.substr(delim0 + 1, delim1)) + initial_time;
32 rendezvous_ranges_.push_back(std::make_pair(start, end));
34 delim0 = line.find(
",", delim1 +1);
40 RCLCPP_ERROR(node_->get_logger(),
"Unable to open rendezvous schedule file");
44 catch (
const std::exception &e)
46 RCLCPP_ERROR(node_->get_logger(),
"Reading simulated rendezvous schedule failed: %s", e.what());
56 uint64_t current_time = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
58 for (
const auto &range : rendezvous_ranges_)
61 if (current_time >= range.first && current_time <= range.second)
bool is_alive()
Check if the robot is alive (aka in the rendez-vous schedule)
SimulatedRendezVous(std::shared_ptr< rclcpp::Node > &node, const std::string &schedule_file, const unsigned int &robot_id)
Rendez-vous simulation. Reads a config file indicating when the robot should be considered alive.