# HG changeset patch # User Ali Rostami # Date 1459599970 25200 # Sat Apr 02 05:26:10 2016 -0700 # Node ID 36a50be853f9e3f0d5402567085cca1d98f6801b # Parent c0943e24cccca0530a36b8f576472e879ba13463 mobility: (fixes #2363) Avoid accumulated position errors for ns-2 mobility The default Ns2MobilityHelper class extrapolates the new positions of the nodes using their current velocity vectors and previous extrapolated positions. Relying only on GPS speed and heading information for the duration of the simulation causes an increasing cumulative position error between positions of nodes in the simulation and the actual positions (The actual positions could be obtained from real experiment logs). By modifying the Ns2MobilityHelper class, both speed and position of mobile nodes are updated in the simulation. Specifically, we set the position of nodes to the GPS-reported position at the time of every location update and extrapolate the position at the time of network events based on the GPS-reported speed vector. Therefore, the simulated node positions are reset to the GPS-reported position at every GPS location update and a slight discontinuity in the nodes trajectory can occur. Although, we have not observed any adverse effect on the simulation results. This patch has been developed jointly at WINLAB, Rutgers University and West Virginia University as part of the V2V safety communications scalability activity of the Interoperability Issues of Vehicle-to-Vehicle Based Safety Systems (V2V-Interoperability) Project headed by the Crash Avoidance Metrics Partnership (CAMP) Vehicle Safety Communications 3 (VSC3) Consortium, in partnership with the United States Department of Transportation (USDOT). diff -r c0943e24cccc -r 36a50be853f9 src/mobility/helper/ns2-mobility-helper.cc --- a/src/mobility/helper/ns2-mobility-helper.cc Thu Mar 31 23:31:50 2016 +0200 +++ b/src/mobility/helper/ns2-mobility-helper.cc Sat Apr 02 05:26:10 2016 -0700 @@ -755,9 +755,10 @@ { return retval; } - // now calculate the xSpeed = distance / time - double xSpeed = (xFinalPosition - retval.m_finalPosition.x) / time; - double ySpeed = (yFinalPosition - retval.m_finalPosition.y) / time; // & same with ySpeed + // distance traveled based on input mobility trace file + double total_Dist = std::sqrt (std::pow (xFinalPosition - retval.m_finalPosition.x, 2) + std::pow (yFinalPosition - retval.m_finalPosition.y, 2)); + double xSpeed = speed * (xFinalPosition - retval.m_finalPosition.x) / total_Dist; // comment out for the scheduled movement + double ySpeed = speed * (yFinalPosition - retval.m_finalPosition.y) / total_Dist; // & same with ySpeed comment out for the scheduled movement retval.m_speed = Vector (xSpeed, ySpeed, 0); // quick and dirty set zSpeed = 0 @@ -766,11 +767,11 @@ NS_LOG_DEBUG ("Calculated Speed: X=" << xSpeed << " Y=" << ySpeed << " Z=" << zSpeed); // Set the Values - Simulator::Schedule (Seconds (at), &ConstantVelocityMobilityModel::SetVelocity, model, Vector (xSpeed, ySpeed, zSpeed)); - retval.m_stopEvent = Simulator::Schedule (Seconds (at + time), &ConstantVelocityMobilityModel::SetVelocity, model, Vector (0, 0, 0)); - retval.m_finalPosition.x += xSpeed * time; - retval.m_finalPosition.y += ySpeed * time; - retval.m_targetArrivalTime += time; + Simulator::Schedule (Seconds (at), &ConstantVelocityMobilityModel::SetPosition, model, Vector (xFinalPosition, yFinalPosition, 0)); // update the speed according to the input mobility trace file + Simulator::Schedule (Seconds (at), &ConstantVelocityMobilityModel::SetVelocity, model, Vector (xSpeed, ySpeed, zSpeed)); // update the position according to the input mobility trace file + retval.m_finalPosition.x = xFinalPosition; //comment out for use scheduled postion + retval.m_finalPosition.y = yFinalPosition; //comment out for use scheduled postion + retval.m_targetArrivalTime = at; //comment out for use scheduled postion } return retval; }