TechTheTime-HighLevel 0.0.1
The high level robot's code using ros2-foxy for the robotics competition(Erobot-2022)
order_reader.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <tuple>
4#include <action_msg_srv_shared/order_codes.hpp>
5#include <map>
6
7namespace order_reader {
8
9 extern std::map<std::string, OrderCodes> str_to_order_code;
10
11 inline std::tuple<OrderCodes, double, int64_t, double> get_order_as_tuple(std::string str) {
12
13 OrderCodes order_code;
14 double distance;
15 int64_t id;
16 double angle;
17
18 str.append(" ");
19
20 int processed = 0;
21 int prev_str_ptr = 0;
22 for(size_t i = 0; i < str.size(); i++) {
23 if(str.at(i) == ' ') {
24 if(processed == 0) {
25 order_code = str_to_order_code.at(str.substr(prev_str_ptr, i-prev_str_ptr));
26 } else if(processed == 1) {
27 distance = std::stod(str.substr(prev_str_ptr, i-prev_str_ptr));
28 } else if(processed == 2) {
29 id = std::stoi(str.substr(prev_str_ptr, i-prev_str_ptr));
30 } else if(processed == 3) {
31 angle = std::stod(str.substr(prev_str_ptr, i-prev_str_ptr));
32 } else {
33 break;
34 }
35 processed++;
36 prev_str_ptr = i + 1;
37 }
38 }
39 return std::make_tuple(order_code, distance, id, angle);
40 }
41}
Definition: order_reader.hpp:7
std::tuple< OrderCodes, double, int64_t, double > get_order_as_tuple(std::string str)
Definition: order_reader.hpp:11
std::map< std::string, OrderCodes > str_to_order_code
Definition: order_reader.cpp:5