-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathutils.h
44 lines (35 loc) · 1.11 KB
/
utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef UTILS_H
#define UTILS_H
#include <math.h>
#include <limits>
#include <vector>
#include "json.hpp"
const double pi = M_PI;
const double lane_width = 4.0; // width of a lane (m)
const double safety_margin = 20.0; // distance to keep from other cars (m)
const double max_safe_speed = 49.5; // max reference speed in the limit (mph)
struct Vehicle {
double d;
double vx, vy;
double speed;
double s;
Vehicle(nlohmann::json sensor_fusion) {
this->vx = sensor_fusion[3];
this->vy = sensor_fusion[4];
this->s = sensor_fusion[5];
this->d = sensor_fusion[6];
this->speed = sqrt(vx * vx + vy * vy);
}
};
// For converting back and forth between radians and degrees.
double deg2rad(double x) { return x * pi / 180; }
double rad2deg(double x) { return x * 180 / pi; }
// Calculate the Euclidea Distance between two points
double distance(double x1, double y1, double x2, double y2) {
return sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
}
// Check if a vehicle is is a certain lane
bool is_in_lane(double d, int lane) {
return (d > lane_width * lane) && (d < lane_width * lane + lane_width);
}
#endif