我需要为流中的每辆车计算当前车辆与前车之间的距离,在边缘上行驶。
在使用 TraCI 时,我遇到了 getLeader应该返回领导者 ID 和我需要的距离的方法。
但我找不到具有此名称的已实现方法,或 Overview Extended Variables Retrieval 下列出的任何其他方法 在 TraCI 中用 C++ 编写。
如果有人能帮助我,我将不胜感激。
我成功实现了 getLastStepVehicleIDs按照建议从感应回路中检索值 here .我遵循了相同类型的已实现方法(例如 getJunctionIds),但在这种情况下找不到此类已实现的方法。
最佳答案
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);
}
关于c++ - 计算当前车辆与前车之间的距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48249351/