Skip to content

Commit

Permalink
rework voicehints #723
Browse files Browse the repository at this point in the history
  • Loading branch information
afischerdev committed Sep 5, 2024
1 parent 7b70cc5 commit 7ead35e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
5 changes: 3 additions & 2 deletions brouter-core/src/main/java/btools/router/VoiceHint.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public float getTime() {
}

float angle = Float.MAX_VALUE;
float lowerBadWayAngle = -181;
float higherBadWayAngle = 181;

boolean turnAngleConsumed;
boolean needsRealTurn;
int maxBadPrio = -1;
Expand Down Expand Up @@ -470,8 +473,6 @@ public String getCruiserMessageString() {
}

public void calcCommand() {
float lowerBadWayAngle = -181;
float higherBadWayAngle = 181;
if (badWays != null) {
for (MessageData badWay : badWays) {
if (badWay.isBadOneway()) {
Expand Down
42 changes: 28 additions & 14 deletions brouter-core/src/main/java/btools/router/VoiceHintProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
public final class VoiceHintProcessor {

double SIGNIFICANT_ANGLE = 22.5;
double INTERNAL_CATCHING_RANGE = 2.;
double INTERNAL_CATCHING_RANGE_NEAR = 2.;
double INTERNAL_CATCHING_RANGE_WIDE = 10.;

// private double catchingRange; // range to catch angles and merge turns
private boolean explicitRoundabouts;
Expand All @@ -23,10 +24,10 @@ public VoiceHintProcessor(double catchingRange, boolean explicitRoundabouts, int
this.transportMode = transportMode;
}

private float sumNonConsumedWithinCatchingRange(List<VoiceHint> inputs, int offset) {
private float sumNonConsumedWithinCatchingRange(List<VoiceHint> inputs, int offset, double range) {
double distance = 0.;
float angle = 0.f;
while (offset >= 0 && distance < INTERNAL_CATCHING_RANGE) {
while (offset >= 0 && distance < range) {
VoiceHint input = inputs.get(offset--);
if (input.turnAngleConsumed) {
break;
Expand Down Expand Up @@ -82,7 +83,7 @@ public List<VoiceHint> process(List<VoiceHint> inputs) {

if (explicitRoundabouts && input.oldWay.isRoundabout()) {
if (roundaboudStartIdx == -1) roundaboudStartIdx = hintIdx;
roundAboutTurnAngle += sumNonConsumedWithinCatchingRange(inputs, hintIdx);
roundAboutTurnAngle += sumNonConsumedWithinCatchingRange(inputs, hintIdx, INTERNAL_CATCHING_RANGE_NEAR);
if (roundaboudStartIdx == hintIdx) {
if (input.badWays != null) {
// remove goodWay
Expand Down Expand Up @@ -171,10 +172,12 @@ public List<VoiceHint> process(List<VoiceHint> inputs) {
}

if (badWay.isBadOneway()) {
if (minAbsAngeRaw == 180f) minAbsAngeRaw = turnAngle; // disable hasSomethingMoreStraight
continue; // ignore wrong oneways
}

if (Math.abs(badTurn) - Math.abs(turnAngle) > 80.f) {
if (minAbsAngeRaw == 180f) minAbsAngeRaw = turnAngle; // disable hasSomethingMoreStraight
continue; // ways from the back should not trigger a slight turn
}

Expand Down Expand Up @@ -228,13 +231,13 @@ public List<VoiceHint> process(List<VoiceHint> inputs) {
}
}

input.angle = sumNonConsumedWithinCatchingRange(inputs, hintIdx);
input.angle = sumNonConsumedWithinCatchingRange(inputs, hintIdx, INTERNAL_CATCHING_RANGE_WIDE);
input.distanceToNext = distance;
distance = 0.;
results.add(input);
}
if (results.size() > 0 && distance < INTERNAL_CATCHING_RANGE) { //catchingRange
results.get(results.size() - 1).angle += sumNonConsumedWithinCatchingRange(inputs, hintIdx);
if (results.size() > 0 && distance < INTERNAL_CATCHING_RANGE_NEAR) { //catchingRange
results.get(results.size() - 1).angle += sumNonConsumedWithinCatchingRange(inputs, hintIdx, INTERNAL_CATCHING_RANGE_NEAR);
}
}

Expand All @@ -251,7 +254,7 @@ public List<VoiceHint> process(List<VoiceHint> inputs) {
if (!(hint.needsRealTurn && (hint.cmd == VoiceHint.C || hint.cmd == VoiceHint.BL))) {
double dist = hint.distanceToNext;
// sum up other hints within the catching range (e.g. 40m)
while (dist < INTERNAL_CATCHING_RANGE && i > 0) {
while (dist < INTERNAL_CATCHING_RANGE_NEAR && i > 0) {
VoiceHint h2 = results.get(i - 1);
dist = h2.distanceToNext;
hint.distanceToNext += dist;
Expand Down Expand Up @@ -292,7 +295,10 @@ public List<VoiceHint> postProcess(List<VoiceHint> inputs, double catchingRange,
}

if (nextInput == null) {
if (input.cmd == VoiceHint.C && !input.goodWay.isLinktType()) {
if ((input.cmd == VoiceHint.C ||
input.cmd == VoiceHint.KR ||
input.cmd == VoiceHint.KL)
&& !input.goodWay.isLinktType()) {
if (input.goodWay.getPrio() < input.maxBadPrio && (inputLastSaved != null && inputLastSaved.distanceToNext > catchingRange)) {
results.add(input);
} else {
Expand All @@ -306,10 +312,15 @@ public List<VoiceHint> postProcess(List<VoiceHint> inputs, double catchingRange,
}
} else {
if ((inputLastSaved != null && inputLastSaved.distanceToNext > catchingRange) || input.distanceToNext > catchingRange) {
if (input.cmd == VoiceHint.C && !input.goodWay.isLinktType()) {
if (input.goodWay.getPrio() < input.maxBadPrio
&& (inputLastSaved != null && inputLastSaved.distanceToNext > minRange)
&& (input.distanceToNext > minRange)) {
if ((input.cmd == VoiceHint.C ||
input.cmd == VoiceHint.KR ||
input.cmd == VoiceHint.KL)
&& !input.goodWay.isLinktType()) {
if (((Math.abs(input.lowerBadWayAngle) < 35.f ||
input.higherBadWayAngle < 35.f)
|| input.goodWay.getPrio() < input.maxBadPrio)
&& (inputLastSaved != null && inputLastSaved.distanceToNext > minRange)
&& (input.distanceToNext > minRange)) {
// add only on prio
results.add(input);
inputLastSaved = input;
Expand Down Expand Up @@ -343,7 +354,10 @@ public List<VoiceHint> postProcess(List<VoiceHint> inputs, double catchingRange,
dist += nextInput.distanceToNext;
angles += nextInput.angle;

if (input.cmd == VoiceHint.C && !input.goodWay.isLinktType()) {
if ((input.cmd == VoiceHint.C ||
input.cmd == VoiceHint.KR ||
input.cmd == VoiceHint.KL)
&& !input.goodWay.isLinktType()) {
if (input.goodWay.getPrio() < input.maxBadPrio) {
if (inputLastSaved != null && inputLastSaved.cmd != VoiceHint.C
&& (inputLastSaved != null && inputLastSaved.distanceToNext > minRange)
Expand Down

0 comments on commit 7ead35e

Please sign in to comment.