工程创新大赛智能网联汽车赛项AEB项目满分开源

#include "SimOneServiceAPI.h"
#include "SimOnePNCAPI.h"
#include "SimOneHDMapAPI.h"
#include "SimOneSensorAPI.h"
#include "SSD/SimPoint3D.h"
#include "UtilMath.h"
#include "hdmap/SampleGetNearMostLane.h"
#include "hdmap/SampleGetLaneST.h"
#include <memory>
#include <limits>
#include <iostream>
#include "SimOneEvaluationAPI.h"
#include <iostream>

//Main function
//
using namespace std;
int main()
{
    bool inAEBState = false;
    bool Forword_people = false;
    bool isSimOneInitialized = false;
    const char* MainVehicleId = "0";
    bool isJoinTimeLoop = true;
    SimOneAPI::InitSimOneAPI(MainVehicleId, isJoinTimeLoop);
    SimOneAPI::SetDriverName(MainVehicleId, "AEB");
    SimOneAPI::SetDriveMode(MainVehicleId, ESimOne_Drive_Mode_API);
    SimOneAPI::InitEvaluationServiceWithLocalData(MainVehicleId);

    int timeout = 20;
    while (true) {
        if (SimOneAPI::LoadHDMap(timeout)) {
            SimOneAPI::SetLogOut(ESimOne_LogLevel_Type::ESimOne_LogLevel_Type_Information, "HDMap Information Loaded");
            break;
        }
        SimOneAPI::SetLogOut(ESimOne_LogLevel_Type::ESimOne_LogLevel_Type_Information, "HDMap Information Loading...");
    }

    while (true) {
        int frame = SimOneAPI::Wait();

        if (SimOneAPI::GetCaseRunStatus() == ESimOne_Case_Status::ESimOne_Case_Status_Stop) {
            SimOneAPI::SaveEvaluationRecord();
            break;
        }

        std::unique_ptr<SimOne_Data_Gps> pGps = std::make_unique<SimOne_Data_Gps>();
        if (!SimOneAPI::GetGps(MainVehicleId, pGps.get())) {
            SimOneAPI::SetLogOut(ESimOne_LogLevel_Type::ESimOne_LogLevel_Type_Warning, "Fetch GPS failed");
        }

        std::unique_ptr<SimOne_Data_Obstacle> pObstacle = std::make_unique<SimOne_Data_Obstacle>();
        if (!SimOneAPI::GetGroundTruth(MainVehicleId, pObstacle.get())) {
            SimOneAPI::SetLogOut(ESimOne_LogLevel_Type::ESimOne_LogLevel_Type_Warning, "Fetch obstacle failed");
        }

        if (SimOneAPI::GetCaseRunStatus() == ESimOne_Case_Status::ESimOne_Case_Status_Running) {
            if (!isSimOneInitialized) {
                SimOneAPI::SetLogOut(ESimOne_LogLevel_Type::ESimOne_LogLevel_Type_Information, "SimOne Initialized!");
                isSimOneInitialized = true;
            }

            SSD::SimPoint3D mainVehiclePos(pGps->posX, pGps->posY, pGps->posZ);
            double mainVehicleSpeed = UtilMath::calculateSpeed(pGps->velX, pGps->velY, pGps->velZ);

            double minDistance = std::numeric_limits<double>::max();
            int potentialObstacleIndex = pObstacle->obstacleSize;
            SSD::SimString mainVehicleLaneId = SampleGetNearMostLane(mainVehiclePos);
            SSD::SimString potentialObstacleLaneId = "";
            for (size_t i = 0; i < pObstacle->obstacleSize; ++i) {
                SSD::SimPoint3D obstaclePos(pObstacle->obstacle[i].posX, pObstacle->obstacle[i].posY, pObstacle->obstacle[i].posZ);
                SSD::SimString obstacleLaneId = SampleGetNearMostLane(obstaclePos);
                if (mainVehicleLaneId == obstacleLaneId) {
                    double obstacleDistance = UtilMath::planarDistance(mainVehiclePos, obstaclePos);

                    if (obstacleDistance < minDistance) {
                        minDistance = obstacleDistance;
                        potentialObstacleIndex = (int)i;
                        potentialObstacleLaneId = obstacleLaneId;
                    }
                }
            }

            auto& potentialObstacle = pObstacle->obstacle[potentialObstacleIndex];
            double obstacleSpeed = UtilMath::calculateSpeed(potentialObstacle.velX, potentialObstacle.velY, potentialObstacle.velZ);


            SSD::SimPoint3D potentialObstaclePos(potentialObstacle.posX, potentialObstacle.posY, potentialObstacle.posZ);
            double sObstalce = 0;
            double tObstacle = 0;

            double sMainVehicle = 0;
            double tMainVehicle = 0;

            bool isObstalceBehind = false;
            bool ObstalceisGoing = false;
            if (!potentialObstacleLaneId.Empty()) {

                SampleGetLaneST(potentialObstacleLaneId, potentialObstaclePos, sObstalce, tObstacle);
                SampleGetLaneST(mainVehicleLaneId, mainVehiclePos, sMainVehicle, tMainVehicle);

                isObstalceBehind = !(sMainVehicle >= sObstalce);
                if (tMainVehicle - tObstacle > 1) {
                    ObstalceisGoing = true;
                }
            }

            std::unique_ptr<SimOne_Data_Control> pControl = std::make_unique<SimOne_Data_Control>();

            // Control mainVehicle with SimOneDriver
            SimOneAPI::GetDriverControl(MainVehicleId, pControl.get());

            // Control mainVehicle without SimOneDriver
            /*pControl->throttle = 0.5;
            pControl->brake = 0;
            pControl->steering = 0;
            pControl->handbrake = 0;
            pControl->isManualGear = 0;
            pControl->gear = static_cast<ESimOne_Gear_Mode>(1);*/

            if (isObstalceBehind && obstacleSpeed != 0) {
                double defaultDistance = 0.1f;
                double timeToCollision = std::abs((minDistance - defaultDistance)) / (obstacleSpeed - mainVehicleSpeed);
                double defautlTimeToCollision = 3.4f;//越大停的越远
                if (-timeToCollision < defautlTimeToCollision && timeToCollision < 0) {
                    inAEBState = true;

                }
                if (inAEBState) {
                    pControl->brake = 1.f;
                    pControl->throttle = 0.;

                    if (mainVehicleSpeed <= 0.5f || std::abs((minDistance - defaultDistance) - defaultDistance) <= 0) {
                        pControl->throttle = 0;
                        pControl->brake = 1;
                    }

                    if (ObstalceisGoing) {
                        pControl->throttle = 0.1f;
                        pControl->brake = 0;
                    }

                }

            }
            if (obstacleSpeed == 0) {
                if (isObstalceBehind) {
                    double defaultDistance = 0.1f;
                    double timeToCollision = std::abs((minDistance - defaultDistance)) / (obstacleSpeed - mainVehicleSpeed);
                    double defautlTimeToCollision = 1.3f;//越大停的越远
                    if (-timeToCollision < defautlTimeToCollision && timeToCollision < 0) {
                        inAEBState = true;

                    }
                    if (inAEBState) {
                        pControl->brake = 1.f;
                        pControl->throttle = 0.;

                        if (mainVehicleSpeed <= 0.5f || std::abs((minDistance - defaultDistance) - defaultDistance) <= 0) {
                            pControl->throttle = 0;
                            pControl->brake = 1;
                        }

                        if (ObstalceisGoing) {
                            pControl->throttle = 0.1f;
                            pControl->brake = 0;
                        }

                    }

                }
            }

            //if (45 < pGps->posX < -45) {
                //double defaultDistance = 2.f;
                //double timeToCollision = std::abs((minDistance - defaultDistance)) / (obstacleSpeed - mainVehicleSpeed);
                //double defautlTimeToCollision = 3.4f;
                //if (-timeToCollision < defautlTimeToCollision && timeToCollision < 0) {
                    //inAEBState = true;
                    //pControl->brake = 1;
                //}
                //if (mainVehicleSpeed <= 1.f) {
                    //pControl->throttle = 0;
                    //pControl->brake = 1;
                //}


            //}

        //}


            SimOneAPI::SetDrive(MainVehicleId, pControl.get());
        }
        else {
            SimOneAPI::SetLogOut(ESimOne_LogLevel_Type::ESimOne_LogLevel_Type_Information, "SimOne Initializing...");
        }

        SimOneAPI::NextFrame(frame);
    }
    return 0;
}
 

