计算当前车辆与前车之间的距离

use*_*039 1 c++ omnet++ veins sumo

我需要计算当前车辆和前车之间的距离,对于流动中的每辆车,在边缘上行驶.

在通过TraCI时,我遇到了getLeader方法,该方法应该返回领导者的ID和我需要的距离.

但我找不到一个带有此名称的实现方法,或者在TraCI中用C++编写的概述扩展变量检索中列出的任何其他方法.

如果有人能帮助我,我真的很感激.


我成功地实施getLastStepVehicleIDs作为建议从感应回路中检索值这里.我遵循已经实现的相同类型的方法(例如getJunctionIds),但在这种情况下,找不到这样已经实现的方法.

Mic*_*ael 7

在TraCICommandInterface.cc中有很多可以借用的函数.没有测试,实现可能看起来像这样

std::pair<std:string, double> TraCICommandInterface::getLeader(const double lookahead) {
    TraCIBuffer request;
    request << static_cast<uint8_t>(VAR_LEADER) << nodeId
                    << static_cast<uint8_t>(TYPE_DOUBLE) << lookahead;
    TraCIBuffer response = connection.query(CMD_GET_VEHICLE_VARIABLE, request);

    uint8_t cmdLength; response >> cmdLength;
    if (cmdLength == 0) {
            uint32_t cmdLengthX;
            response >> cmdLengthX;
    }
    uint8_t responseId; response >> responseId;
    ASSERT(responseId == RESPONSE_GET_VEHICLE_VARIABLE);
    uint8_t variable; response >> variable;
    ASSERT(variable == VAR_LEADER);
    std::string id; response >> id;
    uint8_t typeId_r; response >> typeId_r; ASSERT(typeId_r == TYPE_COMPOUND);
    uint32_t compoundLength; response >> compoundLength; ASSERT(compoundLength == 2);
    uint8_t typeId_resp; response >> typeId_resp; ASSERT(typeId_resp == TYPE_STRING);
    std::string leader; response >> leader;
    uint8_t typeId_resp2; response >> typeId_resp2; ASSERT(typeId_resp2 == TYPE_DOUBLE);
    double dist; response >> dist;

    return std::make_pair(leader, dist);
}
Run Code Online (Sandbox Code Playgroud)