Transmission of vehicular status in Veins

允我心安 提交于 2019-12-01 15:30:50
user4786271

To achieve your goal you have to use the TraCIMobility component of Veins.

You can do that by first getting a pointer to that component in the initialize() method of your node

cModule *tmpMobility = getParentModule()->getSubmodule("veinsmobility");
mobility = dynamic_cast<Veins::TraCIMobility*>(tmpMobility);
ASSERT(mobility);

Once you have the mobility component you can query it for various data.

The type of data that it can provide can be found in TraCIMobility.h

For example in your case you could do:

mobility->getCurrentSpeed().length()); /* will provide velocity vector */
mobility->getAngleRad()); /* will provide angle of movement */

Then you can attach this data to your message and send it to the RSU of your choice.


If this exact solution does not work for you that could be due to me using a different Veins version than yours.

However you will certainly find what you need in TraCIDemo11p.cc or TraCIDemoRSU.cc of your Veins project.

Also, TraCICommandInterface is something you should have a look at.


In the official Veins website under the Documentation section it is said:

Application modules can use the TraCICommandInterface class and related classes, conveniently accessible from TraCIMobility, to interact with the running simulation. The following example shows how to make a vehicle aware of slow traffic on a road called Second Street, potentially causing it to change its route to avoid this road.

mobility = TraCIMobilityAccess().get(getParentModule());
traci = mobility->getCommandInterface();
traciVehicle = mobility->getVehicleCommandInterface();
traciVehicle->changeRoute("Second Street", 3600);

Some of the other vehicle related commands are setSpeed or setParking. Similar methods are available for the whole simulation (e.g., addVehicle, addPolygon), roads (getMeanSpeed), individual lanes (getShape), traffic lights (setProgram), polygons (setShape), points of interest, junctions, routes, vehicle types, or the graphical user interface.

How to use these modules is demonstrated in the source code of the Veins tutorial example. Again, a list of all 80+ available methods can be found in TraCICommandInterface.h or the autogenerated module documentation.

A potentially related question/answer here: https://stackoverflow.com/a/29918148/4786271

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!