0

I use OMNeT++-4.6, sumo-0.22.0 and Veins-4a2.

I am interested to calculate the speed of the vehicle when a message is received. I used getSpeed() function to do it. But the problem is that when I calculated manually the speed basing on the time and the distance (using the formula s = d / t), the value is different.

For example, at t= 55.104470531278 s and the distance d= 29.0477 m, the speed obtained by calling the function getSpeed() is s= 3.34862 m/s = 10.8 km/h. On the other hand the one calculated manually is s= 0.52713 m/s = 1.9 km/h.

I need help to understand why the value obtained by using getSpeed() is different please.

Joe
  • 85
  • 1
  • 9
  • 1
    To support Michaels answer: How exactly do you calculate the speed? – Julian Heinovski Nov 13 '17 at 16:57
  • I called getSpeed() function in onData() function (in my scenario this function is executed when a node receives a message) in order to know the speed of each node when it receives a message. – Joe Nov 14 '17 at 09:20
  • I wanted to know how you manually calculate the speed which you then compare to the value you get from `getSpeed()`. Is ist the average speed over the whole time, like Michael suspected? – Julian Heinovski Nov 14 '17 at 18:08
  • I calculated the speed manually using the formula s = d / t (t is the current simulation time). – Joe Nov 15 '17 at 08:45
  • Okay. I get what t is, but where do you get d from? – Julian Heinovski Nov 15 '17 at 08:47
  • It seems that the issue has been solved by the answer of Michael. I assume that your manual speed is indeed the average (travel) speed which you get from `(overall driven distance of a node / simulation time)`. – Julian Heinovski Nov 15 '17 at 09:09
  • In fact, I calculated the distance at the current time (when a node receives a message), so I was basing on the two coordinates of the two nodes and I calculated the distance between them (therefore it is not the overall driven distance of a node). – Joe Nov 15 '17 at 09:15
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/159036/discussion-between-julian-heinovski-and-joe). – Julian Heinovski Nov 15 '17 at 09:18

1 Answers1

3

getSpeed() returns the current speed of the vehicle (to be precise the one in the last simulation step which is by default 1s) while your calculation gives the average speed over the last ~55s (assuming your simulation started at time 0).

Michael
  • 3,510
  • 1
  • 11
  • 23
  • So from I understood to calculate the average speed at each moment the node receives a message I should calculate manually using the formula (s = d / t) ? – Joe Nov 14 '17 at 10:20
  • 1
    If you want the current (sometimes called local) speed (of the last second) use `getSpeed()`, if you want the average (sometimes called travel) speed over the whole trip up to time t use d / t. It really depends on what you mean by speed. Most of the time people want the current speed and that is not the result of your calculation, but the result of `getSpeed()`. – Michael Nov 15 '17 at 05:21
  • Thank you for your clarification. – Joe Nov 15 '17 at 08:54