4 RCLCPP_DEBUG(rclcpp::get_logger(
"rclcpp"),
"Start openReadFile");
5 std::string file_prefix = ament_index_cpp::get_package_share_directory(
"planning");
6 file_prefix = file_prefix.substr(0, file_prefix.find(
"install"));
7 std::string logger_variable = file_prefix + filename;
8 std::ifstream file(file_prefix + filename);
10 RCLCPP_ERROR(rclcpp::get_logger(
"rclcpp"),
"ERROR opening file: %s\n", logger_variable.c_str());
12 RCLCPP_DEBUG(rclcpp::get_logger(
"rclcpp"),
"Successfully opened %s \n",
13 logger_variable.c_str());
15 RCLCPP_DEBUG(rclcpp::get_logger(
"rclcpp"),
"End openReadFile");
24 std::vector<common_lib::structures::Cone> output;
25 while (track_file >> x >> y >> color) {
26 float x_value = stof(x);
27 float y_value = stof(y);
29 if (color ==
"blue_cone") {
30 cone_color = common_lib::competition_logic::Color::BLUE;
31 }
else if (color ==
"yellow_cone") {
32 cone_color = common_lib::competition_logic::Color::YELLOW;
33 }
else if (color ==
"orange_cone") {
34 cone_color = common_lib::competition_logic::Color::ORANGE;
35 }
else if (color ==
"large_orange_cone") {
36 cone_color = common_lib::competition_logic::Color::LARGE_ORANGE;
38 cone_color = common_lib::competition_logic::Color::UNKNOWN;
41 cone.
position.
x =
static_cast<double>(x_value);
42 cone.
position.
y =
static_cast<double>(y_value);
43 cone.
color = cone_color;
44 output.push_back(cone);
50std::pair<std::vector<common_lib::structures::Cone>, std::vector<common_lib::structures::Cone>>
56 std::vector<common_lib::structures::Cone> left_output;
57 std::vector<common_lib::structures::Cone> right_output;
58 while (track_file >> x >> y >> color) {
59 float x_value = stof(x);
60 float y_value = stof(y);
62 cone.
position.
x =
static_cast<double>(x_value);
63 cone.
position.
y =
static_cast<double>(y_value);
64 if (color ==
"blue_cone" || color ==
"blue") {
65 cone.
color = common_lib::competition_logic::Color::BLUE;
66 left_output.push_back(cone);
67 }
else if (color ==
"yellow_cone" || color ==
"yellow") {
68 cone.
color = common_lib::competition_logic::Color::YELLOW;
69 right_output.push_back(cone);
73 return std::make_pair(left_output, right_output);
76std::vector<common_lib::structures::PathPoint>
path_from_file(
const std::string &path) {
81 std::vector<common_lib::structures::PathPoint> output;
82 while (path_file >> x >> y >> v) {
83 float x_coordinate = stof(x);
84 float y_coordinate = stof(y);
85 float velocity = stof(v);
87 path_point.
position.
x =
static_cast<double>(x_coordinate);
88 path_point.
position.
y =
static_cast<double>(y_coordinate);
90 output.push_back(path_point);
96void extract_info(
const std::string_view &filename_view,
int &size,
int &n_outliers) {
97 std::string filename(filename_view);
98 size_t pos1 = filename.find(
"_");
99 size_t pos2 = filename.find(
"_", pos1 + 1);
100 size_t pos3 = filename.find(
".", pos2 + 1);
101 std::string size_str = filename.substr(pos1 + 1, pos2 - pos1 - 1);
102 std::string n_outliers_str = filename.substr(pos2 + 1, pos3 - pos2 - 1);
103 std::istringstream(size_str) >> size;
104 std::istringstream(n_outliers_str) >> n_outliers;
108 float max_distance = 0.0;
109 for (
size_t i = 1; i < cones.size(); i++) {
110 auto distance =
static_cast<float>(cones[i].position.euclidean_distance(cones[i - 1].position));
111 if (distance > max_distance) {
112 max_distance = distance;
119 const std::vector<std::pair<double, double>> &vec) {
120 std::vector<std::pair<double, double>> result = vec;
121 std::sort(result.begin(), result.end());
126 auto now = std::chrono::system_clock::now();
127 std::time_t now_time = std::chrono::system_clock::to_time_t(now);
129 localtime_r(&now_time, &now_tm);
131 std::stringstream ss;
132 ss << std::put_time(&now_tm,
"%Y-%m-%d-%H:%M");
137 num *=
static_cast<float>(pow(10, decimal_places));
138 auto intermediate =
static_cast<int>(
round(num));
139 num =
static_cast<float>(
static_cast<double>(intermediate) / pow(10, decimal_places));
std::vector< std::pair< double, double > > order_vector_of_pairs(const std::vector< std::pair< double, double > > &vec)
orders a vector of pairs to make it easier to compare them
std::string get_current_date_time_as_string()
Get current date and time as a string.
void extract_info(const std::string_view &filename_view, int &size, int &n_outliers)
Extracts the size and number of outliers from a filename.
std::vector< common_lib::structures::Cone > cone_vector_from_file(const std::string &path)
Retrieves a cone vector from a file.
std::vector< common_lib::structures::PathPoint > path_from_file(const std::string &path)
Retrieves a path point vector from a file.
std::ifstream open_read_file(const std::string &filename)
Opens a file for reading.
float consecutive_max_distance(const std::vector< common_lib::structures::Cone > &cones)
Retrieves the max consecutive distance between adjacent cones in a vector.
std::pair< std::vector< common_lib::structures::Cone >, std::vector< common_lib::structures::Cone > > track_from_file(const std::string &path)
Retrieves a track (a pair of colored cone vectors from each side) from a file.
float round_n(float num, int decimal_places)
rounds float to n decimal places
common_lib::competition_logic::Color color
double round(double number, int n)
round to n decimal places