Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid calling out "keep left/right" when passing an exit #3349

Merged
merged 29 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
416369c
trying a diff angle for fork
ktatterso Oct 7, 2021
f5c4a70
Trying something
ktatterso Oct 14, 2021
a0d9a10
Merge remote-tracking branch 'origin/master' into fork-tweak
ktatterso Oct 14, 2021
3a662d1
f
ktatterso Oct 14, 2021
12be032
stuff
ktatterso Oct 19, 2021
4348494
trying something
ktatterso Oct 22, 2021
ddbc402
Merge remote-tracking branch 'origin/master' into fork-tweak
ktatterso Oct 22, 2021
bc326a4
safer
ktatterso Oct 25, 2021
cf6529c
Merge remote-tracking branch 'origin/master' into fork-tweak
ktatterso Oct 26, 2021
312a8cd
comments
ktatterso Oct 26, 2021
c7bf7f7
Merge remote-tracking branch 'origin/master' into fork-tweak
ktatterso Oct 29, 2021
0f1eef9
var rename
ktatterso Oct 29, 2021
bc77480
latest, tests are a wip
ktatterso Nov 1, 2021
c867ca5
Merge remote-tracking branch 'origin/master' into fork-tweak
ktatterso Nov 1, 2021
d2a4027
test updates
ktatterso Nov 1, 2021
54de0e9
tighter, undoing straight nonsense
ktatterso Nov 2, 2021
c982947
format
ktatterso Nov 2, 2021
5aafb68
more testing
ktatterso Nov 2, 2021
ff1f794
touch ups
ktatterso Nov 2, 2021
ab24178
format for new test logic
ktatterso Nov 2, 2021
09d25a6
changelog
ktatterso Nov 2, 2021
3a70436
comment
ktatterso Nov 2, 2021
39ff821
Some fixes and new tests to back up fixes
ktatterso Nov 4, 2021
ec96dee
Merge remote-tracking branch 'origin/master' into fork-tweak
ktatterso Nov 4, 2021
1a8ca2b
format
ktatterso Nov 4, 2021
9768af3
fixing test case
ktatterso Nov 4, 2021
dbc7a5f
setting tol to 30
ktatterso Nov 5, 2021
ef0074d
dialing in the deceleration lane length equation
ktatterso Nov 8, 2021
286f584
comment
ktatterso Nov 9, 2021
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
Prev Previous commit
Next Next commit
latest, tests are a wip
  • Loading branch information
ktatterso committed Nov 1, 2021
commit bc7748085774c84575f03ea436990d86f28afa1e
28 changes: 21 additions & 7 deletions src/odin/maneuversbuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2258,6 +2258,11 @@ float get_deceleration_lane_length(float speed_kph) {
return 0.122;
}

// This is a new idea... see usage.
bool is_nearly_straight(uint32_t turn_degree) {
return ((turn_degree > 357) || (turn_degree < 3));
}

