Skip to content

Commit

Permalink
traffic history issues (#769)
Browse files Browse the repository at this point in the history
* fix bug causing sim_time between queries to miss due to float precision.
also gave traffic history vehicles an id that would allow them to be colored correctly.

* update from review (magic numbers)
  • Loading branch information
sah-huawei authored Apr 17, 2021
1 parent 8b8d705 commit 8161da4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion smarts/core/traffic_history_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def step(self, provider_actions, dt, elapsed_sim_time) -> ProviderState:
default_dims = VEHICLE_CONFIGS[vehicle_type].dimensions
vehicles.append(
VehicleState(
vehicle_id=v_id,
vehicle_id=f"social-agent-history-{v_id}",
vehicle_type=vehicle_type,
pose=Pose.from_center(
[
Expand Down
13 changes: 9 additions & 4 deletions smarts/sstudio/genhistories.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@


METERS_PER_FOOT = 0.3048
DEFAULT_LANE_WIDTH = 3.7 # a typical US highway lane is 12ft ~= 3.7m wide


class _TrajectoryDataset:
Expand All @@ -41,7 +42,7 @@ def __init__(self, dataset_spec, output):
self.check_dataset_spec(dataset_spec)
self._output = output
self._path = dataset_spec["input_path"]
real_lane_width_m = dataset_spec.get("real_lane_width_m", 3.7)
real_lane_width_m = dataset_spec.get("real_lane_width_m", DEFAULT_LANE_WIDTH)
lane_width = dataset_spec.get("map_net", {}).get(
"lane_width", real_lane_width_m
)
Expand Down Expand Up @@ -114,7 +115,8 @@ def _create_tables(self, dbconxn):
dbconxn.commit()
ccur.close()

def create_output(self):
def create_output(self, time_precision=3):
""" time_precision is limit for digits after decimal for sim_time (3 is milisecond precision) """
dbconxn = sqlite3.connect(self._output)

self._log.debug("creating tables...")
Expand Down Expand Up @@ -150,7 +152,10 @@ def create_output(self):
traj_args = (
vid,
# time units are in milliseconds for both NGSIM and Interaction datasets, convert to secs
round(float(self.column_val_in_row(row, "sim_time")) / 1000, 3),
round(
float(self.column_val_in_row(row, "sim_time")) / 1000,
time_precision,
),
float(self.column_val_in_row(row, "position_x")) * self.scale,
float(self.column_val_in_row(row, "position_y")) * self.scale,
float(self.column_val_in_row(row, "heading_rad")),
Expand All @@ -168,7 +173,7 @@ def create_output(self):
self._log.debug("shifting sim_times..")
mcur = dbconxn.cursor()
mcur.execute(
"UPDATE Trajectory SET sim_time = sim_time - (SELECT min(sim_time) FROM Trajectory)"
f"UPDATE Trajectory SET sim_time = round(sim_time - (SELECT min(sim_time) FROM Trajectory), {time_precision})"
)
mcur.close()
dbconxn.commit()
Expand Down

0 comments on commit 8161da4

Please sign in to comment.