Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何防止自动驾驶解决方案中的过度校正? 我正在用C++中的OpenCV做一个欧洲卡车模拟器2的自主驾驶解决方案。_C++_Opencv - Fatal编程技术网

如何防止自动驾驶解决方案中的过度校正? 我正在用C++中的OpenCV做一个欧洲卡车模拟器2的自主驾驶解决方案。

如何防止自动驾驶解决方案中的过度校正? 我正在用C++中的OpenCV做一个欧洲卡车模拟器2的自主驾驶解决方案。,c++,opencv,C++,Opencv,这里是我们检测道路曲线的位置: int bottom_center = 160; int sum_centerline = 0; int count_centerline = 0; int first_centerline = 0; int last_centerline = 0; double avr_center_to_left = 0; double avr_center_to_right = 0; //#pragma om

这里是我们检测道路曲线的位置:

    int bottom_center = 160;
    int sum_centerline = 0;
    int count_centerline = 0;
    int first_centerline = 0;
    int last_centerline = 0;
    double avr_center_to_left = 0;
    double avr_center_to_right = 0;

    //#pragma omp parallel for
    for (int i = 240; i > 30; i--){
        double center_to_right = -1;
        double center_to_left = -1;

        for (int j = 0; j < 150; j++) {
            if (contours.at<uchar>(i, bottom_center + j) == 112 && center_to_right == -1) {
                center_to_right = j;
            }
            if (contours.at<uchar>(i, bottom_center - j) == 112 && center_to_left == -1) {
                center_to_left = j;
            }
        }
        if (center_to_left != -1 && center_to_right != -1){
            int centerline = (center_to_right - center_to_left + 2 * bottom_center) / 2;
            if (first_centerline == 0) {
                first_centerline = centerline;
            }
            cv::circle(outputImg, Point(centerline, i), 1, Scalar(30, 255, 30), 3);
            cv::circle(outputImg, Point(centerline + center_to_right+20, i), 1, Scalar(255, 30, 30) , 3);
            cv::circle(outputImg, Point(centerline - center_to_left+10, i), 1, Scalar(255, 30, 30) , 3);
            sum_centerline += centerline;
            avr_center_to_left = (avr_center_to_left * count_centerline + center_to_left) / count_centerline + 1;
            avr_center_to_right = (avr_center_to_right * count_centerline + center_to_right) / count_centerline + 1;
            last_centerline = centerline;
            count_centerline++;
        }
        else {}
    }
int-bottom\u-center=160;
int sum_中心线=0;
int count_中心线=0;
int first_中心线=0;
int last_中心线=0;
双avr\u中心到左=0;
双avr_中心到右=0;
//#pragma-omp并行
对于(int i=240;i>30;i--){
双中心到右=-1;
双中心到左=-1;
对于(int j=0;j<150;j++){
如果(等高线在(i,底部中心+j)=112和中心到右侧==-1){
居中至右=j;
}
如果(等高线。在(i,底部\u中心-j)=112和中心\u到左==-1){
中心至左=j;
}
}
如果(居中到左!=-1和居中到右!=-1){
int中心线=(中心到右-中心到左+2*底部到中心)/2;
如果(第一条中心线==0){
第一条中心线=中心线;
}
cv::圆(输出,点(中心线,i),1,标量(30,255,30),3);
cv::圆(输出,点(中心线+中心线到右+20,i),1,标量(255,30,30),3);
cv::圆(输出,点(中心线-中心线到左+10,i),1,标量(255,30,30),3);
中心线总和+=中心线;
avr_中心到左=(avr_中心到左*计数中心线+中心到左)/计数中心线+1;
avr_中心到右=(avr_中心到右*计数中心线+中心到右)/计数中心线+1;
最后的中心线=中心线;
计数中心线++;
}
else{}
}
以下是我目前的转向解决方案:

int diff = 0;
    if (count_centerline != 0) {
        diff = sum_centerline / count_centerline - bottom_center;
        int degree = atan2(last_centerline - first_centerline, count_centerline) * 180 / PI;
        //diff = (90 - degree);

        int move_mouse_pixel = diff;
        cout << "Steer: " << move_mouse_pixel << "px ";
        if (diff <= 20 || diff >= -20){
            SetCursorPos(pt.x + (move_mouse_pixel / 10), height / 2);
        }
        else{
            SetCursorPos(pt.x + (move_mouse_pixel / 25), height / 2);
        }
    }
int-diff=0;
如果(计数中心线!=0){
diff=总和中心线/计数中心线-底部中心线;
int DEGRE=atan2(最后一条中心线-第一条中心线,计数中心线)*180/PI;
//差异=(90度);
int move_mouse_pixel=diff;

我相信PID控制器将适合这项任务。 在您的情况下,它看起来类似于:

            diffOld = diff;
            diff = sum_centerline / count_centerline - bottom_center;
            SetCursorPos(width/2 + Kp* diff + Kd*(diff - diffOld) , height / 2);

不要在此控制器中使用if语句。即使没有错误,您也需要保持转向。我建议跳过积分部分,因为您的对象积分(当您不直行时,积分错误)。您需要通过实验选择Kp和Kd参数的值,例如使用Ziegler–Nichols方法。

我认为a可能有用。@BrianLittlefield相关:。有一节<代码>9.2。转向控制
可能有用。好的,谢谢您提供的信息!我将对此进行研究。