for (int i = 0; i < agvs.size(); i++) { for (int j = 0; j < tasks.size(); j++) { if (tasks[j].id == agvs[i].get_task_id()) { completed_task_index = j; break; } } if (tasks[completed_task_index].completed == 2 ) { // 如果已经完成任务 paths[i].clear(); continue; // 跳过此次循环 } if (! paths[i].empty()) { Node* next_node = paths[i][0]; float speed = agvs[i].getSpeed(); float distance = sqrt(pow(next_node->x - agvs[i].getCurrentX(), 2) + pow(next_node->y - agvs[i].getCurrentY(), 2)); float time = distance / speed * 1000; //node_Value[next_node->x][next_node->y] = 10; QTimer::singleShot(time, this, &, i, next_node { agvs[i].setCurrentX(next_node->x); agvs[i].setCurrentY(next_node->y); this->update(); // 在窗口中重绘 }); } },添加代碼,獲取agv的current的x和y,輸入_MAP[][] = 1,黨agv移動到新的點的時候,上個點MAO變爲0
时间: 2023-12-14 15:39:56 浏览: 54
你可以在下面的循环中添加代码来实现:
```
if (!paths[i].empty()) {
Node* current_node = paths[i][0];
Node* next_node = paths[i][1];
float speed = agvs[i].getSpeed();
float distance = sqrt(pow(next_node->x - agvs[i].getCurrentX(), 2) + pow(next_node->y - agvs[i].getCurrentY(), 2));
float time = distance / speed * 1000;
int current_x = current_node->x;
int current_y = current_node->y;
int next_x = next_node->x;
int next_y = next_node->y;
_MAP[current_x][current_y] = 0;
_MAP[next_x][next_y] = 1;
QTimer::singleShot(time, this, [&]() {
agvs[i].setCurrentX(next_x);
agvs[i].setCurrentY(next_y);
this->update();
});
}
```
这里我们在获取当前节点和下一个节点的坐标之后,将当前节点的地图值设为0,将下一个节点的地图值设为1,表示AGV已经占据了这个位置。同时,我们在移动AGV到下一个节点时,更新AGV的当前坐标,并在窗口中重绘。
阅读全文