bool ManeuversBuilder::IsFork(int node_index,
EnhancedTripLeg_Edge* prev_edge,
EnhancedTripLeg_Edge* curr_edge) const {
Expand Down Expand Up @@ -2384,7 +2389,9 @@ bool ManeuversBuilder::IsFork(int node_index,
// an exit than a highway bifurcation.
int delta = 1;
auto prev_at_delta = trip_path->GetPrevEdge(node_index, delta);
float deceleration_lane_length_km = get_deceleration_lane_length(prev_at_delta->default_speed());
float kt = prev_at_delta->speed();
float deceleration_lane_length_km =
get_deceleration_lane_length(prev_at_delta->default_speed());
float agg_lane_length_km = prev_at_delta->length_km();
while (agg_lane_length_km < deceleration_lane_length_km) {
delta++;
Expand Down Expand Up @@ -2412,12 +2419,19 @@ bool ManeuversBuilder::IsFork(int node_index,

if (prev_edge->IsHighway() &&
((curr_edge->IsHighway() && (xedge->use() == TripLeg_Use_kRampUse)) ||
(xedge->IsHighway() && curr_edge->IsRampUse())) &&
has_lane_bifurcation(trip_path_, node_index, prev_edge, curr_edge, xedge) &&
prev_edge->IsForkForward(
GetTurnDegree(prev_edge->end_heading(), curr_edge->begin_heading())) &&
prev_edge->IsForkForward(GetTurnDegree(prev_edge->end_heading(), xedge->begin_heading()))) {
return true;
(xedge->IsHighway() && curr_edge->IsRampUse()))) {

// If the ramp is actually a straight, announce the turn
if (is_nearly_straight(GetTurnDegree(prev_edge->end_heading(), xedge->begin_heading()))) {
return true;
}

if (has_lane_bifurcation(trip_path_, node_index, prev_edge, curr_edge, xedge) &&
prev_edge->IsForkForward(
GetTurnDegree(prev_edge->end_heading(), curr_edge->begin_heading())) &&
prev_edge->IsForkForward(GetTurnDegree(prev_edge->end_heading(), xedge->begin_heading()))) {
return true;
}
}
}

Expand Down
136 changes: 136 additions & 0 deletions test/gurka/test_forks.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#include "gurka.h"
#include "test.h"
#include <gtest/gtest.h>

#if !defined(VALHALLA_SOURCE_DIR)
#define VALHALLA_SOURCE_DIR
#endif

using namespace valhalla;

//=======================================================================================
class ForkTest : public ::testing::Test {
protected:
static gurka::map map;
static std::shared_ptr<baldr::GraphReader> reader;

static void SetUpTestSuite() {
constexpr double gridsize = 10;

const std::string ascii_map = R"(
A-------B--------------------C----------------------------------------------------------D
E
F
)";
const gurka::ways ways =
{// we start out with two lanes
{"AB",
{{"highway", "motorway"},
{"oneway", "yes"},
{"lanes", "2"},
{"name", "A92"},
{"maxspeed", "120"}}},
// BC is three lanes because it "grew" a deceleration lane. length = 200 m
{"BC",
{{"highway", "motorway"},
{"oneway", "yes"},
{"lanes", "3"},
{"name", "A92"},
{"maxspeed", "120"}}},
// now back to two lanes
{"CD",
{{"highway", "motorway"},
{"oneway", "yes"},
{"lanes", "2"},
{"name", "A92"},
{"maxspeed", "120"}}},
// this ramp forms a small angle ~15 deg
{"CE",
{{"highway", "motorway_link"}, {"oneway", "yes"}, {"lanes", "2"}, {"name", "A92 link"}}},
{"EF",
{{"highway", "motorway_link"}, {"oneway", "yes"}, {"lanes", "2"}, {"name", "A92 link"}}}};

const gurka::nodes nodes;
const auto layout = gurka::detail::map_to_coordinates(ascii_map, gridsize);
map = gurka::buildtiles(layout, ways, nodes, {}, "test/data/ForkTest", {});
reader = test::make_clean_graphreader(map.config.get_child("mjolnir"));
}
};

std::shared_ptr<baldr::GraphReader> ForkTest::reader;
gurka::map ForkTest::map = {};

//------------------------------------------------------------------
TEST_F(ForkTest, test) {
auto result = gurka::do_action(valhalla::Options::route, map, {"A", "D"}, "auto");

// TODO: should not announce stay left since we detect a deceleration lane
for (const auto& leg : result.directions().routes(0).legs()) {
for (const auto& maneuver : leg.maneuver()) {
std::cout << maneuver.text_instruction() << "\n";
}
}
}

//=======================================================================================
class ForkTest2 : public ::testing::Test {
protected:
static gurka::map map;
static std::shared_ptr<baldr::GraphReader> reader;

static void SetUpTestSuite() {
constexpr double gridsize = 10;

const std::string ascii_map = R"(
A-------B--------------------C----------------------------------------------------------D
E
F
)";
const gurka::ways ways =
{// we start out with two lanes
{"AB",
{{"highway", "motorway"},
{"oneway", "yes"},
{"lanes", "2"},
{"name", "D4"},
{"maxspeed", "120"}}},
// BC is three lanes because it "grew" a deceleration lane. length = 200 m
{"BC",
{{"highway", "motorway"},
{"oneway", "yes"},
{"lanes", "3"},
{"name", "D4"},
{"maxspeed", "120"}}},
// now back to two lanes - but wait this is a different highway. ramp forms a small angle ~15
// deg
{"CD",
{{"highway", "motorway_link"},
{"oneway", "yes"},
{"lanes", "2"},
{"name", "D2"},
{"maxspeed", "120"}}},
// this is the continuation of D4
{"CE", {{"highway", "motorway"}, {"oneway", "yes"}, {"lanes", "2"}, {"name", "D4"}}},
{"EF", {{"highway", "motorway"}, {"oneway", "yes"}, {"lanes", "2"}, {"name", "D4"}}}};

const gurka::nodes nodes;
const auto layout = gurka::detail::map_to_coordinates(ascii_map, gridsize);
map = gurka::buildtiles(layout, ways, nodes, {}, "test/data/ForkTest", {});
reader = test::make_clean_graphreader(map.config.get_child("mjolnir"));
}
};

std::shared_ptr<baldr::GraphReader> ForkTest2::reader;
gurka::map ForkTest2::map = {};

//------------------------------------------------------------------
TEST_F(ForkTest2, test) {
auto result = gurka::do_action(valhalla::Options::route, map, {"A", "F"}, "auto");

// TODO: since the "ramp" goes straight, announce the "stay right"
for (const auto& leg : result.directions().routes(0).legs()) {
for (const auto& maneuver : leg.maneuver()) {
std::cout << maneuver.text_instruction() << "\n";
}
}
}