Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
utils.cpp
Go to the documentation of this file.
2
3std::vector<custom_interfaces::msg::PathPoint> create_path_msg(std::string track_file) {
4 std::string track_file_path = "../../src/control/test/assets/" + track_file + ".csv";
5 std::ifstream trackFile(track_file_path);
6
7 std::vector<custom_interfaces::msg::PathPoint> pathpoint_array;
8
9 std::string line;
10
11 std::getline(trackFile, line); // Skip the first line
12
13 while (std::getline(trackFile, line)) {
14 std::istringstream iss(line);
15 std::string x, y, v;
16 if (std::getline(iss, x, ',') && std::getline(iss, y, ',') && std::getline(iss, v)) {
17 // Create a PathPoint and add it to the PathPointArray
18 custom_interfaces::msg::PathPoint point;
19 point.x = std::stod(x); // string to double
20 point.y = std::stod(y);
21 point.v = std::stod(v);
22 pathpoint_array.push_back(point);
23 }
24 }
25 trackFile.close();
26 return pathpoint_array;
27};
std::vector< custom_interfaces::msg::PathPoint > create_path_msg(std::string track_file)
Reads track files and creates a PathPointArray message.
Definition utils.cpp:3