| | |
| | | |
| | | Relation IntersectionOf(Line line1, Line line2) |
| | | { |
| | | // Fail if either line segment is zero-length. |
| | | if ((isEqual(line1.X1, line1.X2) && isEqual(line1.Y1, line1.Y2)) || (isEqual(line2.X1, line2.X2) && isEqual(line2.Y1, line2.Y2))) |
| | | return GM_None; |
| | | |
| | |
| | | if ((isEqual(line1.X1, line2.X2) && isEqual(line1.Y1, line2.Y2)) || (isEqual(line1.X2, line2.X2) && isEqual(line1.Y2, line2.Y2))) |
| | | return GM_Intersection; |
| | | |
| | | // 直线坐标变换重合 |
| | | // (1) Translate the system so that point A is on the origin. |
| | | line1.X2 -= line1.X1; line1.Y2 -= line1.Y1; |
| | | line2.X1 -= line1.X1; line2.Y1 -= line1.Y1; |
| | | line2.X2 -= line1.X1; line2.Y2 -= line1.Y1; |
| | | |
| | | // Discover the length of segment A-B. |
| | | double distAB = sqrt(line1.X2 * line1.X2 + line1.Y2 * line1.Y2); |
| | | |
| | | // 旋转到X轴 |
| | | // (2) Rotate the system so that point B is on the positive X axis. |
| | | double theCos = line1.X2 / distAB; |
| | | double theSin = line1.Y2 / distAB; |
| | | double newX = line2.X1 * theCos + line2.Y1 * theSin; |
| | |
| | | line2.Y2 = line2.Y2 * theCos - line2.X2 * theSin; |
| | | line2.X2 = newX; |
| | | |
| | | // Fail if segment C-D doesn't cross line A-B. |
| | | if ((line2.Y1 < 0 && line2.Y2 < 0) || (line2.Y1 >= 0 && line2.Y2 >= 0)) { |
| | | return GM_None; |
| | | } |
| | | |
| | | // (3) Discover the position of the intersection point along line A-B. |
| | | double posAB = line2.X2 + (line2.X1 - line2.X2) * line2.Y2 / (line2.Y2 - line2.Y1); |
| | | |
| | | // Fail if segment C-D crosses line A-B outside of segment A-B. |
| | | if (posAB < 0 || posAB > distAB) { |
| | | return GM_None; |
| | | } |
| | | |
| | | // (4) Apply the discovered position to line A-B in the original coordinate system. |
| | | return GM_Intersection; |
| | | } |
| | | |
| | |
| | | return p4; |
| | | } |
| | | |
| | | /************************************************************** |
| | | * p3于 p1---p2构成直线 |
| | | * @param p1 |
| | | * @param p2 |
| | | * @param p3 |
| | | * @return |
| | | */ |
| | | bool VerticalPointOnLine(PointF point, Line line) |
| | | { |
| | | PointF p1, p2; |
| | | |
| | | p1.X = line.X1; |
| | | p1.Y = line.Y1; |
| | | |
| | | p2.X = line.X2; |
| | | p2.Y = line.Y2; |
| | | |
| | | PointF pv = GetVerticalPoint(p1, p2, point); |
| | | |
| | | if (isEqual2(pv.X, MIN(p1.X, p2.X)) || isEqual2(pv.X, MAX(p1.X, p2.X)) || |
| | | (pv.X > MIN(p1.X, p2.X) && pv.X < MAX(p1.X, p2.X))) { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /**************************************************************** |
| | | * p3 |
| | | * | 'L' |
| | |
| | | bool OutsidePolygon(const Polygon *t1, const Polygon *t2); |
| | | int IntersectionOfLine(PointF p1, PointF p2, PointF p3); |
| | | PointF GetVerticalPoint(PointF p1, PointF p2, PointF p3); |
| | | bool VerticalPointOnLine(PointF point, Line line); |
| | | PointF Calc3Point(PointF p1, PointF p2, double L, char dir); |
| | | |
| | | #endif //GUI_GEOMETRY_H |
| | |
| | | ExecuteExam(CurrExamMapIndex, AreaMapList, car, CarModelList, speed, moveDirect, azimuth, rtkTime); |
| | | } |
| | | |
| | | void DistanceOfTire2X(std::vector<double> &array, const car_model *car, std::vector<Line> line_set) |
| | | { |
| | | double ld = 100, rd = 100; |
| | | |
| | | array.clear(); |
| | | |
| | | for (auto line = line_set.begin(); line != line_set.end(); line++) { |
| | | double ld_t = 100, rd_t = 100; |
| | | double d; |
| | | if (VerticalPointOnLine(car->carXY[car->left_front_tire[TIRE_OUTSIDE]], *line)) { |
| | | d = DistanceOf(car->carXY[car->left_front_tire[TIRE_OUTSIDE]], *line); |
| | | if (d < ld_t) { |
| | | ld_t = d; |
| | | } |
| | | } |
| | | if (VerticalPointOnLine(car->carXY[car->left_rear_tire[TIRE_OUTSIDE]], *line)) { |
| | | d = DistanceOf(car->carXY[car->left_rear_tire[TIRE_OUTSIDE]], *line); |
| | | if (d < ld_t) { |
| | | ld_t = d; |
| | | } |
| | | } |
| | | |
| | | if (VerticalPointOnLine(car->carXY[car->right_front_tire[TIRE_OUTSIDE]], *line)) { |
| | | d = DistanceOf(car->carXY[car->right_front_tire[TIRE_OUTSIDE]], *line); |
| | | if (d < rd_t) { |
| | | rd_t = d; |
| | | } |
| | | } |
| | | if (VerticalPointOnLine(car->carXY[car->right_rear_tire[TIRE_OUTSIDE]], *line)) { |
| | | d = DistanceOf(car->carXY[car->right_rear_tire[TIRE_OUTSIDE]], *line); |
| | | if (d < rd_t) { |
| | | rd_t = d; |
| | | } |
| | | } |
| | | |
| | | if (isEqual2(ld_t, rd_t)) { |
| | | if (!isEqual(ld_t, 100)) { |
| | | if (rd_t < rd) |
| | | rd = rd_t; |
| | | if (ld_t < ld) |
| | | ld = ld_t; |
| | | } |
| | | } else if (ld_t > rd_t) { |
| | | if (rd_t < rd) |
| | | rd = rd_t; |
| | | } else { |
| | | if (ld_t < ld) |
| | | ld = ld_t; |
| | | } |
| | | } |
| | | |
| | | array.push_back(ld); |
| | | array.push_back(rd); |
| | | } |
| | | |
| | | static void DetectEnterOrExitMap(const car_model *car, LIST_CAR_MODEL &CarModelList, LIST_AREA_MAP &mapList) |
| | | { |
| | | if (CurrExamMapIndex < 0) { |
| | |
| | | #ifndef MYAPPLICATION2_AREA_EXAM_H |
| | | #define MYAPPLICATION2_AREA_EXAM_H |
| | | |
| | | #include <vector> |
| | | #include "../driver_test.h" |
| | | |
| | | void InitAreaExam(void); |
| | | void TerminateAreaExam(void); |
| | | void TestAreaGeneral(LIST_AREA_MAP &AreaMapList, const car_model *car, LIST_CAR_MODEL &CarModelList, double speed, int moveDirect, double azimuth, const struct RtkTime *rtkTime); |
| | | void DistanceOfTire2X(std::vector<double> &array, const car_model *car, std::vector<Line> line_set); |
| | | |
| | | #endif //MYAPPLICATION2_AREA_EXAM_H |
| | |
| | | #include "../utils/xconvert.h" |
| | | #include "../master/comm_if.h" |
| | | #include "../native-lib.h" |
| | | #include "area_exam.h" |
| | | |
| | | #include <vector> |
| | | #include <cstdlib> |
| | |
| | | { |
| | | Polygon tireRect; |
| | | int who = 0; |
| | | vector<double> dtox; |
| | | vector<Line> line_set; |
| | | int s; |
| | | |
| | | MakePolygon(&tireRect, {car->carXY[car->left_front_tire[TIRE_OUTSIDE]], |
| | | car->carXY[car->right_front_tire[TIRE_OUTSIDE]], |
| | | car->carXY[car->right_rear_tire[TIRE_OUTSIDE]], |
| | |
| | | // 更新车尾扫描线 |
| | | UpdateEndLine(false, &scanWindow, map, map2, &tireRect); |
| | | |
| | | // 计算边距 |
| | | s = scanWindow.leftStart; |
| | | for (int e = scanWindow.leftStart - 1; e >= scanWindow.leftEnd; --e) { |
| | | Line redLine; |
| | | MakeLine(&redLine, &map->point[s], &map->point[e]); |
| | | line_set.push_back(redLine); |
| | | s = e; |
| | | } |
| | | |
| | | s = scanWindow.rightStart; |
| | | for (int e = scanWindow.rightStart - 1; e >= scanWindow.rightEnd; --e) { |
| | | Line redLine; |
| | | MakeLine(&redLine, &map2->point[s], &map2->point[e]); |
| | | line_set.push_back(redLine); |
| | | s = e; |
| | | } |
| | | |
| | | DistanceOfTire2X(dtox, car, line_set); |
| | | |
| | | MA_SendDistance(dtox[0], dtox[1]); |
| | | |
| | | DEBUG("scanWindow leftStart %d leftEnd %d rightStart %d rightEnd %d", scanWindow.leftStart, scanWindow.leftEnd, scanWindow.rightStart, scanWindow.rightEnd); |
| | | |
| | | if (CrashRedLine(map, map2, car, &scanWindow, who)) { |
| | |
| | | #include "../driver_test.h" |
| | | #include "../utils/xconvert.h" |
| | | #include "../master/comm_if.h" |
| | | #include "area_exam.h" |
| | | #include <vector> |
| | | #include <cstdlib> |
| | | |
| | |
| | | char crossCtrlLine = 0; |
| | | uint32_t tp = TimeMakeComposite(rtkTime->hh, rtkTime->mm, rtkTime->ss, rtkTime->mss*10); |
| | | int who = 0; |
| | | vector<double> dtox; |
| | | vector<Line> line_set; |
| | | Line distance_line; |
| | | |
| | | if (ExitParkArea(map, car)) { |
| | | DEBUG("离开场地"); |
| | |
| | | goto TEST_END; |
| | | } |
| | | |
| | | // 距离检测 |
| | | MakeLine(&distance_line, &map->point[0], &map->point[7]); |
| | | line_set.push_back(distance_line); |
| | | MakeLine(&distance_line, &map->point[1], &map->point[2]); |
| | | line_set.push_back(distance_line); |
| | | MakeLine(&distance_line, &map->point[2], &map->point[3]); |
| | | line_set.push_back(distance_line); |
| | | MakeLine(&distance_line, &map->point[3], &map->point[4]); |
| | | line_set.push_back(distance_line); |
| | | MakeLine(&distance_line, &map->point[4], &map->point[5]); |
| | | line_set.push_back(distance_line); |
| | | MakeLine(&distance_line, &map->point[5], &map->point[6]); |
| | | line_set.push_back(distance_line); |
| | | DistanceOfTire2X(dtox, car, line_set); |
| | | MA_SendDistance(dtox[0], dtox[1]); |
| | | |
| | | if (CrashRedLine(map, car, who)) { |
| | | if (!occurCrashRedLine && reverseCar) { |
| | |
| | | #include "../utils/xconvert.h" |
| | | #include "../test_common/car_sensor.h" |
| | | #include "../master/comm_if.h" |
| | | #include "area_exam.h" |
| | | |
| | | #include <vector> |
| | | #include <cstdlib> |
| | |
| | | |
| | | int TestParkEdge(const Polygon *map, const car_model *car, const car_model *carPrev, double speed, int moveStatus, const struct RtkTime *rtkTime) |
| | | { |
| | | vector<double> dtox; |
| | | vector<Line> line_set; |
| | | Line distance_line; |
| | | |
| | | if (CrashRedLine1(map, car)) { |
| | | if (!occurCrashRedLine1 && occurMoveBack) { |
| | | // 车轮压边线,每次扣10分 |
| | |
| | | goto TEST_END; |
| | | } |
| | | |
| | | // 距离检测 |
| | | MakeLine(&distance_line, &map->point[0], &map->point[7]); |
| | | line_set.push_back(distance_line); |
| | | MakeLine(&distance_line, &map->point[1], &map->point[2]); |
| | | line_set.push_back(distance_line); |
| | | MakeLine(&distance_line, &map->point[2], &map->point[3]); |
| | | line_set.push_back(distance_line); |
| | | MakeLine(&distance_line, &map->point[3], &map->point[4]); |
| | | line_set.push_back(distance_line); |
| | | MakeLine(&distance_line, &map->point[4], &map->point[5]); |
| | | line_set.push_back(distance_line); |
| | | MakeLine(&distance_line, &map->point[5], &map->point[6]); |
| | | line_set.push_back(distance_line); |
| | | DistanceOfTire2X(dtox, car, line_set); |
| | | MA_SendDistance(dtox[0], dtox[1]); |
| | | |
| | | if (occurMoveBack) { |
| | | uint32_t tp = TimeMakeComposite(rtkTime->hh, rtkTime->mm, rtkTime->ss, rtkTime->mss*10); |
| | | |
| | |
| | | #include "../utils/xconvert.h" |
| | | #include "../test_common/car_sensor.h" |
| | | #include "../master/comm_if.h" |
| | | #include "area_exam.h" |
| | | |
| | | #define DEBUG(fmt, args...) LOGD("<stop_and_start> <%s>: " fmt, __func__, ##args) |
| | | |
| | |
| | | testing = false; |
| | | } |
| | | |
| | | // 距离检测 |
| | | { |
| | | double dis2 = DistanceOfTire2Edge(map, car); |
| | | vector<double> dtox; |
| | | vector<Line> line_set; |
| | | Line distance_line; |
| | | |
| | | MA_SendDistance(DistanceOf(map->point[8], map->point[7]) - dis2, dis2); |
| | | MakeLine(&distance_line, &map->point[0], &map->point[8]); |
| | | line_set.push_back(distance_line); |
| | | DistanceOfTire2X(dtox, car, line_set); |
| | | MA_SendDistance(dtox[0], dtox[1]); |
| | | } |
| | | |
| | | if (prevMoveDirect != moveDirect) { |
| | |
| | | #include "../defs.h" |
| | | #include "../test_common/car_sensor.h" |
| | | #include "../master/comm_if.h" |
| | | #include "area_exam.h" |
| | | |
| | | #include <vector> |
| | | #include <cstdlib> |
| | |
| | | int TestTurnA90(const Polygon *map, const car_model *car, const car_model *carPrev, double heading, double speed, int moveDirect, const struct RtkTime *rtkTime) |
| | | { |
| | | int az = (int) heading; |
| | | vector<double> dtox; |
| | | vector<Line> line_set; |
| | | Line distance_line; |
| | | |
| | | if (ExitTestArea(map, car)) { |
| | | testing = false; |
| | | goto TEST_END; |
| | | } |
| | | |
| | | // 距离检测 |
| | | MakeLine(&distance_line, &map->point[0], &map->point[5]); |
| | | line_set.push_back(distance_line); |
| | | MakeLine(&distance_line, &map->point[5], &map->point[4]); |
| | | line_set.push_back(distance_line); |
| | | MakeLine(&distance_line, &map->point[1], &map->point[2]); |
| | | line_set.push_back(distance_line); |
| | | MakeLine(&distance_line, &map->point[2], &map->point[3]); |
| | | line_set.push_back(distance_line); |
| | | DistanceOfTire2X(dtox, car, line_set); |
| | | MA_SendDistance(dtox[0], dtox[1]); |
| | | |
| | | if (CrashRedLine(map, car)) { |
| | | if (!crashRedLine) { |
| | | crashRedLine = true; |
| | |
| | | package com.anyun.exam.lib; |
| | | |
| | | import android.app.Service; |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.content.SharedPreferences; |
| | | import android.database.Cursor; |
| | | import android.media.AudioManager; |
| | | import android.media.MediaPlayer; |
| | | import android.media.Ringtone; |
| | | import android.media.RingtoneManager; |
| | | import android.net.Uri; |
| | | import android.os.IBinder; |
| | | import android.os.Process; |
| | | import android.os.RemoteCallbackList; |
| | |
| | | import androidx.annotation.Nullable; |
| | | |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.util.ArrayList; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | |
| | | /** |
| | |
| | | new Thread(new StartNative()).start(); |
| | | |
| | | new Thread(new TestThread()).start(); |
| | | |
| | | PlayRing(this); |
| | | } |
| | | |
| | | public void PlayRing(Context context) { |
| | | RingtoneManager ringtoneManager= new RingtoneManager(context); // 铃声管理器 |
| | | |
| | | for (int i = 0; i < ringtoneManager.getCursor().getCount(); i++) { |
| | | Log.i(TAG, "铃声名称 " + ringtoneManager.getRingtone(i).getTitle(context)); |
| | | |
| | | if (ringtoneManager.getRingtone(i).getTitle(this).equals("Carina")) { |
| | | Log.d(TAG, "播放铃声"); |
| | | |
| | | final MediaPlayer mediaPlayer = new MediaPlayer(); |
| | | Uri src = ringtoneManager.getRingtoneUri(i); |
| | | |
| | | try { |
| | | mediaPlayer.setDataSource(context, src); |
| | | mediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); |
| | | mediaPlayer.setLooping(false); |
| | | mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { |
| | | @Override |
| | | public void onCompletion(MediaPlayer mp) { |
| | | // 在播放完毕被回调 |
| | | Log.d(TAG, "播放完成"); |
| | | mediaPlayer.stop(); |
| | | mediaPlayer.release(); |
| | | } |
| | | }); |
| | | |
| | | mediaPlayer.prepareAsync(); |
| | | mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { |
| | | @Override |
| | | public void onPrepared(MediaPlayer mp) { |
| | | // 装载完毕回调 |
| | | Log.d(TAG, "装载完毕回调"); |
| | | mediaPlayer.start(); |
| | | } |
| | | }); |
| | | |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | class TestThread implements Runnable { |