计算当前车辆与前车之间的距离 [英] Calculating the distance between the current vehicle and the preceding vehicle

查看:83
本文介绍了计算当前车辆与前车之间的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have needed to calculate the distance between the current vehicle and the preceding vehicle,for each vehicle in a flow, running on an edge.

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

While going through TraCI, I came across getLeader method which is supposed to return the Id of the leader and the distance I need.

但我找不到具有此名称的已实现方法,或 扩展变量检索概述 用 TraCI 中的 C++ 编写.

But I could not find a implemented method with this name, or any of the other method listed under Overview Extended Variables Retrieval written in C++ in TraCI.

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

I really appreciate if someone can help me with this.

我成功地实施了 getLastStepVehicleIDs 以按照建议从归纳循环中检索值此处.我遵循了已实现的相同类型的方法(例如 getJunctionIds),但在这种情况下,找不到此类已实现的方法.

I was successful in implementing getLastStepVehicleIDs to retrieve values from induction loops as advised here. I followed the already implemented methods of the same type (e.g. getJunctionIds), but in this case no such already implemented methods can be found.

推荐答案

TraCICommandInterface.cc 中有很多功能可以借用.如果没有测试,实现可能看起来像这样

There are plenty of functions to borrow from in TraCICommandInterface.cc. Without testing an implementation could look like this

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);
}

这篇关于计算当前车辆与前车之间的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