0

I am using veins 5.0 and i am trying to calculate the distance between the vehicles and setting their speed. I want to calculate it every second and i want to do it by sending wsm messages.My goal is to have for example 5 vehicles, each vehicle will communicate with the front vehicle and get its position with the intention of calculating their distance and keep it static. I am new to this and i don't know how to approach it. I tried to do something like this on handlePositionUpdate

void TraCIDemo11p::handlePositionUpdate(cObject* obj)
{
    DemoBaseApplLayer::handlePositionUpdate(obj);
    // stopped for for at least 10s?
    if (x<simTime()){ 
      TraCIDemo11pMessage* wsm1 = new TraCIDemo11pMessage();
      populateWSM(wsm1);
      wsm1->setPosition(mobility->getPositionAt(simTime())); 
      wsm1->setSpeed(mobility->getSpeed()); 
      if (dataOnSch) {
startService(Channel::sch2, 42, "Traffic Information Service");
          message to self to send later
scheduleAt(computeAsynchronousSendingTime(1,ChannelType::service), wsm1);
      }
      else {
         sendDown(wsm1);
      }
    }
ChrisK
  • 1
  • 2
  • Is this a question about coding or solving the problem? The solution to the problem can be very complex and will typically need "tuning" to get the desirable behaviour. Basically the following vehicles want to travel at the same speed as the lead vehicle. However if the distance is too great it wants to go a bit faster. If too close, a bit slower. A simple first step would be to make the speed equal plus an amount proportional to the distance error. Tune by chaging this ratio. Make the vehicles follow each other rather than the lead. A big error in one would cause a crash. – William J Bagshaw Jun 13 '20 at 14:24
  • Hello thanks for comenting, It's a question about the coding. You describing exactly what i want to do. I want the vehicles to follow its other and not the leading one. I don't know where to start and which functions to use. – ChrisK Jun 15 '20 at 14:38

1 Answers1

0

You are describing what is, effectively, a platooning application. You might want to base your source code on Plexe, the platooning extension to Veins. It already comes with state-of-the-art distance controllers like PATH or Ploeg. More information can be found on http://plexe.car2x.org/

Christoph Sommer
  • 6,893
  • 1
  • 17
  • 35
  • Thanks for your reply, unfortunately i can't work with plexe. How can i send wsm messages every 5 seconds so i will be able to calculate the distance between vehicles? – ChrisK Aug 08 '20 at 12:37
  • i also get that error message **undisposed object: (veins::TraCIDemo11pMessage) RSUExampleScenario.node[1].appl.** – ChrisK Aug 08 '20 at 15:32
  • The source code of the demo application you are already basing your code on shows you how to send a beacon. For how to do something after a certain time (or at regular time intervals) I would suggest to have a look at the example application of subprojects/veins_inet – Christoph Sommer Aug 09 '20 at 12:39