【发布时间】:2021-01-02 18:36:39
【问题描述】:
我正在使用静脉 5,我正在尝试获取距节点一定距离内的节点位置。更具体地说,我试图在瞬间获得所有节点的映射位置以处理节点的位置。
我读了这个问题How to get count of cars in specific range,但它集中在静脉 4.6 中,而且我不知道如何使用 Christoph Sommer 建议的方法。是否有可能获得静脉 5 中的映射?我该怎么做?
我会很感激任何帮助 谢谢!
【问题讨论】:
我正在使用静脉 5,我正在尝试获取距节点一定距离内的节点位置。更具体地说,我试图在瞬间获得所有节点的映射位置以处理节点的位置。
我读了这个问题How to get count of cars in specific range,但它集中在静脉 4.6 中,而且我不知道如何使用 Christoph Sommer 建议的方法。是否有可能获得静脉 5 中的映射?我该怎么做?
我会很感激任何帮助 谢谢!
【问题讨论】:
最后我得到了模拟中所有节点的位置,并计算了它们与标记汽车的距离。
为此,我通过以下方式将 Ahmad Ahsan 在问题 How to get Coordinates of each vehicle in VEINS? 中的答案“翻译”为静脉 5.0:
void MessageGenerator::getMapping(){
// Get my position on the scenario
veins::Coord myPosition = mobility->getPositionAt(simTime());
EV << myPosition << endl;
// Get all available nodes in simulation
std::map<std::string, cModule*> allNodes = mobility->getManager()->getManagedHosts();
// Iterate through collection and find distance,
std::map<std::string, cModule*>::iterator it;
for(it = allNodes.begin(); it != allNodes.end(); it++)
{
TraCIMobility* auxMobility = TraCIMobilityAccess().get(it->second);
veins::Coord receiverPosition = auxMobility->getPositionAt(simTime());
//returns distance in meters
double dist = myPosition.distance(receiverPosition);
EV << "Distance: " << dist << endl;
}
}
关键变化在于 getPositionAt(simTime()) 方法。
如this 帖子中所讨论的,如果将此数据用于实际模拟目的,则在模拟中获取所有车辆的方法是一种不好的做法,因为很少可能在一个时间步中获取所有位置。就我而言,我仅将其用于评估目的。
【讨论】: