From d9dc7419b35b7762bc5222cf874ccc39d2d66f43 Mon Sep 17 00:00:00 2001 From: yy1717 <fctom1215@outlook.com> Date: 星期一, 10 八月 2020 18:36:31 +0800 Subject: [PATCH] 坐标 --- lib/src/main/cpp/master/comm_if.cpp | 47 +++++++++++++++ lib/src/main/cpp/test_items2/road_exam.cpp | 95 +++++++++++++++++++++++++++++-- lib/src/main/cpp/driver_test.h | 21 +++++-- 3 files changed, 148 insertions(+), 15 deletions(-) diff --git a/lib/src/main/cpp/driver_test.h b/lib/src/main/cpp/driver_test.h index cbad97b..69173a1 100644 --- a/lib/src/main/cpp/driver_test.h +++ b/lib/src/main/cpp/driver_test.h @@ -141,23 +141,32 @@ // 涓�缁勫钩琛岀殑鍒嗛亾绾� typedef struct { - std::vector<lane_direct_t> lane_direct; + std::vector<lane_direct_t> lane_direct; // 姣忎竴杞﹂亾鐨勮繍琛屾柟鍚� std::vector<std::vector<segment_t>> lines; // 姣忔鍩熶笅鐨勫钩琛岀殑涓�缁勭嚎 } separate_t; typedef struct { + int active; + string tts; + bool stopFlag; + Line line; +} stop_line_t; + +typedef struct { int id; Line startLine; - Line stopLine; - int active; // 鍒拌揪璺彛灏鹃儴鐨勮杩涙柟鍚� +// Line stopLine; +// int active; // 鍒拌揪璺彛灏鹃儴鐨勮杩涙柟鍚� bool activeBreak; // 璺彛鍒硅溅鍑忛�� bool activeStop; // 璺彛鍋滆溅鐬湜 bool errorLane; // 閿欒杞﹂亾 int targetRoad; - int stopFlag; - string tts; - bool arrivedTail; +// int stopFlag; +// string tts; +// bool arrivedTail; Polygon area; // 鏁翠釜閬撹矾鍖哄煙 + + std::vector<stop_line_t> stopLine; std::vector<edge_t> leftEdge; std::vector<edge_t> rightEdge; std::vector<separate_t> separate; diff --git a/lib/src/main/cpp/master/comm_if.cpp b/lib/src/main/cpp/master/comm_if.cpp index 5ff520f..57cd155 100644 --- a/lib/src/main/cpp/master/comm_if.cpp +++ b/lib/src/main/cpp/master/comm_if.cpp @@ -808,7 +808,7 @@ MakeLine(&road.startLine, &p1, &p2); } - if (itr->HasMember("stop_line")) { + /*if (itr->HasMember("stop_line")) { const Value &a2 = (*itr)["stop_line"]; PointF p1, p2; @@ -824,7 +824,52 @@ } MakeLine(&road.stopLine, &p1, &p2); + }*/ + if (itr->HasMember("crossing") && itr->IsArray()) { + const Value &a2 = (*itr)["crossing"]; + + vector<stop_line_t> crossing; + + for (Value::ConstValueIterator itr2 = a2.Begin(); itr2 != a2.End(); ++itr2) { + stop_line_t temp; + if (!itr2->IsObject()) { + break; + } + if (itr2->HasMember("active")) { + const Value &s = (*itr2)["active"]; + temp.active = s.GetInt(); + } + if (itr2->HasMember("stop_flag")) { + const Value &s = (*itr2)["stop_flag"]; + temp.stopFlag = s.GetInt(); + } + if (itr2->HasMember("tts")) { + const Value &s = (*itr2)["tts"]; + temp.tts = s.GetString(); + } + if (itr2->HasMember("line")) { + const Value &s = (*itr2)["line"]; + PointF p1, p2; + int n = 0; + + if (s.IsArray() && s.Size() >= 2) { + for (Value::ConstValueIterator itr3 = s.Begin(); itr3 != s.End(); ++itr3, ++n) { + if (n == 0) { + p1 = mapPoints[(*itr3).GetInt()]; + } else if (n == 1) { + p2 = mapPoints[(*itr3).GetInt()]; + } + } + MakeLine(&temp.line, &p1, &p2); + } + } + + crossing.push_back(temp); + } + + road.stopLine.assign(crossing.begin(), crossing.end()); } + if (itr->HasMember("active")) { const Value &s = (*itr)["active"]; DEBUG("璺彛鍔ㄤ綔 %d", s.GetInt()); diff --git a/lib/src/main/cpp/test_items2/road_exam.cpp b/lib/src/main/cpp/test_items2/road_exam.cpp index 3a1a5b0..8e42c1e 100644 --- a/lib/src/main/cpp/test_items2/road_exam.cpp +++ b/lib/src/main/cpp/test_items2/road_exam.cpp @@ -1379,11 +1379,11 @@ ArrivedRoadEnd(RoadMap.roads[currExamMapIndex], car, CarModelList); - if (CrashTheLine(RoadMap.roads[currExamMapIndex].stopLine, car, CarModelList)) { - DEBUG("涓嬩竴涓洰鏍囪矾 id = %d", RoadMap.roads[currExamMapIndex].targetRoad); - nextRoadId = RoadMap.roads[currExamMapIndex].targetRoad; - checkTurn = true; - } +// if (CrashTheLine(RoadMap.roads[currExamMapIndex].stopLine, car, CarModelList)) { +// DEBUG("涓嬩竴涓洰鏍囪矾 id = %d", RoadMap.roads[currExamMapIndex].targetRoad); +// nextRoadId = RoadMap.roads[currExamMapIndex].targetRoad; +// checkTurn = true; +// } if (checkTurn) { // 妫�鏌ユ槸鍚︽寔缁浆鍚� @@ -1988,7 +1988,7 @@ * @param car * @param CarModelList */ -static void ArrivedRoadEnd(road_t &road, const car_model *car, LIST_CAR_MODEL &CarModelList) +/*static void ArrivedRoadEnd(road_t &road, const car_model *car, LIST_CAR_MODEL &CarModelList) { // 璁$畻杞﹀墠杩涜建杩瑰欢闀跨嚎 double yaw = YawOf(car->carXY[ car->axial[AXIAL_FRONT] ], car->carXY[ car->axial[AXIAL_REAR] ]); @@ -2009,6 +2009,84 @@ } } else if (road.arrivedTail) { road.arrivedTail = false; + } +}*/ + +// 璺彛锛屾彁绀猴紝鍓�30绫宠繘鍏ワ紝 绂诲紑 +// 浜鸿閬擄紝杞︾珯锛屽墠30绫宠繘鍏ワ紝绂诲紑 +// 瀛︽牎锛岃繘鍏ワ紝绂诲紑 + +map<int, int> CrossingStatus; + +static void ChangeCrossingStatus(int roadIndex, int index, int status) +{ + int key = roadIndex * 100 + index; + + auto it = CrossingStatus.find(key); + + if (it != CrossingStatus.end()) { + CrossingStatus.erase(it); + } + CrossingStatus.insert(pair<int, int>(key, status)); +} + +static int GetCrossingStatus(int roadIndex, int index) +{ + int key = roadIndex * 100 + index; + + auto it = CrossingStatus.find(key); + + if (it != CrossingStatus.end()) { + return it->second; + } + return -1; +} + +enum { + CROSSING_STATUS_INVALID = -1, + CROSSING_STATUS_GUIDE, + CROSSING_STATUS_REDUCE_SPEED, + CROSSING_STATUS_BREAK_CAR, + CROSSING_STATUS_STOP_CAR +}; + +static void CheckCrossing(int roadIndex, road_t &road, const car_model *car, LIST_CAR_MODEL &CarModelList) +{ + for (int i = 0; i < road.stopLine.size(); ++i) { + if (CrashTheLine(road.stopLine[i].line, car, CarModelList)) { + if (road.stopLine[i].stopFlag) { + if (GetCrossingStatus(roadIndex, i) != CROSSING_STATUS_STOP_CAR) { + + } + } else { + if (GetCrossingStatus(roadIndex, i) != CROSSING_STATUS_BREAK_CAR) { + + } + } + ChangeCrossingStatus(roadIndex, i, CROSSING_STATUS_INVALID); + } else { + + } + PointF point; + double distance; + + point.X = road.stopLine[i].line.X1; + point.Y = road.stopLine[i].line.Y1; + + distance = CalcDistanceReference(car->carXY[car->axial[AXIAL_FRONT]], point, road.rightEdge); + + if (distance > 10 && distance < 50) { + if (GetCrossingStatus(roadIndex, i) == CROSSING_STATUS_INVALID) { + if (!road.stopLine[i].tts.empty()) { + PlayTTS(road.stopLine[i].tts.c_str()); + } + ChangeCrossingStatus(roadIndex, i, CROSSING_STATUS_GUIDE); + } + } else if (distance > 0 && distance < 30) { + if (GetCrossingStatus(roadIndex, i) != 1) { + ChangeCrossingStatus(roadIndex, i, 1); + } + } } } @@ -2084,7 +2162,7 @@ MakeLine(&extLine, &car->carXY[ car->axial[AXIAL_FRONT] ], &extPoint); // 璺彛鍒硅溅鐐� - for (int i = 0; i < map.roads.size(); ++i) { +/* for (int i = 0; i < map.roads.size(); ++i) { // 杞﹀ご鍜岃矾鍙h窛绂讳笉瓒�30绫� if (IntersectionOf(extLine, map.roads[i].stopLine) == GM_Intersection && IntersectionOfLine(car->carXY[ car->axial[AXIAL_FRONT] ], map.roads[i].stopLine) == 1 ) { @@ -2122,7 +2200,8 @@ } } } - } + }*/ + // 浜鸿閬撱�佸叕浜ょ珯鍒硅溅鐐癸紱瀛︽牎闄愰�熷尯 // DEBUG("琛ュ叏鐗规畩鍖哄煙 size = %d", map.specialAreas.size()); for (int i = 0; i < map.specialAreas.size(); i++) { -- Gitblit v1.8.0