I want to change the speed of vehicles in the next time in veins

54 views
Skip to first unread message

faezeh

unread,
May 15, 2020, 11:49:44 AM5/15/20
to OMNeT++ Users
In my simulation I want to have maxSpeed 80 for vehicles and I want to change the speed of my vehicles in the next time
The first in the .rou.xml  file, I set the maximum speed to 80.

<routes >
        <vType color="1,1,0" maxSpeed="80" minGap="2" length="2.5" sigma="0.5" decel="4.5" accel="2.6" id="vtype0"/>
        <route id="route0" edges="182884827#0 182884827#1 182884827#2"/>
        <flow id="flow0" number="100" period="3" begin="0" route="route0" type="vtype0"/>
   
</routes>

but whenever I use  GET_SPEED= my_mobility->getSpeed(); All speeds were close to 20.
But I want it to give me different speeds that are less than 80 and the speeds change dynamically.
According to this link:


I create this code:

in this code I find available cars in simulation environment, for each available car, I selected the random number from 10 to 80 speeds to be assigned to each vehicle .
Then I use setspeed() and I set this random number as speed.



  std::map<std::string, cModule*> availableCars = mobility->getManager()->getManagedHosts();
   std::map<std::string, cModule*>::iterator it;

    for(it = availableCars.begin(); it != availableCars.end(); it++){


       TraCIMobility* mobility1 = TraCIMobilityAccess().get(it->second);
      TraCICommandInterface::Vehicle* traciVehicle1=mobility1->getVehicleCommandInterface();
     
   
        double select_random_speed=uniform(40,80);

        std::cout<<"select random ="<<select_random_speed<<std::endl;
        traciVehicle1->setSpeed(select_random_speed);
   
      double GET_SPEED= mobility1->getSpeed();

       std::cout<<"GET_SPEED"<<GET_SPEED<<std::endl;
     
  }


But again, the outputs are close to 20.

Please help me solve my problem.

Christoph Sommer

unread,
May 19, 2020, 12:39:06 PM5/19/20
to OMNeT++ Users Mailinglist
On 15 May 2020, at 17:49, faezeh <fz.ab...@gmail.com> wrote:
>
> in the .rou.xml file, I set the maximum speed to 80.
> [..]
> but whenever I use GET_SPEED= my_mobility->getSpeed(); All speeds were close to 20.

You allowed cars to drive faster, but maybe your roads have lower speed limits.

Best,

Christoph


--
Jun.-Prof. Dr.-Ing. Christoph Sommer
Cooperative Mobile Systems Group
Heinz Nixdorf Institute, Paderborn University, Germany
https://www.cms-labs.org/people/sommer/

faezeh

unread,
May 19, 2020, 12:54:50 PM5/19/20
to OMNeT++ Users
Thank you very much for your answer.
How can I change the speed limit from the road?

faezeh

unread,
May 19, 2020, 2:12:39 PM5/19/20
to OMNeT++ Users
I  understand what I did wrong
In omnet++, Unit of the speed is m/s
But I wanted the speed to be km/h
That is, 80 km/h is equivalent to 22.2 m/s and because of that  my speeds were close to 20.




On Tuesday, May 19, 2020 at 9:39:06 AM UTC-7, Christoph Sommer wrote:
Reply all
Reply to author
Forward
0 new messages