Node* start_node = new Node(agvs[i].getCurrentX(), agvs[i].getCurrentY()); Node* end_node = new Node(agvs[i].getStartX(), agvs[i].getStartY()); Node* end_node1 = new Node(agvs[i].getEndX(), agvs[i].getEndY()); std::vector<Node*> path_to_start = astar.getPath(start_node, end_node); std::vector<Node*> path_to_end = astar.getPath(end_node, end_node1);,增加代碼,如果agv的current的x和y等於任務起點的x和y,則只將agv的起點和任務的終點放入path中
时间: 2023-07-15 22:15:19 浏览: 75
你可以在 if 语句中添加条件,判断 agv 的当前坐标是否与任务起点坐标相同,如果是则直接将 agv 的起点和任务的终点放入路径中。代码如下:
```cpp
Node* start_node = new Node(agvs[i].getCurrentX(), agvs[i].getCurrentY());
Node* end_node = new Node(agvs[i].getStartX(), agvs[i].getStartY());
Node* end_node1 = new Node(agvs[i].getEndX(), agvs[i].getEndY());
if (agvs[i].getCurrentX() == agvs[i].getStartX() && agvs[i].getCurrentY() == agvs[i].getStartY()) {
std::vector<Node*> path;
path.push_back(start_node);
path.push_back(end_node1);
// do something with path
}
else {
std::vector<Node*> path_to_start = astar.getPath(start_node, end_node);
std::vector<Node*> path_to_end = astar.getPath(end_node, end_node1);
// do something with path_to_start and path_to_end
}
```
阅读全文