如何在VEINS中获取每辆车的坐标? [英] How to get Coordinates of each vehicle in VEINS?

查看:252
本文介绍了如何在VEINS中获取每辆车的坐标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Veins 4.6,Sumo 0.25和Omnet ++ 5.2.我需要获取给定时间的两个车辆(节点)的坐标,以计算它们之间的距离.

I am using Veins 4.6, Sumo 0.25 and Omnet++ 5.2. I need to get the coordinates of two vehicles (nodes) at a given time, to calculate the distance between them.

我试图在handlePositionUpdate()函数中修改TraCIDemo11p.cc文件.问题在于,当veh0同时返回其坐标时,veh1发送的坐标非常小.

I have tried to modify the TraCIDemo11p.cc file in the function handlePositionUpdate(). The Problem is when the veh0 returns its coordinate at the same time there is coordinate sent by veh1 which is very small.

如何获取给定时间的两辆车的位置并找到它们之间的距离?

void TraCIDemo11p :: handlePositionUpdate(cObject* obj) {

    BaseWaveApplLayer::handlePositionUpdate(obj);

    // Get vehicle ID
    std::string vehID = mobility->getExternalId().c_str();

    // Get coordinates of first vehicle
    if (vehID == "veh0"){
        firstVehX = mobility->getCurrentPosition().x;
        firstVehY = mobility->getCurrentPosition().y;
        firstVehZ = mobility->getCurrentPosition().z;
        calculateDistance(vehID, firstVehX, firstVehY,firstVehZ);
    }   

    //Get coordinates of second vehicle
    if (vehID == "veh1"){
        secondVehX = mobility->getCurrentPosition().x;
        secondVehY = mobility->getCurrentPosition().y;
        secondVehZ = mobility->getCurrentPosition().z;

        calculateDistance(vehID, secondVehX, secondVehY, secondVehZ);

    }
}

推荐答案

据我了解,您想计算此代码所运行的车辆到其他车辆的距离.但是,我不确定这辆其他车辆是什么.例如是firstVeh吗?

As far as I understood, you want to calculate the distance from the vehicle this code is running on to some other car. However, I am not sure what this other vehicle is. Is it firstVeh for instance?

如果是这种情况,那么使用此代码,您将无法实现所需的功能(如您已经弄清楚的那样).该代码在模拟中的每辆车上运行,但独立于所有其他车.因此,mobility仅指向运行此代码的当前车辆的机动性模块.因此,mobility->getCurrentPosition()始终只会为您提供恰好这辆车的位置.

If this is the case, with this code you can not have achieve what you want (as you figured out already). This code runs on every vehicle in the simulation but is independent from all other vehicles. Therefore, mobility points only to the mobility module of the current vehicle this code is running on. Thus, mobility->getCurrentPosition() always gives you only the position of exactly this vehicle.

例如,用于计算到firstVeh的距离,您需要其坐标.但是,通常情况下,您对模拟中的其他任何车辆都不了解,除非您从其中收到包含其位置的消息(请参阅

For calculating the distance to firstVeh for example, you need its coordinates. Usually, however, you do not have any knowledge about arbitrary other vehicles in the simulation, unless you receive a message from them which includes its position (see Calculating distance between cars nodes VEINS).

如果您确实需要计算与其他任意车辆的距离(即,不是上述消息的发件人),则可以从如何获取特定范围内的汽车数量).但是,在我看来,这是一种不好的做法,因为实际上,除了消息的某些发件人之外,您也不会意识到场景中的其他任何汽车.

If you really need to calculate the distance to an other, arbitrary vehicle (i.e. not an aforementioned sender of a message), you could get a pointer to that vehicle from the TraCIScenarioManager (see How to get count of cars in specific range). This, however, is bad practice in my opinion, since in reality you would not be aware of any other cars in the scenario, other than some sender of a message, either.

这篇关于如何在VEINS中获取每辆车的坐标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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