-1

I want to transmit a given car's vehicular data such as it's vType, instantaneous speed and position to a RSU in a scenario in Veins.

How can I obtain the data from SUMO and send it through MiXiM methods to an RSU node?

Julian Heinovski
  • 1,822
  • 3
  • 16
  • 27
AayDee
  • 181
  • 12
  • What have you tried so far? Your question is a bit too broad. Please clarify and provide a [minimal example](http://stackoverflow.com/help/mcve). – Kryptos Jun 05 '15 at 13:17
  • I have studied certain examples to use MiXiM and TraCI for OMNeT++ and SUMO, respectively. – AayDee Jun 05 '15 at 14:11
  • But I am unable to determine how I can identify the instantaneous speed and position of a car through TraCI Python API. Also, can I use this data in Veins? – AayDee Jun 05 '15 at 14:12
  • Ok, so I found out the commands in TraCI Python API to extract the vehicle's speed, position, roadID and vType. My question is how do I do this within the Veins framework and how do I transmit this data from the car node to another node. – AayDee Jun 05 '15 at 14:18

1 Answers1

3

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

Community
  • 1
  • 1
user4786271
  • 1,555
  • 13
  • 18
  • Thanks a lot. I shall check out the commands. Thanks again. :) – AayDee Jun 08 '15 at 07:43
  • A very simple help, please. I have created my .msg file. Where do I write the initialization and update statements for a message? The nodes here get derived from the MiXiM base node modules, right? – AayDee Jun 08 '15 at 09:17
  • usually the connection to external modules happens in the initialization phase, that is, within the `initialize()` function of your `.cc` file. Also the update statements should be written in the `.cc` file of your application, based on the condition you want to perform the update. This tutorial will help you understand how the initialization and message handling and creation work: https://omnetpp.org/doc/omnetpp/tictoc-tutorial/ – user4786271 Jun 08 '15 at 11:13
  • Yes, I have already went through the tutorials. My question was that in these tutorials, we actually write a new .cc file for each simple module that we create. But when I'm using Veins, or even MiXiM, I don't need to write the .cc files as I'm using the Base mobility node modules. In that case, I was asking for which .cc file I need to write the code and in which functions? Should I be writing new .cc files and inherit some classes or something? I tried this with an example in MiXiM but I seemed to hit a dead end about which classes to inherit. – AayDee Jun 08 '15 at 11:53
  • playing around with the existing module's code is not a good idea, because there might be some legacy behaviour which should not be modified. Your best bet would be to create `.cc` & `.h` file of your own, where you will take the code of the `*Demo*.cc` as foundation. For example you can start from `TraCIDemo11p.cc` and then modify it according to your needs. – user4786271 Jun 08 '15 at 14:16
  • Thanks for the advice. I'll keep that in mind. And could you advise me on sending the data through some message as well? For example, let's say that I have been able to obtain the current speed of the car and I want to send it to some other node. Where should I embed my data so that it can be sent as a payload? I think I have to use the WaveShortMessage class, is it? – AayDee Jun 08 '15 at 14:26
  • When you create your `.msg` file, OMNeT++ generates header (.h) and implementation (.cc) file automatically. In the .cc file of your message you have `get()` and `set()` methods for each field that you have defined in your msg. For example if you have a field called `destinationAddress`, you can set the data in this field by doing `myMsg->setDestinationAddress(some_address)`. If you recap on the TicToc tutorial you will remember there was a line like: `msg->getName()`. The principle is the same. This data can be read on the receiving party by doing `msg->getWhateverField()` – user4786271 Jun 08 '15 at 15:11
  • Yes, that's true. But I meant the source file of the module where I have to implement the handleMessage() or whatever function. For example, do I have to generate this message in the Application layer or at the Physical layer or something, that's what I meant. Sorry if I was being unclear on that. – AayDee Jun 09 '15 at 07:04
  • you are looking for `vType` , `speed` and `position` none of these info belongs to the lower layers of the network stack. These data is application specific in my opinion. So generating message in the .cc file of your application is the best. You can design your message to extend the `WaveShortMessage` and add the fields that you need there. This way the message will be compatible with the lower layers, while serving your purpose in the app layer. – user4786271 Jun 09 '15 at 09:09
  • Thanks for the insight. I shall modify TraciDemo11p itself and extend WSM to see how it goes. – AayDee Jun 09 '15 at 11:51