mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-26 16:02:23 +03:00
following logic wasn't considering length of lead vehicle properly?
adjusted code a bit, but still seeing a violation
This commit is contained in:
parent
6bdb28cced
commit
17262063a1
@ -145,30 +145,32 @@ impl Car {
|
||||
assert!(self.id != other.id.as_car());
|
||||
assert!(current_dist_along < other.dist_along);
|
||||
let other_vehicle = other.vehicle.as_ref().unwrap();
|
||||
let dist_behind_other =
|
||||
dist_scanned_ahead + (other.dist_along - current_dist_along);
|
||||
let dist_behind_others_back = dist_scanned_ahead
|
||||
+ (other.dist_along - current_dist_along)
|
||||
- other_vehicle.length;
|
||||
// If our lookahead doesn't even hit the lead vehicle (plus following distance!!!), then ignore them.
|
||||
// TODO Maybe always consider them. We might just speed up.
|
||||
let total_scanning_dist =
|
||||
dist_scanned_ahead + dist_to_lookahead + other_vehicle.following_dist();
|
||||
if total_scanning_dist >= dist_behind_other {
|
||||
dist_scanned_ahead + dist_to_lookahead + kinematics::FOLLOWING_DISTANCE;
|
||||
if total_scanning_dist >= dist_behind_others_back {
|
||||
let accel = vehicle.accel_to_follow(
|
||||
self.speed,
|
||||
orig_speed_limit,
|
||||
other_vehicle,
|
||||
dist_behind_other,
|
||||
dist_behind_others_back,
|
||||
other.speed,
|
||||
)?;
|
||||
|
||||
if self.debug {
|
||||
debug!(
|
||||
" {} needs {} to not hit {}. Currently {} behind them",
|
||||
self.id, accel, other.id, dist_behind_other
|
||||
" {} needs {} to not hit {}. Currently {} behind their back",
|
||||
self.id, accel, other.id, dist_behind_others_back
|
||||
);
|
||||
}
|
||||
|
||||
constraints.push(accel);
|
||||
} else if self.debug {
|
||||
debug!(" {} is {} behind {}. Scanned ahead so far {} + lookahead dist {} + following dist {} = {} is less than that, so ignore them", self.id, dist_behind_other, other.id, dist_scanned_ahead, dist_to_lookahead, other_vehicle.following_dist(), total_scanning_dist);
|
||||
debug!(" {} is {} behind {}'s back. Scanned ahead so far {} + lookahead dist {} + following dist {} = {} is less than that, so ignore them", self.id, dist_behind_others_back, other.id, dist_scanned_ahead, dist_to_lookahead, kinematics::FOLLOWING_DISTANCE, total_scanning_dist);
|
||||
}
|
||||
}
|
||||
|
||||
@ -379,15 +381,15 @@ impl SimQueue {
|
||||
// assert here we're not squished together too much
|
||||
for slice in cars_queue.windows(2) {
|
||||
let ((dist1, c1), (dist2, c2)) = (slice[0], slice[1]);
|
||||
let following_dist = cars[&c1].vehicle.following_dist();
|
||||
if dist1 - dist2 < following_dist {
|
||||
let dist_apart = dist1 - dist2 - cars[&c1].vehicle.length;
|
||||
if dist_apart < kinematics::FOLLOWING_DISTANCE {
|
||||
let mut err = format!(
|
||||
"On {:?}, {} and {} are {} apart -- that's {} too close\n",
|
||||
id,
|
||||
c1,
|
||||
c2,
|
||||
dist1 - dist2,
|
||||
following_dist - (dist1 - dist2),
|
||||
dist_apart,
|
||||
kinematics::FOLLOWING_DISTANCE - dist_apart,
|
||||
);
|
||||
// TODO We used to have old_queue and could print more debug info. Meh.
|
||||
err.push_str(&format!("Queue ({}):\n", cars_queue.len()));
|
||||
@ -715,7 +717,7 @@ impl DrivingSimState {
|
||||
self.cars[&other].speed,
|
||||
other_vehicle.clamp_speed(map.get_parent(start_lane).get_speed_limit()),
|
||||
¶ms.vehicle,
|
||||
start_dist - other_dist,
|
||||
start_dist - other_dist - params.vehicle.length,
|
||||
0.0 * si::MPS,
|
||||
).unwrap();
|
||||
if accel_for_other_to_stop <= other_vehicle.max_deaccel {
|
||||
|
@ -36,7 +36,7 @@ const BUS_LENGTH: Distance = si::Meter {
|
||||
|
||||
// At all speeds (including at rest), cars must be at least this far apart, measured from front of
|
||||
// one car to the back of the other.
|
||||
const FOLLOWING_DISTANCE: Distance = si::Meter {
|
||||
pub const FOLLOWING_DISTANCE: Distance = si::Meter {
|
||||
value_unsafe: 1.0,
|
||||
_marker: std::marker::PhantomData,
|
||||
};
|
||||
@ -243,35 +243,23 @@ impl Vehicle {
|
||||
dist_at_constant_accel(self.max_deaccel, TIMESTEP, current_speed)
|
||||
}
|
||||
|
||||
// Relative to the front of the car
|
||||
pub fn following_dist(&self) -> Distance {
|
||||
self.length + FOLLOWING_DISTANCE
|
||||
}
|
||||
|
||||
pub fn accel_to_follow(
|
||||
&self,
|
||||
our_speed: Speed,
|
||||
our_speed_limit: Speed,
|
||||
other: &Vehicle,
|
||||
dist_behind_other: Distance,
|
||||
dist_behind_others_back: Distance,
|
||||
other_speed: Speed,
|
||||
) -> Result<Acceleration, Error> {
|
||||
/* A seemingly failed attempt at a simpler version:
|
||||
|
||||
// What if they slam on their brakes right now?
|
||||
let their_stopping_dist = other.stopping_distance(other.min_next_speed(other_speed));
|
||||
let worst_case_dist_away = dist_behind_other + their_stopping_dist;
|
||||
self.accel_to_stop_in_dist(our_speed, worst_case_dist_away)
|
||||
*/
|
||||
|
||||
let us_worst_dist = self.max_lookahead_dist(our_speed, our_speed_limit)?;
|
||||
let most_we_could_go = self.max_next_dist(our_speed, our_speed_limit)?;
|
||||
let least_they_could_go = other.min_next_dist(other_speed)?;
|
||||
|
||||
// TODO this optimizes for next tick, so we're playing it really
|
||||
// conservative here... will that make us fluctuate more?
|
||||
let projected_dist_from_them = dist_behind_other - most_we_could_go + least_they_could_go;
|
||||
let desired_dist_btwn = us_worst_dist + other.following_dist();
|
||||
let projected_dist_from_them =
|
||||
dist_behind_others_back - most_we_could_go + least_they_could_go;
|
||||
let desired_dist_btwn = us_worst_dist + FOLLOWING_DISTANCE;
|
||||
|
||||
// Positive = speed up, zero = go their speed, negative = slow down
|
||||
let delta_dist = projected_dist_from_them - desired_dist_btwn;
|
||||
|
Loading…
Reference in New Issue
Block a user