全国大学生智能汽车竞赛 设计资料 程序 源代码 复盘资料供参考 全国大学生智能汽车竞赛 设计资料 程序 源代码 复盘资料供参考 全国大学生智能汽车竞赛 设计资料 程序 源代码 复盘资料供参考 全国大学生智能汽车竞赛 设计资料 程序 源代码 复盘资料供参考 全国大学生智能汽车竞赛 设计资料 程序 源代码 复盘资料供参考 全国大学生智能汽车竞赛 设计资料 程序 源代码 复盘资料供参考 全国大学生智能汽车竞赛 设计资料 程序 源代码 复盘资料供参考 全国大学生智能汽车竞赛 设计资料 程序 源代码 复盘资料供参考 全国大学生智能汽车竞赛 设计资料 程序 源代码 复盘资料供参考 全国大学生智能汽车竞赛 设计资料 程序 源代码 复盘资料供参考 全国大学生智能汽车竞赛 设计资料 程序 源代码 复盘资料供参考 全国大学生智能汽车竞赛 设计资料 程序 源代码 复盘资料供参考 全国大学生智能汽车竞赛 设计资料 程序 源代码 复盘资料供参考 全国大学生智能汽车竞赛 设计资料 程序 源代码 复盘资料供参考 全国大学生智能汽车竞赛 设计资料 程序 源代码 复盘资料供参考 全国大学生智能汽车竞赛 设计资料 程序 源代码 复盘资料供参考 全国大学生智能汽车竞赛 设计资料 程序 源代码 复盘资料供参考 全国大学生智能汽车竞赛 设计资料 程序 源代码 复盘资料供参考 全国大学生智能汽车竞赛 设计资料 程序 源代码 复盘资料供参考 全国大学生智能汽车竞赛 设计资料 程序 源代码 复盘资料供参考 全国大学生智能汽车竞赛 设计资料 程序 源代码 复盘资料供参考 全国大学生智能汽车竞赛 设计资料 程序 源代码 复盘资料供参考 全国大学生智能汽车竞赛 设计资料 程序 源代码 复盘资料供参考 全国大学生智能汽车竞赛 设计资料 程序 源代码 复盘资料供参考
### 工程创新大赛中的智能网联汽车赛项开发资源 #### 关于智能网联汽车的技术背景 智能网联汽车是当前汽车行业发展的核心方向之一,其融合了人工智能、大数据分析以及物联网等多项前沿技术。为了支持这一领域的技术创新和发展,“2021首届汽车开发者大会”提出了构建“汽车开发者生态”的倡议[^1]。该倡议旨在通过资源整合和技术共享来促进行业的快速发展。 与此同时,在全球范围内,随着科技革命的深入发展,越来越多的企业和机构参与到智能网联汽车的研究与实践中。例如,由吉利汽车集团、阿里云及 NVIDIA 英伟达联合发起的“2023全球智能汽车AI挑战赛”,进一步强调了自动驾驶、AI大模型等关键技术的重要性,并试图探索这些技术如何更好地服务于未来的智慧交通体系[^2]。 #### 示例代码展示 以下是针对智能网联汽车可能涉及的一些基础功能模块(如路径规划算法)所提供的 Python 实现案例: ```python import numpy as np def calculate_path(start_point, end_point): """ 计算两点之间的最短直线距离并返回一系列中间坐标点。 参数: start_point (tuple): 起始位置(x,y)形式表示. end_point (tuple): 终止位置(x,y)形式表示. 返回值: list[tuple]: 中间经过的所有节点组成的列表. """ num_points = 10 # 假设生成十个均匀分布的关键点 path_coordinates = [] for i in range(num_points + 1): ratio = float(i)/num_points new_x = int((end_point[0]-start_point[0])*ratio)+start_point[0] new_y = int((end_point[1]-start_point[1])*ratio)+start_point[1] path_coordinates.append((new_x,new_y)) return path_coordinates if __name__ == "__main__": starting_location = (0, 0) destination = (50, 75) planned_route = calculate_path(starting_location,destination) print("Planned Route:",planned_route[:]) ``` 上述脚本定义了一个简单的函数 `calculate_path` 来模拟车辆从起点到终点之间创建一条虚拟行驶路线的过程。此方法虽然非常简化,但它可以作为一个入门级的例子帮助理解基本概念。 对于更复杂的场景比如避障或者动态环境下的导航,则需要引入高级别的感知系统配合机器学习框架完成相应任务处理。 #### 可利用的开放平台与工具链推荐 除了编写自定义程序外,还可以考虑借助现有的开源项目或商业软件包来进行快速原型设计: - **CARLA Simulator**: 提供逼真的城市驾驶仿真环境,适合测试各种ADAS特性; - **Apollo Open Platform by Baidu**: 百度推出的全面覆盖硬件接口标准至云端服务的整体解决方案; - **ROS Robotics Operating System**: 广泛应用于机器人控制领域同时也适用于车联网通信协议栈搭建等工作; 以上提到的内容均有助于参赛选手们积累实战经验从而提高竞赛表现水平。
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值