yy1717
2020-10-23 c484cbb09d445e2ab30ea011c6d2ffd87202bb26
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// Created by YY on 2020/3/23.
//
 
#include "drive_straight.h"
#include "../driver_test.h"
#include "../native-lib.h"
#include "../jni_log.h"
#include "road_exam.h"
#include "../master/comm_if.h"
#include "../common/apptimer.h"
#include "../test_common/odo_graph.h"
#include <cmath>
 
#define DEBUG(fmt, args...)     LOGD("<road_exam drive_straight> <%s>: " fmt, __func__, ##args)
 
static int setup;
static double beginOdo;
static int yaw_stat;
static double offsetBase;
 
static void TtsBack(int seq)
{
    setup = 1;
}
 
void StartDriveStraightExam(void) {
    DEBUG("开始直线行驶");
    setup = 0;
    yaw_stat = 0;
    PlayTTS(examParam.straight_begin_tts, TtsBack);
}
 
bool TestDriveStraight(road_exam_map &RoadMap, int roadIndex, const car_model *car, const struct RtkTime *rtkTime) {
    static double yaw;
    static Line baseLine;
    static double offset1, offset2;
 
    if (roadIndex < 0 || roadIndex >= RoadMap.roads.size())
        return false;
 
    if (setup == 1) {
        // 偏航角平均值
        static vector<double> yaws;
 
        if (yaw_stat == 0) {
            yaws.clear();
        }
        yaws.push_back(car->yaw);
        yaw_stat++;
 
        if (yaw_stat == 15) {
            yaw = AvgYaw(yaws);
            vector<double>().swap(yaws);
 
            DEBUG("创建基线 yaw %f", yaw);
            PointF extPoint = PointExtend(car->basePoint, 100, yaw);
            MakeLine(&baseLine, &car->basePoint, &extPoint);
            beginOdo = ReadOdo();
 
            PointF px = CalcProjectionWithRoadEdge(RoadMap.roads[roadIndex].rightEdge, car->carXY[car->axial[AXIAL_FRONT]]);
            offsetBase = DistanceOf(px, car->carXY[car->axial[AXIAL_FRONT]]);
            DEBUG("起点偏离 %f", offsetBase);
 
            setup = 2;
        }
    } else if (setup == 2) {
        offset1 = DistanceOf(car->carXY[car->axial[AXIAL_FRONT]], baseLine);
 
        if (offset1 > examParam.straight_max_offset) {
            DEBUG("虚拟直线偏移大于30厘米 offset1 = %f", offset1);
//            // 偏移大于30厘米,不合格
//            AddExamFault(30, rtkTime);
//            return false;
        }
 
        PointF px = CalcProjectionWithRoadEdge(RoadMap.roads[roadIndex].rightEdge, car->carXY[car->axial[AXIAL_FRONT]]);
        offset2 = DistanceOf(px, car->carXY[car->axial[AXIAL_FRONT]]);
 
        if (fabs(offset2 - offsetBase) > examParam.straight_max_offset) {
            DEBUG("直线偏移大于30厘米 offset2 = %f", fabs(offset2 - offsetBase));
            // 偏移大于30厘米,不合格
            AddExamFault(30, rtkTime);
            return false;
        }
    }
 
    if (setup == 2 && ReadOdo() - beginOdo > examParam.straight_limit_distance) {
        DEBUG("直线行驶结束 offset1 = %f offset2 = %f", offset1, fabs(offset2 - offsetBase));
 
        PlayTTS(examParam.straight_end_tts, NULL);
        return false;
    }
 
    return true;
}