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

New voicehints for motorway exit #742

Merged
merged 7 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 9 additions & 9 deletions brouter-core/src/main/java/btools/router/FormatGpx.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public String formatAsGpx(BufferedWriter sb, OsmTrack t) throws IOException {
sb.append("<!-- cmd idx lon lat d2next geometry -->\n");
sb.append("<!-- $turn-instruction-start$\n");
for (VoiceHint hint : t.voiceHints.list) {
sb.append(String.format(" $turn$%6s;%6d;%10s;%10s;%6d;%s$\n", hint.getCommandString(), hint.indexInTrack,
sb.append(String.format(" $turn$%6s;%6d;%10s;%10s;%6d;%s$\n", hint.getCommandString(turnInstructionMode), hint.indexInTrack,
formatILon(hint.ilon), formatILat(hint.ilat), (int) (hint.distanceToNext), hint.formatGeometry()));
}
sb.append(" $turn-instruction-end$ -->\n");
Expand Down Expand Up @@ -121,7 +121,7 @@ public String formatAsGpx(BufferedWriter sb, OsmTrack t) throws IOException {
sb.append(" <rtept lat=\"").append(formatILat(hint.ilat)).append("\" lon=\"")
.append(formatILon(hint.ilon)).append("\">\n")
.append(" <desc>")
.append(turnInstructionMode == 3 ? hint.getMessageString() : hint.getCruiserMessageString())
.append(turnInstructionMode == 3 ? hint.getMessageString(turnInstructionMode) : hint.getCruiserMessageString())
.append("</desc>\n <extensions>\n");

rteTime = t.getVoiceHintTime(i + 1);
Expand All @@ -132,7 +132,7 @@ public String formatAsGpx(BufferedWriter sb, OsmTrack t) throws IOException {
lastRteTime = rteTime;
}
sb.append(" <turn>")
.append(turnInstructionMode == 3 ? hint.getCommandString() : hint.getCruiserCommandString())
.append(turnInstructionMode == 3 ? hint.getCommandString(turnInstructionMode) : hint.getCruiserCommandString())
.append("</turn>\n <turn-angle>").append("" + (int) hint.angle)
.append("</turn-angle>\n <offset>").append("" + hint.indexInTrack).append("</offset>\n </extensions>\n </rtept>\n");
}
Expand All @@ -154,7 +154,7 @@ public String formatAsGpx(BufferedWriter sb, OsmTrack t) throws IOException {
.append(formatILat(hint.ilat)).append("\">")
.append(hint.selev == Short.MIN_VALUE ? "" : "<ele>" + (hint.selev / 4.) + "</ele>")
.append("<name>")
.append(hint.getMessageString())
.append(hint.getMessageString(turnInstructionMode))
.append("</name>")
.append("<extensions><locus:rteDistance>").append("" + hint.distanceToNext).append("</locus:rteDistance>");
float rteTime = t.getVoiceHintTime(i + 1);
Expand All @@ -173,9 +173,9 @@ public String formatAsGpx(BufferedWriter sb, OsmTrack t) throws IOException {
for (VoiceHint hint : t.voiceHints.list) {
sb.append(" <wpt lon=\"").append(formatILon(hint.ilon)).append("\" lat=\"")
.append(formatILat(hint.ilat)).append("\">")
.append("<name>").append(hint.getMessageString()).append("</name>")
.append("<sym>").append(hint.getSymbolString().toLowerCase()).append("</sym>")
.append("<type>").append(hint.getSymbolString()).append("</type>")
.append("<name>").append(hint.getMessageString(turnInstructionMode)).append("</name>")
.append("<sym>").append(hint.getSymbolString(turnInstructionMode).toLowerCase()).append("</sym>")
.append("<type>").append(hint.getSymbolString(turnInstructionMode)).append("</type>")
.append("</wpt>\n");
}
}
Expand Down Expand Up @@ -270,7 +270,7 @@ public String formatAsGpx(BufferedWriter sb, OsmTrack t) throws IOException {
sele += "<name>" + mwpt.name + "</name>";
}
sele += "<desc>" + hint.getCruiserMessageString() + "</desc>";
sele += "<sym>" + hint.getCommandString(hint.cmd) + "</sym>";
sele += "<sym>" + hint.getCommandString(hint.cmd, turnInstructionMode) + "</sym>";
if (mwpt != null) {
sele += "<type>Via</type>";
}
Expand All @@ -287,7 +287,7 @@ public String formatAsGpx(BufferedWriter sb, OsmTrack t) throws IOException {
sele += "<brouter:speed>" + (((int) (speed * 10)) / 10.f) + "</brouter:speed>";
}

sele += "<brouter:voicehint>" + hint.getCommandString() + ";" + (int) (hint.distanceToNext) + "," + hint.formatGeometry() + "</brouter:voicehint>";
sele += "<brouter:voicehint>" + hint.getCommandString(turnInstructionMode) + ";" + (int) (hint.distanceToNext) + "," + hint.formatGeometry() + "</brouter:voicehint>";
if (n.message != null && n.message.wayKeyValues != null && !n.message.wayKeyValues.equals(lastway)) {
sele += "<brouter:way>" + n.message.wayKeyValues + "</brouter:way>";
lastway = n.message.wayKeyValues;
Expand Down
6 changes: 3 additions & 3 deletions brouter-core/src/main/java/btools/router/FormatJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public String format(OsmTrack t) {
for (VoiceHint hint : t.voiceHints.list) {
sb.append(" [");
sb.append(hint.indexInTrack);
sb.append(',').append(hint.getJsonCommandIndex());
sb.append(',').append(hint.getJsonCommandIndex(turnInstructionMode));
sb.append(',').append(hint.getExitNumber());
sb.append(',').append(hint.distanceToNext);
sb.append(',').append((int) hint.angle);

// not always include geometry because longer and only needed for comment style
if (turnInstructionMode == 4) { // comment style
if (turnInstructionMode == 4 || turnInstructionMode == 9) { // comment style
sb.append(",\"").append(hint.formatGeometry()).append("\"");
}

Expand Down Expand Up @@ -122,7 +122,7 @@ public String format(OsmTrack t) {
.append(sele).append("],\n");
nn = n;
}
if (t.nodes != null && !t.nodes.isEmpty()) sb.deleteCharAt(sb.lastIndexOf(","));
sb.deleteCharAt(sb.lastIndexOf(","));

sb.append(" ]\n");
sb.append(" }\n");
Expand Down
52 changes: 47 additions & 5 deletions brouter-core/src/main/java/btools/router/VoiceHint.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class VoiceHint {
static final int RNLB = 14; // Roundabout left
static final int TU = 15; // 180 degree u-turn
static final int BL = 16; // Beeline routing
static final int EL = 17; // Beeline routing
static final int ER = 18; // Beeline routing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@afischerdev The comments here should mention the exit instructions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, looks better


int ilon;
int ilat;
Expand Down Expand Up @@ -65,7 +67,7 @@ public void addBadWay(MessageData badWay) {
badWays.add(badWay);
}

public int getJsonCommandIndex() {
public int getJsonCommandIndex(int timode) {
switch (cmd) {
case TLU:
return 10;
Expand Down Expand Up @@ -97,6 +99,10 @@ public int getJsonCommandIndex() {
return 14;
case BL:
return 16;
case EL:
return timode == 2 || timode == 9 ? 17 : 8;
case ER:
return timode == 2 || timode == 9 ? 18 : 9;
case OFFR:
return 12;
default:
Expand All @@ -111,7 +117,7 @@ public int getExitNumber() {
/*
* used by comment style, osmand style
*/
public String getCommandString() {
public String getCommandString(int timode) {
switch (cmd) {
case TLU:
return "TU"; // should be changed to TLU when osmand uses new voice hint constants
Expand Down Expand Up @@ -143,6 +149,10 @@ public String getCommandString() {
return "RNLB" + (-roundaboutExit);
case BL:
return "BL";
case EL:
return timode == 2 || timode == 9 ? "EL" : "KL";
case ER:
return timode == 2 || timode == 9 ? "ER" : "KR";
case OFFR:
return "OFFR";
default:
Expand All @@ -153,7 +163,7 @@ public String getCommandString() {
/*
* used by trkpt/sym style
*/
public String getCommandString(int c) {
public String getCommandString(int c, int timode) {
switch (c) {
case TLU:
return "TLU";
Expand Down Expand Up @@ -185,6 +195,10 @@ public String getCommandString(int c) {
return "RNLB" + (-roundaboutExit);
case BL:
return "BL";
case EL:
return timode == 2 || timode == 9 ? "EL" : "KL";
case ER:
return timode == 2 || timode == 9 ? "ER" : "KR";
case OFFR:
return "OFFR";
default:
Expand All @@ -195,7 +209,7 @@ public String getCommandString(int c) {
/*
* used by gpsies style
*/
public String getSymbolString() {
public String getSymbolString(int timode) {
switch (cmd) {
case TLU:
return "TU";
Expand Down Expand Up @@ -227,6 +241,10 @@ public String getSymbolString() {
return "RNLB" + (-roundaboutExit);
case BL:
return "BL";
case EL:
return timode == 2 || timode == 9 ? "EL" : "KL";
case ER:
return timode == 2 || timode == 9 ? "ER" : "KR";
case OFFR:
return "OFFR";
default:
Expand Down Expand Up @@ -269,6 +287,10 @@ public String getLocusSymbolString() {
return "roundabout_e" + (-roundaboutExit);
case BL:
return "beeline";
case EL:
return "exit_left";
case ER:
return "exit_right";
default:
throw new IllegalArgumentException("unknown command: " + cmd);
}
Expand All @@ -277,7 +299,7 @@ public String getLocusSymbolString() {
/*
* used by osmand style
*/
public String getMessageString() {
public String getMessageString(int timode) {
switch (cmd) {
case TLU:
return "u-turn"; // should be changed to u-turn-left when osmand uses new voice hint constants
Expand Down Expand Up @@ -307,6 +329,10 @@ public String getMessageString() {
return "Take exit " + roundaboutExit;
case RNLB:
return "Take exit " + (-roundaboutExit);
case EL:
return timode == 2 || timode == 9 ? "exit left" : "keep left";
case ER:
return timode == 2 || timode == 9 ? "exit right" : "keep right";
default:
throw new IllegalArgumentException("unknown command: " + cmd);
}
Expand Down Expand Up @@ -345,6 +371,10 @@ public int getLocusAction() {
return 26 + roundaboutExit;
case RNLB:
return 26 - roundaboutExit;
case EL:
return 9;
case ER:
return 10;
default:
throw new IllegalArgumentException("unknown command: " + cmd);
}
Expand Down Expand Up @@ -383,6 +413,10 @@ public int getOruxAction() {
return 1008 + roundaboutExit;
case RNLB:
return 1008 + roundaboutExit;
case EL:
return 1015;
case ER:
return 1014;
default:
throw new IllegalArgumentException("unknown command: " + cmd);
}
Expand Down Expand Up @@ -423,6 +457,10 @@ public String getCruiserCommandString() {
return "RNLB" + (-roundaboutExit);
case BL:
return "BL";
case EL:
return "EL";
case ER:
return "ER";
case OFFR:
return "OFFR";
default:
Expand Down Expand Up @@ -465,6 +503,10 @@ public String getCruiserMessageString() {
return "take exit " + (-roundaboutExit);
case BL:
return "beeline";
case EL:
return "exit left";
case ER:
return "exit right";
case OFFR:
return "offroad";
default:
Expand Down
19 changes: 19 additions & 0 deletions brouter-core/src/main/java/btools/router/VoiceHintProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,17 @@ public List<VoiceHint> postProcess(List<VoiceHint> inputs, double catchingRange,
inputLastSaved.distanceToNext += input.distanceToNext;
}
}
} else if ((input.goodWay.getPrio() == 29 && input.maxBadPrio == 30) &&
((hintIdx + 1 < inputs.size() && inputs.get(hintIdx+1).goodWay.getPrio() < 29) ||
(hintIdx + 2 < inputs.size() && inputs.get(hintIdx+2).goodWay.getPrio() < 29))) {
// leave motorway
if (input.cmd == VoiceHint.KR || input.cmd == VoiceHint.TSLR) {
input.cmd = VoiceHint.ER;
} else if (input.cmd == VoiceHint.KL || input.cmd == VoiceHint.TSLL) {
input.cmd = VoiceHint.EL;
}
results.add(input);
inputLastSaved = input;
} else {
// add all others
// ignore motorway / primary continue
Expand Down Expand Up @@ -384,6 +395,14 @@ public List<VoiceHint> postProcess(List<VoiceHint> inputs, double catchingRange,
inputLastSaved.distanceToNext += input.distanceToNext;
}
}
} else if ((input.goodWay.getPrio() == 29 && input.maxBadPrio == 30)) {
// leave motorway
if (input.cmd == VoiceHint.KR || input.cmd == VoiceHint.TSLR) {
input.cmd = VoiceHint.ER;
} else if (input.cmd == VoiceHint.KL || input.cmd == VoiceHint.TSLL) {
input.cmd = VoiceHint.EL;
}
save = true;
} else if (VoiceHint.is180DegAngle(input.angle)) {
// add u-turn, 180 degree
save = true;
Expand Down
3 changes: 3 additions & 0 deletions docs/features/voicehints.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ And there are other rules
* merge two hints when near to each other - e.g. left, left to u-turn left
* marker when highway exit and continue nearly same direction
* beeline goes direct from via to via point
* junction on motorway via motorway_link and next way less then motorway_link is a motorway exit

There are some variables in the profiles that affect on the voice hint generation:
* considerTurnRestrictions -
Expand All @@ -51,4 +52,6 @@ Voice hint variables
| RNDB | roundabout |
| RNLB | roundabout left |
| BL | beeline routing |
| EL | exit left |
| ER | exit right |

Loading