40TEST(agents_types, road_option_values_match_python) {
41 EXPECT_EQ(
static_cast<int>(RoadOption::Void), -1);
42 EXPECT_EQ(
static_cast<int>(RoadOption::Left), 1);
43 EXPECT_EQ(
static_cast<int>(RoadOption::Right), 2);
44 EXPECT_EQ(
static_cast<int>(RoadOption::Straight), 3);
45 EXPECT_EQ(
static_cast<int>(RoadOption::LaneFollow), 4);
46 EXPECT_EQ(
static_cast<int>(RoadOption::ChangeLaneLeft), 5);
47 EXPECT_EQ(
static_cast<int>(RoadOption::ChangeLaneRight), 6);
50TEST(agents_types, behavior_cautious_matches_python) {
52 EXPECT_FLOAT_EQ(p.max_speed, 40.0f);
53 EXPECT_FLOAT_EQ(p.speed_lim_dist, 6.0f);
54 EXPECT_FLOAT_EQ(p.speed_decrease, 12.0f);
55 EXPECT_FLOAT_EQ(p.safety_time, 3.0f);
56 EXPECT_FLOAT_EQ(p.min_proximity_threshold, 12.0f);
57 EXPECT_FLOAT_EQ(p.braking_distance, 6.0f);
58 EXPECT_EQ (p.tailgate_counter, 0);
61TEST(agents_types, behavior_normal_matches_python) {
63 EXPECT_FLOAT_EQ(p.max_speed, 50.0f);
64 EXPECT_FLOAT_EQ(p.speed_lim_dist, 3.0f);
65 EXPECT_FLOAT_EQ(p.speed_decrease, 10.0f);
66 EXPECT_FLOAT_EQ(p.safety_time, 3.0f);
67 EXPECT_FLOAT_EQ(p.min_proximity_threshold, 10.0f);
68 EXPECT_FLOAT_EQ(p.braking_distance, 5.0f);
69 EXPECT_EQ (p.tailgate_counter, 0);
72TEST(agents_types, behavior_aggressive_matches_python) {
74 EXPECT_FLOAT_EQ(p.max_speed, 70.0f);
75 EXPECT_FLOAT_EQ(p.speed_lim_dist, 1.0f);
76 EXPECT_FLOAT_EQ(p.speed_decrease, 8.0f);
77 EXPECT_FLOAT_EQ(p.safety_time, 3.0f);
78 EXPECT_FLOAT_EQ(p.min_proximity_threshold, 8.0f);
79 EXPECT_FLOAT_EQ(p.braking_distance, 4.0f);
82 EXPECT_EQ (p.tailgate_counter, -1);
89TEST(agents_misc, positive_clamps_at_zero) {
90 EXPECT_FLOAT_EQ(
Positive(-3.5f), 0.0f);
91 EXPECT_FLOAT_EQ(
Positive(0.0f), 0.0f);
92 EXPECT_FLOAT_EQ(
Positive(2.5f), 2.5f);
95TEST(agents_misc, compute_distance_basic) {
106TEST(agents_misc, unit_vector_is_normalized) {
111 EXPECT_NEAR(u[0], 0.6f, 1e-3f);
112 EXPECT_NEAR(u[1], 0.8f, 1e-3f);
113 EXPECT_NEAR(u[2], 0.0f, 1e-3f);
115 const float mag = std::sqrt(u[0]*u[0] + u[1]*u[1] + u[2]*u[2]);
116 EXPECT_NEAR(mag, 1.0f, 1e-3f);
119TEST(agents_misc, is_within_distance_no_angle_filter) {
128TEST(agents_misc, is_within_distance_too_close_returns_true) {
134 EXPECT_TRUE(
IsWithinDistance(overlap, ref, 0.001f, std::make_pair(0.0f, 90.0f)));
137TEST(agents_misc, is_within_distance_with_forward_arc_filter) {
146 EXPECT_TRUE (
IsWithinDistance(front_diag, ref, 10.0f, std::make_pair(0.0f, 90.0f)));
147 EXPECT_FALSE(
IsWithinDistance(behind, ref, 10.0f, std::make_pair(0.0f, 90.0f)));
152 EXPECT_FALSE(
IsWithinDistance(front_axial, ref, 10.0f, std::make_pair(0.0f, 90.0f)));
155TEST(agents_misc, compute_magnitude_angle_zero_yaw) {
160 EXPECT_NEAR(mag, 10.0f, 1e-3f);
161 EXPECT_NEAR(angle, 0.0f, 1e-2f);
164TEST(agents_misc, compute_magnitude_angle_perpendicular) {
169 EXPECT_NEAR(mag, 5.0f, 1e-3f);
170 EXPECT_NEAR(angle, 90.0f, 1e-2f);
178TEST(agents_factories, local_planner_default_options) {
181 EXPECT_FLOAT_EQ(opt.dt, 1.0f / 20.0f);
182 EXPECT_FLOAT_EQ(opt.target_speed, 20.0f);
183 EXPECT_FLOAT_EQ(opt.sampling_radius, 2.0f);
184 EXPECT_FLOAT_EQ(opt.max_throttle, 0.75f);
185 EXPECT_FLOAT_EQ(opt.max_brake, 0.30f);
186 EXPECT_FLOAT_EQ(opt.max_steering, 0.80f);
187 EXPECT_FLOAT_EQ(opt.offset, 0.0f);
188 EXPECT_FLOAT_EQ(opt.base_min_distance, 3.0f);
189 EXPECT_FLOAT_EQ(opt.distance_ratio, 0.5f);
190 EXPECT_FALSE (opt.follow_speed_limits);
193 EXPECT_FLOAT_EQ(opt.lateral.K_P, 1.95f);
194 EXPECT_FLOAT_EQ(opt.lateral.K_I, 0.05f);
195 EXPECT_FLOAT_EQ(opt.lateral.K_D, 0.20f);
196 EXPECT_FLOAT_EQ(opt.longitudinal.K_P, 1.50f);
197 EXPECT_FLOAT_EQ(opt.longitudinal.K_I, 0.05f);
198 EXPECT_FLOAT_EQ(opt.longitudinal.K_D, 0.20f);
201TEST(agents_factories, basic_agent_default_options_inherits_local_planner) {
204 EXPECT_FALSE(opt.ignore_traffic_lights);
205 EXPECT_FALSE(opt.ignore_stop_signs);
206 EXPECT_FALSE(opt.ignore_vehicles);
207 EXPECT_FALSE(opt.use_bbs_detection);
208 EXPECT_FLOAT_EQ(opt.sampling_resolution, 2.0f);
209 EXPECT_FLOAT_EQ(opt.base_tlight_threshold, 5.0f);
210 EXPECT_FLOAT_EQ(opt.base_vehicle_threshold, 5.0f);
211 EXPECT_FLOAT_EQ(opt.detection_speed_ratio, 1.0f);
212 EXPECT_FLOAT_EQ(opt.max_brake, 0.6f);
214 EXPECT_FLOAT_EQ(opt.target_speed, 20.0f);
215 EXPECT_FLOAT_EQ(opt.dt, 1.0f / 20.0f);
218TEST(agents_factories, constant_velocity_default_options) {
220 EXPECT_FALSE(opt.use_basic_behavior);
221 EXPECT_TRUE (std::isinf(opt.restart_time));
223 EXPECT_FALSE(opt.ignore_traffic_lights);
224 EXPECT_FLOAT_EQ(opt.max_brake, 0.6f);
233TEST(agents_api, surface_pins) {
235 static_assert(std::is_same_v<PlanItem,
236 std::pair<carla::SharedPtr<carla::client::Waypoint>,
RoadOption>>,
237 "LocalPlanner::PlanItem must be (Waypoint, RoadOption)");
240 static_assert(std::is_same_v<RouteItem,
241 std::pair<carla::SharedPtr<carla::client::Waypoint>,
RoadOption>>,
242 "GlobalRoutePlanner::RouteItem must be (Waypoint, RoadOption)");
245 static_assert(
static_cast<int>(Behavior::Cautious) !=
static_cast<int>(Behavior::Normal),
246 "BehaviorAgent::Behavior values must be distinct");
247 static_assert(
static_cast<int>(Behavior::Normal) !=
static_cast<int>(Behavior::Aggressive),
248 "BehaviorAgent::Behavior values must be distinct");
251 static_assert(std::is_base_of_v<LocalPlanner::Options, BasicAgent::Options>,
252 "BasicAgent::Options must inherit LocalPlanner::Options");
256 "ConstantOptions must inherit BasicAgent::Options");
259 static_assert(std::is_base_of_v<BasicAgent, BehaviorAgent>,
260 "BehaviorAgent must inherit BasicAgent");
261 static_assert(std::is_base_of_v<BasicAgent, ConstantVelocityAgent>,
262 "ConstantVelocityAgent must inherit BasicAgent");
266 static_assert(std::has_virtual_destructor_v<BasicAgent>,
267 "BasicAgent must have a virtual destructor");
static Options DefaultOptions()
Out-of-line default factory; see LocalPlanner::DefaultOptions().
static ConstantOptions DefaultConstantOptions()
Out-of-line default factory; see LocalPlanner::DefaultOptions().
std::pair< SharedPtr< client::Waypoint >, RoadOption > RouteItem
static Options DefaultOptions()
Construct a LocalPlanner.
std::pair< SharedPtr< client::Waypoint >, RoadOption > PlanItem
Euler angles of a rotation in CARLA's / Unreal's left-handed frame: x forward, y right,...
bool IsWithinDistance(const geom::Transform &target, const geom::Transform &reference, float max_distance, std::optional< std::pair< float, float > > angle_interval)
Returns true when target is within max_distance of reference.
RoadOption
Topological direction emitted by the planners.
float ComputeDistance(const geom::Location &a, const geom::Location &b)
Euclidean distance between two locations (matches numpy's regularised version that adds an epsilon to...
float Positive(float v)
Clamp v at zero. Inline because it's tiny.
std::pair< float, float > ComputeMagnitudeAngle(const geom::Location &target, const geom::Location ¤t, float orientation_deg)
Returns the (distance, angle in degrees) from current to target relative to a forward orientation ori...
std::array< float, 3 > UnitVector(const geom::Location &a, const geom::Location &b)
Unit vector going from a to b, including the z component.
static constexpr BehaviorParameters Aggressive()
static constexpr BehaviorParameters Cautious()
static constexpr BehaviorParameters Normal()
TEST(agents_types, road_option_values_match_python)