Class Raceline

Class Documentation

class Raceline

Represents the path that the car follows, extracted from the map.

Public Functions

Raceline()

Constructor for the Raceline class.

inline void initialize(const std::string &filename, bool is_closed_track = true)

Initializes the Raceline object with raceline data.

Parameters:

filename – Name of the CSV file containing the raceline data.

inline void initialize(const std::string &filename, bool &success, bool is_closed_track = true)

Initializes the Raceline object with raceline data.

Parameters:
  • filename – Name of the CSV file containing the raceline data.

  • success – Reference to a boolean variable to store the success status.

inline float get_target_speed(int index) const

Retrieves the target speed based on the speed function.

Parameters:

index – The index of the point on the path.

Returns:

The target speed at the given index.

inline RacelineRow get_raceline_row(int index) const

Retrieves the raceline data at a given index.

Parameters:

index – The index of the point on the path.

Returns:

The raceline data at the given index.

inline RacelineData get_raceline_data() const

Retrieves the whole raceline data.

Returns:

The raceline data.

std::tuple<std::vector<float>, std::vector<float>, std::vector<float>, std::vector<float>> get_borders() const

Retrieves the borders of the raceline.

Returns:

A tuple containing the borders of the raceline:

  • first: x coordinates of the left border

  • second: y coordinates of the left border

  • third: x coordinates of the right border

  • fourth: y coordinates of the right border

inline int get_num_points() const

Retrieves the raceline data at a given index.

Returns:

The number of points in the raceline.

inline int get_nearest_index() const

Retrieves the nearest index.

Returns:

The index of the nearest point on the raceline.

inline std::pair<std::vector<float>, std::vector<float>> get_raceline_xy() const

Retrieves the raceline points.

Returns:

A pair of vectors containing the x and y coordinates:

  • first: x coordinates as a vector

  • second: y coordinates as a vector

inline std::vector<float> get_heading() const

Retrieves the heading angles of the raceline points.

Returns:

A vector containing the heading angles of the raceline points.

inline std::vector<float> get_curvature() const

Retrieves the curvature values of the raceline points.

Returns:

A vector containing the curvature values of the raceline points.

void read_csv(const std::string &filename)

Reads the raceline data from a CSV file.

Parameters:

filename – The name of the CSV file to read.

void read_csv(const std::string &filename, bool &success)

Reads the raceline data from a CSV file and returns success status.

Parameters:
  • filename – The name of the CSV file to read.

  • success – A reference to a boolean variable to store the success status.

int search_nearest_index(const float &x, const float &y, float window_size_m = 0.0f) const

Searches for the nearest index in a set of points to a given (x, y) coordinate.

This function iterates through the set of points defined by the raceline data, and finds the index of the point that is closest to the given (x, y) coordinate.

Parameters:
  • x – The x-coordinate of the point to search for.

  • y – The y-coordinate of the point to search for.

  • window_size_m – Search window (meters) around the last nearest index. 0 = full scan.

Returns:

int The index of the nearest point in the set.

int search_nearest_index(const float &s) const

Searches for the nearest index in the array based on the given value.

This function iterates through the array of s values in the raceline and finds the index of the point that is closest to the given value s. The distance is calculated using the absolute difference between the given value and each point in the array.

Parameters:

s – The value to search for the nearest index.

Returns:

The index of the point that is closest to the given value s.

std::pair<float, float> frenet_to_cartesian_r(const float &s, const float &d) const

Converts a Frenet s and d Frenet coordinate into cartesian coordinate.

This function takes a pair of Frenet coordinates (s, d) and converts them into Cartesian coordinates based on the raceline data.

Parameters:
  • s – The Frenet s coordinate.

  • d – The Frenet d coordinate.

Returns:

The vector of Cartesian points.

std::pair<float, float> frenet_to_cartesian_r(const std::pair<float, float> &point) const

Converts a single Frenet point into Cartesian coordinates.

This function takes a single point in Frenet coordinates and converts it into Cartesian coordinates based on the raceline data.

Parameters:

point – The Frenet point to convert, tuple of s and d.

Returns:

The Cartesian point.

std::vector<std::pair<float, float>> frenet_to_cartesian_r(const std::vector<std::pair<float, float>> &points) const

Converts a set of Frenet points into Cartesian coordinates.

This function takes a set of points in Frenet coordinates and converts them into Cartesian coordinates based on the raceline data.

Parameters:

points – The vector of Frenet points to convert.

Returns:

The vector of Cartesian points.

std::pair<float, float> cartesian_to_frenet(const float &x, const float &y) const

Converts a Cartesian point into Frenet coordinates.

This function takes a Cartesian point and converts it into Frenet coordinates based on the raceline data.

Parameters:
  • x – The x-coordinate of the point.

  • y – The y-coordinate of the point.

Returns:

The Frenet coordinates of the point.

std::pair<float, float> cartesian_to_frenet(const std::pair<float, float> &points) const

Converts a single Cartesian point into Frenet coordinates.

This function takes a single Cartesian point and converts it into Frenet coordinates based on the raceline data.

Parameters:

points – The Cartesian point to convert, tuple of x and y.

Returns:

The Frenet coordinates of the point.

std::vector<std::pair<float, float>> cartesian_to_frenet(const std::vector<std::pair<float, float>> &points) const

Converts a set of Cartesian points into Frenet coordinates.

This function takes a set of Cartesian points and converts them into Frenet coordinates based on the raceline data.

Parameters:

points – The vector of tuple x,y to convert.

Returns:

The vector of Frenet points.

std::tuple<float, float, float, float, float, int> search_nearest_point_tdp_projected(const float &actual_x, const float &actual_y, const int &tdp)

Compute frenet coordinates of the car with respect to the path and the equivalent cartesian coordinate. It comprehends the computation of the index of the nearest point on the path. The tdp is considered.

Parameters:
  • actual_x – The x-coordinate of the car.

  • actual_y – The y-coordinate of the car.

  • tdp – The time delay parameter (int).

Returns:

std::tuple<float, float, float, float, int> A tuple containing:

  • current_x: The x-coordinate of the car (considering tdp)

  • current_y: The y-coordinate of the car (considering tdp)

  • s_euclidian[projected_index]: The frenet s coordinate (considering tdp)

  • distance_d: The frenet n coordinate (considering tdp)

  • heading[projected_index]: The heading angle of the car (considering tdp)

  • nearest_index: The index of the nearest point on the path (considering tdp)

std::tuple<float, float, int> search_look_ahead_point(const float &actual_x, const float &actual_y, const float &actual_v, const float &look_ahead_gain, const float &min_look_ahead_dist, float window_size_m = 0.0f)

Searches the look ahead point on the path considering car position and speed.

Parameters:
  • actual_x – The x-coordinate of the car.

  • actual_y – The y-coordinate of the car.

  • actual_v – The speed of the car.

  • look_ahead_gain – The look ahead gain.

  • min_look_ahead_dist – The minimum look ahead distance.

  • window_size_m – Search window (meters) around the last nearest index. 0 = full scan.

Returns:

Tuple with look_ahead_x, look_ahead_y, nearest_index.