我使用Veins 4.4,OMNeT ++ 5.0和Sumo 0.25。
我使用traci->getCurrentPosition()
来获取车辆的实际位置,即traci->getCurrentPosition().x
和traci->getCurrentPosition().y
。
我想估计车辆在特定时间的位置,以便获得车辆轨迹的某些位置。
因此,我使用函数traci->getPositionAt(time)
并设置simtime_t time = simTime()+60
以获取60 s
之后车辆的位置。但我得到了现在的位置!
getCurrentPosition()
和getPositionAt(time)
之间的区别是什么?
如何获得车辆轨迹的某些位置?
答案 0 :(得分:1)
下面是您提到的所有功能的实现。正如您在第一种情况中所看到的,getPositionAt()
的评论说:
它旨在作为
simTime()
传递actualTime
并返回 实际位置。
似乎这些功能根本不包括你的情况。
您可以在Move.h
查看这些功能的工作原理。评论也很详细
/**
* @brief Returns the position of the Move (Host) at the specified point in time.
* It is intended to be passed simTime() as actualTime and returns the actual position.
*
* Assumes that direction represents a normalized vector (length equals 1.0).
* Further this function does not check whether the given time point is before
* the startTime of the actual move pattern. So in this case one might obtain
* an unintended result.
*
*/
virtual Coord getPositionAt(simtime_t_cref actualTime = simTime()) const
{
// if speed is very close to 0.0, the host is practically standing still
if ( FWMath::close(speed, 0.0) ) return startPos;
// otherwise: actualPos = startPos + ( direction * v * t )
return startPos + ( direction * speed * SIMTIME_DBL(actualTime - startTime) );
}
virtual const Coord& getCurrentPosition() const
{
if (lastPos.z != DBL_MAX)
return lastPos;
return startPos;
}
getPositionAt()
也在TraCIMobility.h
实施为:
virtual Coord getPositionAt(const simtime_t& t) const {
return move.getPositionAt(t) ;
}
和getCurrentPosition()
在BaseMobility.h
实施为:
/** @brief Returns the current position at the current simulation time. */
virtual Coord getCurrentPosition(/*simtime_t_cref stWhen = simTime()*/) const {
//return move.getPositionAt(stWhen);
return move.getStartPos();
}