From a5f7261f270e670cf9bec3211e28dc8cd5b6e297 Mon Sep 17 00:00:00 2001 From: Marc Garcia Puig Date: Tue, 26 Mar 2019 18:31:41 +0100 Subject: [PATCH] Added support for lane mark info on waypoint core --- LibCarla/source/carla/client/Waypoint.cpp | 8 ++ LibCarla/source/carla/client/Waypoint.h | 7 +- .../source/carla/road/element/LaneMarking.h | 10 ++- .../road/element/WaypointInformationTypes.cpp | 74 +++++++++++++++++++ .../road/element/WaypointInformationTypes.h | 48 ++++++++++++ PythonAPI/lane_explorer.py | 4 +- 6 files changed, 147 insertions(+), 4 deletions(-) create mode 100644 LibCarla/source/carla/road/element/WaypointInformationTypes.cpp create mode 100644 LibCarla/source/carla/road/element/WaypointInformationTypes.h diff --git a/LibCarla/source/carla/client/Waypoint.cpp b/LibCarla/source/carla/client/Waypoint.cpp index ba127f78c..81a403efc 100644 --- a/LibCarla/source/carla/client/Waypoint.cpp +++ b/LibCarla/source/carla/client/Waypoint.cpp @@ -76,6 +76,14 @@ namespace client { static_cast::type>(rhs)); } + const road::element::WaypointInfoRoadMark Waypoint::GetRightRoadMark() const { + return road::element::WaypointInfoRoadMark(*_mark_record.first); + } + + const road::element::WaypointInfoRoadMark Waypoint::GetLeftRoadMark() const { + return road::element::WaypointInfoRoadMark(*_mark_record.second); + } + Waypoint::LaneChange Waypoint::GetLaneChange() const { const auto lane_change_right = _mark_record.first->GetLaneChange(); const auto lane_change_left = _mark_record.second->GetLaneChange(); diff --git a/LibCarla/source/carla/client/Waypoint.h b/LibCarla/source/carla/client/Waypoint.h index 0abeeb4ed..d9bd7ab9f 100644 --- a/LibCarla/source/carla/client/Waypoint.h +++ b/LibCarla/source/carla/client/Waypoint.h @@ -6,11 +6,12 @@ #pragma once +#include "carla/geom/Transform.h" #include "carla/Memory.h" #include "carla/NonCopyable.h" -#include "carla/geom/Transform.h" #include "carla/road/element/RoadInfoMarkRecord.h" #include "carla/road/element/Waypoint.h" +#include "carla/road/element/WaypointInformationTypes.h" #include "carla/road/Lane.h" namespace carla { @@ -73,6 +74,10 @@ namespace client { SharedPtr Left() const; + const road::element::WaypointInfoRoadMark GetRightRoadMark() const; + + const road::element::WaypointInfoRoadMark GetLeftRoadMark() const; + Waypoint::LaneChange GetLaneChange() const; private: diff --git a/LibCarla/source/carla/road/element/LaneMarking.h b/LibCarla/source/carla/road/element/LaneMarking.h index 58de530c2..2c65ccd6a 100644 --- a/LibCarla/source/carla/road/element/LaneMarking.h +++ b/LibCarla/source/carla/road/element/LaneMarking.h @@ -13,7 +13,15 @@ namespace element { enum class LaneMarking { Other, Broken, - Solid + Solid, + SolidSolid, // (for double solid line) + SolidBroken, // (from inside to outside, exception: center lane -from left to right) + BrokenSolid, // (from inside to outside, exception: center lane -from left to right) + BrokenBroken, // (from inside to outside, exception: center lane -from left to right) + BottsDots, + Grass, // (meaning a grass edge) + Curb, + None }; } // namespace element diff --git a/LibCarla/source/carla/road/element/WaypointInformationTypes.cpp b/LibCarla/source/carla/road/element/WaypointInformationTypes.cpp new file mode 100644 index 000000000..6d4f1ce74 --- /dev/null +++ b/LibCarla/source/carla/road/element/WaypointInformationTypes.cpp @@ -0,0 +1,74 @@ +// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma +// de Barcelona (UAB). +// +// This work is licensed under the terms of the MIT license. +// For a copy, see . + +#include "carla/road/element/WaypointInformationTypes.h" +#include "carla/road/element/RoadInfoMarkRecord.h" + +namespace carla { +namespace road { +namespace element { + + WaypointInfoRoadMark::WaypointInfoRoadMark(const RoadInfoMarkRecord &info) { + const auto &t = info.GetType(); + const auto &c = info.GetColor(); + const auto &lc = info.GetLaneChange(); + + if (t == "broken") { + type = LaneMarking::Broken; + } else if (t == "solid") { + type = LaneMarking::Solid; + } else if (t == "solid solid") { + type = LaneMarking::SolidSolid; + } else if (t == "solid broken") { + type = LaneMarking::SolidBroken; + } else if (t == "broken solid") { + type = LaneMarking::BrokenSolid; + } else if (t == "broken broken") { + type = LaneMarking::BrokenBroken; + } else if (t == "botts dots") { + type = LaneMarking::BottsDots; + } else if (t == "grass") { + type = LaneMarking::Grass; + } else if (t == "curb") { + type = LaneMarking::Curb; + } else if (t == "none") { + type = LaneMarking::None; + } else { + type = LaneMarking::Other; + } + + if (c == "standard") { + color = WaypointInfoRoadMark::Color::Standard; + } else if (c == "blue") { + color = WaypointInfoRoadMark::Color::Blue; + } else if (c == "green") { + color = WaypointInfoRoadMark::Color::Green; + } else if (c == "red") { + color = WaypointInfoRoadMark::Color::Red; + } else if (c == "white") { + color = WaypointInfoRoadMark::Color::White; + } else if (c == "yellow") { + color = WaypointInfoRoadMark::Color::Yellow; + } else { + color = WaypointInfoRoadMark::Color::Other; + } + + if (lc == RoadInfoMarkRecord::LaneChange::Increase) { + lane_change = WaypointInfoRoadMark::LaneChange::Increase; + } else if (lc == RoadInfoMarkRecord::LaneChange::Decrease) { + lane_change = WaypointInfoRoadMark::LaneChange::Decrease; + } else if (lc == RoadInfoMarkRecord::LaneChange::Both) { + lane_change = WaypointInfoRoadMark::LaneChange::Both; + } else if (lc == RoadInfoMarkRecord::LaneChange::None) { + lane_change = WaypointInfoRoadMark::LaneChange::None; + } + + width = info.GetWidth(); + } + +} // namespace element +} // namespace road +} // namespace carla diff --git a/LibCarla/source/carla/road/element/WaypointInformationTypes.h b/LibCarla/source/carla/road/element/WaypointInformationTypes.h new file mode 100644 index 000000000..ead3c0ff5 --- /dev/null +++ b/LibCarla/source/carla/road/element/WaypointInformationTypes.h @@ -0,0 +1,48 @@ +// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma +// de Barcelona (UAB). +// +// This work is licensed under the terms of the MIT license. +// For a copy, see . + +#pragma once + +#include "carla/road/element/LaneMarking.h" +#include + +namespace carla { +namespace road { +namespace element { + + class RoadInfoMarkRecord; + + struct WaypointInfoRoadMark { + + // WaypointInfoRoadMark() {} + + WaypointInfoRoadMark(const RoadInfoMarkRecord &info); + + LaneMarking type = LaneMarking::None; + + enum class Color : uint8_t { + Standard, // (equivalent to "white") + Blue, + Green, + Red, + White = Standard, + Yellow, + Other + } color = Color::Standard; + + enum class LaneChange : uint8_t { + Increase, + Decrease, + Both, + None + } lane_change = LaneChange::None; + + float width = 0.0f; + }; + +} // namespace element +} // namespace road +} // namespace carla diff --git a/PythonAPI/lane_explorer.py b/PythonAPI/lane_explorer.py index 5ac58b2d8..e6250007a 100755 --- a/PythonAPI/lane_explorer.py +++ b/PythonAPI/lane_explorer.py @@ -130,13 +130,13 @@ def main(): # check for available right driving lanes if current_w.lane_change & carla.LaneChange.Right: right_w = current_w.get_right_lane() - if right_w and right_w.lane_type == 'driving': + if right_w and right_w.lane_type == carla.LaneType.Driving: potential_w += list(right_w.next(waypoint_separation)) # check for available left driving lanes if current_w.lane_change & carla.LaneChange.Left: left_w = current_w.get_left_lane() - if left_w and left_w.lane_type == 'driving': + if left_w and left_w.lane_type == carla.LaneType.Driving: potential_w += list(left_w.next(waypoint_separation)) # choose a random waypoint to be the next