0

I was wondering how can I start writing a program able to send message when a vehicle is close to the RSU. First, I still get confused by some definitions, but, little by little, I think I will learn veins.

module = simulation.getModuleByPath("rsu[0]");
c = MobilityAccess().get(module)->getCurrentPosition();

I found this part of code in this thread: Getting the location of two different modules

But still have some questions:

1) Module is what kind of object? I would guess TraCIMobility*

2) How about simulation? I have no idea.

So, could anyone please first explain to me how to get RSU coordinates in the TraCIDemo11p.cc?

Thanks!

Community
  • 1
  • 1
pb772
  • 539
  • 1
  • 3
  • 14
  • StackOverflow is all about finding good answers to (good) questions. Your question makes it hard to find a good answer because it is asking multiple different things. In the interest of helping as many people as possible, would you mind limiting each post to only one question and phrasing this question as generally as possible? (for example, "given two Veins `Coord` objects, how can I calculate their distance?") – Christoph Sommer Feb 21 '17 at 08:16
  • Ok, thanks for the suggestion. I will start asking how to get RSU coordinates from the TraCIDemo11p.cc, I think the other part I can do by myself after I obtain RSU coordinates. – pb772 Feb 21 '17 at 08:25

2 Answers2

3

If you investigate the Veins 4.4 tutorial simulation (e.g., by running it in OMNeT++'s TkEnv), you will see that rsu[0] contains a submodule named mobility which is of type BaseMobility. If you investigate the BaseMobility class you will see that it has a method getCurrentPosition(). Presumably from reading the OMNeT++ user manual you already know how to get a pointer to any module in your simulation.

Put this knowledge together and you have found one way (of many possible ways) to get the position of a (named) node in a Veins simulation.

Assuming you are using Veins 4.4, the following code can be executed by any OMNeT++ module in the simulation to get the position of a node named rsu[0]:

Coord pos = check_and_cast<BaseMobility*>(getSimulation()->getModuleByPath("rsu[0].mobility"))->getCurrentPosition();
Christoph Sommer
  • 6,893
  • 1
  • 17
  • 35
1

Additionally, If you need a dynamic way to get the RSU coordinates. Mainly if you have a scenario with more than one RSU, you can use "findSubModule":

BaseMobility *baseMob;
baseMob = FindModule<BaseMobility*>::findSubModule(getParentModule());
Coord rsuCoord = baseMob->getCurrentPosition();

Hope this can help someone.

Cheers.