fix bug generating too near waypoints

This commit is contained in:
Joel Moriana 2021-07-30 00:49:10 +02:00 committed by bernat
parent c451c3cb8a
commit c84747676e
2 changed files with 16 additions and 4 deletions

View File

@ -94,9 +94,15 @@ namespace traffic_manager {
out_file.write(reinterpret_cast<const char *>(&total), sizeof(uint32_t)); out_file.write(reinterpret_cast<const char *>(&total), sizeof(uint32_t));
// write simple waypoints // write simple waypoints
std::unordered_set<uint64_t> used_ids;
for (auto& wp: dense_topology) { for (auto& wp: dense_topology) {
if (used_ids.find(wp->GetId()) != used_ids.end()) {
log_error("Could not generate the binary file. There are repeated waypoints");
}
CachedSimpleWaypoint cached_wp(wp); CachedSimpleWaypoint cached_wp(wp);
cached_wp.Write(out_file); cached_wp.Write(out_file);
used_ids.insert(wp->GetId());
} }
out_file.close(); out_file.close();
@ -252,15 +258,15 @@ namespace traffic_manager {
// Adding more waypoints if the angle is too tight or if they are too distant. // Adding more waypoints if the angle is too tight or if they are too distant.
for (std::size_t i = 0; i < segment_waypoints.size() - 1; ++i) { for (std::size_t i = 0; i < segment_waypoints.size() - 1; ++i) {
float distance = distance_squared(segment_waypoints.at(i)->GetLocation(), segment_waypoints.at(i+1)->GetLocation()); double distance = std::abs(segment_waypoints.at(i)->GetWaypoint()->GetDistance() - segment_waypoints.at(i+1)->GetWaypoint()->GetDistance());
double angle = wpt_angle(segment_waypoints.at(i)->GetTransform().rotation.GetForwardVector(), segment_waypoints.at(i+1)->GetTransform().rotation.GetForwardVector()); double angle = wpt_angle(segment_waypoints.at(i)->GetTransform().rotation.GetForwardVector(), segment_waypoints.at(i+1)->GetTransform().rotation.GetForwardVector());
int16_t angle_splits = static_cast<int16_t>(angle/MAX_WPT_RADIANS); int16_t angle_splits = static_cast<int16_t>(angle/MAX_WPT_RADIANS);
int16_t distance_splits = static_cast<int16_t>(distance/MAX_WPT_DISTANCE); int16_t distance_splits = static_cast<int16_t>((distance*distance)/MAX_WPT_DISTANCE);
auto max_splits = max(angle_splits, distance_splits); auto max_splits = max(angle_splits, distance_splits);
if (max_splits >= 1) { if (max_splits >= 1) {
// Compute how many waypoints do we need to generate. // Compute how many waypoints do we need to generate.
for (uint16_t j = 0; j < max_splits; ++j) { for (uint16_t j = 0; j < max_splits; ++j) {
auto next_waypoints = segment_waypoints.at(i)->GetWaypoint()->GetNext(std::sqrt(distance)/(max_splits+1)); auto next_waypoints = segment_waypoints.at(i)->GetWaypoint()->GetNext(distance/(max_splits+1));
if (next_waypoints.size() != 0) { if (next_waypoints.size() != 0) {
auto new_waypoint = next_waypoints.front(); auto new_waypoint = next_waypoints.front();
i++; i++;

View File

@ -113,7 +113,13 @@ void TrafficManagerLocal::SetupLocalMap() {
auto files = episode_proxy.Lock()->GetRequiredFiles("TM"); auto files = episode_proxy.Lock()->GetRequiredFiles("TM");
if (!files.empty()) { if (!files.empty()) {
local_map->Load(episode_proxy.Lock()->GetCacheFile(files[0], true)); auto content = episode_proxy.Lock()->GetCacheFile(files[0], true);
if (content.size() != 0) {
local_map->Load(content);
} else {
log_warning("No InMemoryMap cache found. Setting up local map. This may take a while...");
local_map->SetUp();
}
} else { } else {
log_warning("No InMemoryMap cache found. Setting up local map. This may take a while..."); log_warning("No InMemoryMap cache found. Setting up local map. This may take a while...");
local_map->SetUp(); local_map->SetUp();