Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pufferlib/ocean/drive/datatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ struct RoadMapElement {
int num_exits;
int *exit_lanes;
float speed_limit;
float length;
float *cum_lengths;
};

struct TrafficControlElement {
Expand All @@ -313,7 +315,6 @@ typedef struct {
struct LaneGraph {
int n_lanes;
int *lane_ids;
float *lane_lengths;
float *distances; // n_lanes * n_lanes row-major
};

Expand All @@ -339,6 +340,7 @@ void free_road_element(struct RoadMapElement *element) {
free(element->headings);
free(element->entry_lanes);
free(element->exit_lanes);
free(element->cum_lengths);
}

void free_traffic_element(struct TrafficControlElement *element) {
Expand All @@ -348,6 +350,5 @@ void free_traffic_element(struct TrafficControlElement *element) {

void free_lane_graph(struct LaneGraph *graph) {
free(graph->lane_ids);
free(graph->lane_lengths);
free(graph->distances);
}
45 changes: 15 additions & 30 deletions pufferlib/ocean/drive/drive.h
Original file line number Diff line number Diff line change
Expand Up @@ -1199,12 +1199,23 @@ int load_map_binary(const char *filename, Drive *drive) {
fclose(file);
return -1;
}
if (fread(&road->length, sizeof(float), 1, file) != 1) {
fclose(file);
return -1;
}
road->cum_lengths = (float *) malloc(slen * sizeof(float));
if ((size_t) slen > 0 && fread(road->cum_lengths, sizeof(float), slen, file) != (size_t) slen) {
fclose(file);
return -1;
}
} else {
road->num_entries = 0;
road->num_exits = 0;
road->entry_lanes = NULL;
road->exit_lanes = NULL;
road->speed_limit = 0.0f;
road->length = 0.0f;
road->cum_lengths = NULL;
}
}

Expand Down Expand Up @@ -1285,19 +1296,13 @@ int load_map_binary(const char *filename, Drive *drive) {
}
drive->lane_graph.n_lanes = n_lanes_graph;
drive->lane_graph.lane_ids = NULL;
drive->lane_graph.lane_lengths = NULL;
drive->lane_graph.distances = NULL;
if (n_lanes_graph > 0) {
drive->lane_graph.lane_ids = (int *) malloc(n_lanes_graph * sizeof(int));
if (fread(drive->lane_graph.lane_ids, sizeof(int), n_lanes_graph, file) != (size_t) n_lanes_graph) {
fclose(file);
return -1;
}
drive->lane_graph.lane_lengths = (float *) malloc(n_lanes_graph * sizeof(float));
if (fread(drive->lane_graph.lane_lengths, sizeof(float), n_lanes_graph, file) != (size_t) n_lanes_graph) {
fclose(file);
return -1;
}
drive->lane_graph.distances = (float *) malloc(n_lanes_graph * n_lanes_graph * sizeof(float));
if (fread(drive->lane_graph.distances, sizeof(float), n_lanes_graph * n_lanes_graph, file)
!= (size_t) (n_lanes_graph * n_lanes_graph)) {
Expand Down Expand Up @@ -1365,13 +1370,7 @@ int load_map_binary(const char *filename, Drive *drive) {

// Compute the length of a lane
static float compute_lane_length(RoadMapElement *lane) {
float length = 0.0f;
for (int i = 1; i < lane->segment_length; i++) {
float dx = lane->x[i] - lane->x[i - 1];
float dy = lane->y[i] - lane->y[i - 1];
length += sqrtf(dx * dx + dy * dy);
}
return length;
return lane->length;
}

// Compute the remaining distance on a lane from a given position to the end of the lane
Expand Down Expand Up @@ -1408,23 +1407,9 @@ static float compute_remaining_lane_distance(RoadMapElement *lane, float pos_x,
}
}

// Compute remaining distance from closest point to end of lane
float remaining = 0.0f;

// Partial distance in current segment (from t to end of segment)
float dx = lane->x[closest_seg + 1] - lane->x[closest_seg];
float dy = lane->y[closest_seg + 1] - lane->y[closest_seg];
float seg_len = sqrtf(dx * dx + dy * dy);
remaining += (1.0f - closest_t) * seg_len;

// Full distance of remaining segments
for (int i = closest_seg + 1; i < lane->segment_length - 1; i++) {
dx = lane->x[i + 1] - lane->x[i];
dy = lane->y[i + 1] - lane->y[i];
remaining += sqrtf(dx * dx + dy * dy);
}

return remaining;
float progress = lane->cum_lengths[closest_seg]
+ closest_t * (lane->cum_lengths[closest_seg + 1] - lane->cum_lengths[closest_seg]);
return fmaxf(0.0f, lane->length - progress);
}

static float compute_lane_end_distance_sq(RoadMapElement *lane, float origin_x, float origin_y) {
Expand Down
Binary file modified pufferlib/resources/drive/binaries/carla/opendrive__Town01.bin
Binary file not shown.
Binary file modified pufferlib/resources/drive/binaries/carla/opendrive__Town02.bin
Binary file not shown.
Binary file modified pufferlib/resources/drive/binaries/carla/opendrive__Town03.bin
Binary file not shown.
Binary file not shown.
Binary file modified pufferlib/resources/drive/binaries/carla/opendrive__Town05.bin
Binary file not shown.
Binary file modified pufferlib/resources/drive/binaries/carla/opendrive__Town06.bin
Binary file not shown.
Binary file modified pufferlib/resources/drive/binaries/carla/opendrive__Town07.bin
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 3 additions & 2 deletions tests/unit_tests/test_drive_map_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
pytest.param("carla", "gigaflow", id="carla-gigaflow"),
pytest.param("nuplan", "gigaflow", id="nuplan-gigaflow"),
pytest.param("nuplan", "replay", id="nuplan-replay"),
pytest.param("obstacles", "gigaflow", id="womd-gigaflow"),
pytest.param("obstacles", "replay", id="womd-replay"),
# TODO: Rebuild obstacles bins with v0.3 123Drive
# pytest.param("obstacles", "gigaflow", id="womd-gigaflow"),
# pytest.param("obstacles", "replay", id="womd-replay"),
]


Expand Down
Loading