From f8f36e161f1af1727a6c81d01fe0fef1e19fcec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Karas?= Date: Sun, 21 May 2023 22:51:21 +0200 Subject: [PATCH 1/2] skip short distance information when vehicle is car --- .../include/osmscout/navigation/VoiceInstructionAgent.h | 1 + .../src/osmscout/navigation/VoiceInstructionAgent.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libosmscout/include/osmscout/navigation/VoiceInstructionAgent.h b/libosmscout/include/osmscout/navigation/VoiceInstructionAgent.h index f4d6829f3..99f8ca12b 100644 --- a/libosmscout/include/osmscout/navigation/VoiceInstructionAgent.h +++ b/libosmscout/include/osmscout/navigation/VoiceInstructionAgent.h @@ -175,6 +175,7 @@ class OSMSCOUT_API VoiceInstructionAgent CLASS_FINAL : public NavigationAgent private: DistanceUnitSystem units{DistanceUnitSystem::Metrics}; + Vehicle vehicle{vehicleCar}; // state used for triggering GpsFound / GpsLost messages bool prevGpsSignal{true}; diff --git a/libosmscout/src/osmscout/navigation/VoiceInstructionAgent.cpp b/libosmscout/src/osmscout/navigation/VoiceInstructionAgent.cpp index a71f8e63d..d4e84a1d7 100644 --- a/libosmscout/src/osmscout/navigation/VoiceInstructionAgent.cpp +++ b/libosmscout/src/osmscout/navigation/VoiceInstructionAgent.cpp @@ -270,7 +270,9 @@ std::vector VoiceInstructionAgent::toSampl return samples; } - if (distanceInUnits > 50){ + if (bool skipDistanceInformation = (distanceInUnits < 80 && vehicle == vehicleCar); + !skipDistanceInformation){ + samples.push_back(VoiceSample::After); if (distanceInUnits > 800){ samples.push_back(VoiceSample::Distance800); @@ -299,7 +301,7 @@ std::vector VoiceInstructionAgent::toSampl toSamples(samples, message.type); if (then){ auto thenDistance = then.distance - message.distance; - if (thenDistance <= Meters(200)) { // ignore then messsage otherwise + if (thenDistance <= Meters(200)) { // ignore then message otherwise samples.push_back(VoiceSample::Then); toSamples(samples, then.type); } @@ -316,6 +318,7 @@ std::list VoiceInstructionAgent::Process(const NavigationM // reset state lastMessage.type=MessageType::NoMessage; lastMessagePosition=Distance::Zero(); + vehicle=routeUpdateMessage->vehicle; return result; } From b69c13bfaed653d4aecfa7396a0b063416118d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Karas?= Date: Sat, 27 May 2023 01:20:48 +0200 Subject: [PATCH 2/2] move roundabout voice message to roundabout enter And use short roundabout instruction when roundabout is close. Instead of phrase "on the roundabout, use the third exit" use just "use the third exit". --- .../navigation/VoiceInstructionAgent.h | 11 ++-- .../navigation/VoiceInstructionAgent.cpp | 51 ++++++++++++++----- 2 files changed, 46 insertions(+), 16 deletions(-) diff --git a/libosmscout/include/osmscout/navigation/VoiceInstructionAgent.h b/libosmscout/include/osmscout/navigation/VoiceInstructionAgent.h index 99f8ca12b..1c1a8a985 100644 --- a/libosmscout/include/osmscout/navigation/VoiceInstructionAgent.h +++ b/libosmscout/include/osmscout/navigation/VoiceInstructionAgent.h @@ -118,8 +118,8 @@ class OSMSCOUT_API VoiceInstructionAgent CLASS_FINAL : public NavigationAgent { public: - enum class MessageType { - NoMessage, + enum class MessageType: int { + NoMessage = 0, LeaveRbExit1, LeaveRbExit2, @@ -138,7 +138,9 @@ class OSMSCOUT_API VoiceInstructionAgent CLASS_FINAL : public NavigationAgent LeaveMotorway, LeaveMotorwayRight, - LeaveMotorwayLeft + LeaveMotorwayLeft, + + Silent }; struct MessageStruct { @@ -195,7 +197,8 @@ class OSMSCOUT_API VoiceInstructionAgent CLASS_FINAL : public NavigationAgent private: void toSamples(std::vector &samples, - const MessageType &messageType); + const MessageType &messageType, + bool shortRoundaboutMessage); std::vector toSamples(const Distance &distanceFromStart, const MessageStruct &message, diff --git a/libosmscout/src/osmscout/navigation/VoiceInstructionAgent.cpp b/libosmscout/src/osmscout/navigation/VoiceInstructionAgent.cpp index d4e84a1d7..7f3b2c87d 100644 --- a/libosmscout/src/osmscout/navigation/VoiceInstructionAgent.cpp +++ b/libosmscout/src/osmscout/navigation/VoiceInstructionAgent.cpp @@ -32,6 +32,7 @@ struct PostprocessorCallback : public RouteDescriptionPostprocessor::Callback Distance distanceFromStart; Distance stopAfter; Distance distance; + std::optional roundaboutEnter; //GetExitCount()){ case 1: @@ -120,11 +137,13 @@ struct PostprocessorCallback : public RouteDescriptionPostprocessor::Callback // it is not correct, but what else we may say? type = MessageType::LeaveRbExit6; } + // say the message before entering the roundabout if (!nextMessage){ - nextMessage = VoiceInstructionAgent::MessageStruct{type, distance}; + nextMessage = VoiceInstructionAgent::MessageStruct{type, *roundaboutEnter}; } else if (!thenMessage){ - thenMessage = VoiceInstructionAgent::MessageStruct{type, distance}; + thenMessage = VoiceInstructionAgent::MessageStruct{type, *roundaboutEnter}; } + roundaboutEnter = std::nullopt; } void OnTargetReached(const osmscout::RouteDescription::TargetDescriptionRef& /*targetDescription*/) override @@ -188,33 +207,32 @@ struct PostprocessorCallback : public RouteDescriptionPostprocessor::Callback } }; -void VoiceInstructionAgent::toSamples(std::vector &samples, const MessageType &type) +void VoiceInstructionAgent::toSamples(std::vector &samples, const MessageType &type, bool shortRoundaboutMessage) { using VoiceSample = VoiceInstructionMessage::VoiceSample; + + if (!shortRoundaboutMessage && type>=MessageType::LeaveRbExit1 && type<=MessageType::LeaveRbExit6) { + samples.push_back(VoiceSample::RbCross); + } + switch (type) { case MessageType::LeaveRbExit1: - samples.push_back(VoiceSample::RbCross); samples.push_back(VoiceSample::RbExit1); break; case MessageType::LeaveRbExit2: - samples.push_back(VoiceSample::RbCross); samples.push_back(VoiceSample::RbExit2); break; case MessageType::LeaveRbExit3: - samples.push_back(VoiceSample::RbCross); samples.push_back(VoiceSample::RbExit3); break; case MessageType::LeaveRbExit4: - samples.push_back(VoiceSample::RbCross); samples.push_back(VoiceSample::RbExit4); break; case MessageType::LeaveRbExit5: - samples.push_back(VoiceSample::RbCross); samples.push_back(VoiceSample::RbExit5); break; case MessageType::LeaveRbExit6: - samples.push_back(VoiceSample::RbCross); samples.push_back(VoiceSample::RbExit6); break; @@ -262,6 +280,11 @@ std::vector VoiceInstructionAgent::toSampl std::vector samples; assert(message); + + if (message.type == MessageType::Silent) { + return samples; + } + // distance from our position to next message Distance nextMessageDistance = (message.distance - distanceFromStart); double distanceInUnits = (units == DistanceUnitSystem::Metrics) ? nextMessageDistance.AsMeter() : nextMessageDistance.As(); @@ -270,6 +293,10 @@ std::vector VoiceInstructionAgent::toSampl return samples; } + // We are close to roundabout, we will use short roundabout message in such case. + bool shortRoundaboutMessage = message.type >= MessageType::LeaveRbExit1 && message.type <= MessageType::LeaveRbExit6 && + distanceInUnits < 120; + if (bool skipDistanceInformation = (distanceInUnits < 80 && vehicle == vehicleCar); !skipDistanceInformation){ @@ -298,12 +325,12 @@ std::vector VoiceInstructionAgent::toSampl samples.push_back(units == DistanceUnitSystem::Metrics ? VoiceSample::Meters : VoiceSample::Yards); } - toSamples(samples, message.type); + toSamples(samples, message.type, shortRoundaboutMessage); if (then){ auto thenDistance = then.distance - message.distance; if (thenDistance <= Meters(200)) { // ignore then message otherwise samples.push_back(VoiceSample::Then); - toSamples(samples, then.type); + toSamples(samples, then.type, true); } } return samples;