From 0701276b4fec856d5427e4776eec3cc7c56ec065 Mon Sep 17 00:00:00 2001 From: yy1717 <fctom1215@outlook.com> Date: 星期二, 25 八月 2020 17:51:10 +0800 Subject: [PATCH] 坐标 --- lib/src/main/cpp/test_items2/drive_straight.cpp | 13 ++-- lib/src/main/cpp/native-lib.h | 1 lib/src/main/cpp/native-lib.cpp | 29 +++++++++ lib/src/main/cpp/test_items2/through_something.cpp | 8 +- lib/src/main/cpp/test_items2/road_exam.cpp | 24 +++++++- lib/src/main/cpp/test_common/Geometry.h | 2 lib/src/main/cpp/rtk_module/virtual_rtk.cpp | 4 + lib/src/main/cpp/rtk_platform/platform.cpp | 4 + lib/src/main/cpp/test_common/Geometry.cpp | 41 +++++++++++++ 9 files changed, 113 insertions(+), 13 deletions(-) diff --git a/lib/src/main/cpp/native-lib.cpp b/lib/src/main/cpp/native-lib.cpp index 5204dd3..1f47779 100644 --- a/lib/src/main/cpp/native-lib.cpp +++ b/lib/src/main/cpp/native-lib.cpp @@ -251,6 +251,35 @@ return id; } +void PlayRing(void) +{ + JNIEnv *env; + bool ready_in_java_env = false; + + if (sg_jvm->GetEnv((void **)&env, JNI_VERSION_1_6) != JNI_OK) { + // Attach涓荤嚎绋� + if (sg_jvm->AttachCurrentThread(&env, NULL) != JNI_OK) { + LOGE("%s: AttachCurrentThread() failed", __FUNCTION__); + return; + } + } else { + ready_in_java_env = true; + } + + jclass cls = env->GetObjectClass(sg_obj); + jmethodID fun = env->GetMethodID(cls, "PlayBreakRing", "()V"); + + env->CallVoidMethod(sg_obj, fun); + + env->DeleteLocalRef(cls); + + if (!ready_in_java_env) { + //Detach涓荤嚎绋� + if (sg_jvm->DetachCurrentThread() != JNI_OK) { + LOGE("%s: DetachCurrentThread() failed", __FUNCTION__); + } + } +} extern "C" JNIEXPORT void JNICALL Java_com_anyun_exam_lib_RemoteService_startNative(JNIEnv *env, jobject thiz) { diff --git a/lib/src/main/cpp/native-lib.h b/lib/src/main/cpp/native-lib.h index 79e4d61..a088514 100644 --- a/lib/src/main/cpp/native-lib.h +++ b/lib/src/main/cpp/native-lib.h @@ -24,5 +24,6 @@ void DrawScreen(const Polygon *map, const Polygon *car); void SendMsgToMainProc(int cmd, const char *value); int PlayTTS(const char *string, void (*callback)(int)); +void PlayRing(void); #endif //RTKBASESTATION_NATIVE_LIB_H diff --git a/lib/src/main/cpp/rtk_module/virtual_rtk.cpp b/lib/src/main/cpp/rtk_module/virtual_rtk.cpp index 498b0c6..0bf16b7 100644 --- a/lib/src/main/cpp/rtk_module/virtual_rtk.cpp +++ b/lib/src/main/cpp/rtk_module/virtual_rtk.cpp @@ -57,6 +57,7 @@ if (fd > 0) { DEBUG("铏氭嫙骞冲彴杩炴帴鎴愬姛"); + PlayTTS("妯℃嫙鍣ㄨ繛鎺�", NULL); } else { DEBUG("铏氭嫙骞冲彴杩炴帴澶辫触"); } @@ -97,5 +98,8 @@ } free(vs); + + PlayTTS("妯℃嫙鍣ㄦ柇寮�", NULL); + pthread_exit(NULL); } diff --git a/lib/src/main/cpp/rtk_platform/platform.cpp b/lib/src/main/cpp/rtk_platform/platform.cpp index 01b96f1..35d7b4a 100644 --- a/lib/src/main/cpp/rtk_platform/platform.cpp +++ b/lib/src/main/cpp/rtk_platform/platform.cpp @@ -310,6 +310,8 @@ AppTimer_delete(TriggerHeartbeat); AppTimer_delete(RegisterPlatformTimeout); AppTimer_delete(LoginPlatformTimeout); + + PlayTTS("鍩哄噯婧愭柇寮�", NULL); } if (events & PLATFORM_REGISTER_EVT) { DEBUG("PLATFORM_REGISTER_EVT"); @@ -333,6 +335,8 @@ requestPlatformSendRtk = true; AppTimer_delete(TriggerHeartbeat); AppTimer_add(TriggerHeartbeat, D_SEC(30)); + + PlayTTS("鍩哄噯婧愬缓绔�", NULL); } else { platformStatus.login = 0; } diff --git a/lib/src/main/cpp/test_common/Geometry.cpp b/lib/src/main/cpp/test_common/Geometry.cpp index 242f55f..03c9d4b 100644 --- a/lib/src/main/cpp/test_common/Geometry.cpp +++ b/lib/src/main/cpp/test_common/Geometry.cpp @@ -14,6 +14,7 @@ #include <iosfwd> #include <iomanip> #include <sstream> +#include <vector> #include "../jni_log.h" @@ -626,3 +627,43 @@ { return isEqual(p1.X, p2.X) && isEqual(p1.Y, p2.Y); } + +double AvgYaw(std::vector<double> &angles) +{ + double x = 0, y = 0; + double deg = 0; + + for (int i = 0; i < angles.size(); ++i) { + x += sin(toRadians(angles[i])); + y += cos(toRadians(angles[i])); + } + + if (fabs(y) <= EPSILON) { + if (x > EPSILON) { + deg = 90; + } else { + deg = 270; + } + } + else if (fabs(x) <= EPSILON) { + if (y > EPSILON) { + deg = 0; + } else { + deg = 180; + } + } else { + deg = toDegree(atan(fabs(x / y))); + + if (x < -EPSILON && y > EPSILON) { + deg = 360 - deg; + } + else if (x < -EPSILON && y < -EPSILON) { + deg = 180 + deg; + } + else if (x > EPSILON && y < -EPSILON) { + deg = 180 - deg; + } + } + + return deg; +} \ No newline at end of file diff --git a/lib/src/main/cpp/test_common/Geometry.h b/lib/src/main/cpp/test_common/Geometry.h index 399bafb..6ae52a3 100644 --- a/lib/src/main/cpp/test_common/Geometry.h +++ b/lib/src/main/cpp/test_common/Geometry.h @@ -7,6 +7,7 @@ #include <stdint.h> #include <initializer_list> +#include <vector> enum Relation { @@ -64,5 +65,6 @@ PointF Calc3Point(PointF p1, PointF p2, double L, char dir); PointF PointExtend(PointF ori, double length, double yaw); bool IsSamePoint(PointF p1, PointF p2); +double AvgYaw(std::vector<double> &angles); #endif //GUI_GEOMETRY_H diff --git a/lib/src/main/cpp/test_items2/drive_straight.cpp b/lib/src/main/cpp/test_items2/drive_straight.cpp index 94ba625..04ec8fa 100644 --- a/lib/src/main/cpp/test_items2/drive_straight.cpp +++ b/lib/src/main/cpp/test_items2/drive_straight.cpp @@ -39,17 +39,18 @@ if (setup == 1) { // 鍋忚埅瑙掑钩鍧囧�� + static vector<double> yaws; + if (yaw_stat == 0) { - yaw = car->yaw; - } else { - yaw += car->yaw; + yaws.clear(); } + yaws.push_back(car->yaw); yaw_stat++; - DEBUG("瑙掑害鐭 car %f yaw %f", car->yaw, yaw); - if (yaw_stat == 5) { - yaw = fmod(yaw, 360) / 5; + yaw = AvgYaw(yaws); + vector<double>().swap(yaws); + DEBUG("鍒涘缓鍩虹嚎 yaw %f", yaw); PointF extPoint = PointExtend(car->basePoint, 100, yaw); MakeLine(&baseLine, &car->basePoint, &extPoint); diff --git a/lib/src/main/cpp/test_items2/road_exam.cpp b/lib/src/main/cpp/test_items2/road_exam.cpp index 5913dc5..3e4d0c5 100644 --- a/lib/src/main/cpp/test_items2/road_exam.cpp +++ b/lib/src/main/cpp/test_items2/road_exam.cpp @@ -411,7 +411,7 @@ index = 0; } - while (n++ < RoadMap.roads.size()) { + while (n < RoadMap.roads.size()) { bool changeSegment = false; vector<PointF> roadOutLine; Polygon area; @@ -453,6 +453,7 @@ free(area.point); index = (index + 1) % RoadMap.roads.size(); + n++; } if (n >= RoadMap.roads.size()) { @@ -924,12 +925,13 @@ if (newLane.road == Lane.road && newLane.sep == Lane.sep) { gain = newLane.no - Lane.no; } else { + DEBUG("杞﹂亾鍒嗘鍒囨崲"); ChangeLane.gain = 0; } // 妫�鏌ヨ浆鍚戠伅 if (gain != 0) { - DEBUG("鍙橀亾 gain %d", gain); + DEBUG("鍙橀亾 new lane %d, gain %d", newLane.no, gain); car_sensor_value_t lamp = ReadCarSensorValue(TURN_SIGNAL_LAMP); if (lamp.name == TURN_SIGNAL_LAMP) { if (gain < 0) { @@ -1209,6 +1211,19 @@ return guide; } +static void RingBreak(void) +{ + static int oldValue = BREAK_INACTIVE; + car_sensor_value_t brk = ReadCarSensorValue(BREAK); + + if (brk.name == BREAK) { + if (brk.value == BREAK_ACTIVE && oldValue != BREAK_ACTIVE) { + PlayRing(); + } + oldValue = brk.value; + } +} + void TestRoadGeneral(road_exam_map &RoadMap, const car_model *car, LIST_CAR_MODEL &CarModelList, double speed, int moveDirect, const struct RtkTime *rtkTime) { double BigStraightRoadFree = 0, RoadCrossingFree = 0, TargetFree = 0; @@ -1216,6 +1231,9 @@ UpdateCarSensor(rtkTime); UpdataOdo(speed, moveDirect, rtkTime); + + // 鍒硅溅鎻愮ず闊� + RingBreak(); // 瓒呴�熸娴� if (speed > MAX_SPEED) { @@ -1536,7 +1554,7 @@ if (RoadExamStatus == ROAD_EXAM_ITEM_CAR_START) { freeRunExceptDistance = 60.0; } else { - freeRunExceptDistance = 200.0; + freeRunExceptDistance = 250.0; } RoadExamStatus = ROAD_EXAM_FREE_RUN; diff --git a/lib/src/main/cpp/test_items2/through_something.cpp b/lib/src/main/cpp/test_items2/through_something.cpp index f75d5db..2c18908 100644 --- a/lib/src/main/cpp/test_items2/through_something.cpp +++ b/lib/src/main/cpp/test_items2/through_something.cpp @@ -226,18 +226,18 @@ } PointF point2 = CalcProjectionWithRoadEdge(RoadMap.roads[roadIndex].leftEdge, - RoadMap.specialAreas[x].area[1]); - MakeLine(&line, &RoadMap.specialAreas[x].area[1], &point2); + RoadMap.specialAreas[x].area[0]); + MakeLine(&line, &RoadMap.specialAreas[x].area[0], &point2); if (CrashTheLine(line, car, CarModelList)) { if (RoadMap.specialAreas[x].type == ZEBRA_CROSSING && !(it->second & REDUCE_SPEED)) { - DEBUG("涓嶆寜瑙勫畾鍑忛��"); + DEBUG("浜鸿閬� 涓嶆寜瑙勫畾鍑忛��"); AddExamFault(48, rtkTime); } if (RoadMap.specialAreas[x].type == BUS_STATION_AREA && !(it->second & REDUCE_SPEED)) { - DEBUG("涓嶆寜瑙勫畾鍑忛��"); + DEBUG("鍏氦绔� 涓嶆寜瑙勫畾鍑忛��"); AddExamFault(50, rtkTime); } RemoveTargetReduceRec(TargetReduceRec2, it->first); -- Gitblit v1.8.0