Fix forklift movement
Bug where forklift couldnt get to certain nodes is removed by reimplementing vecdtor addition and substarction.
This commit is contained in:
parent
c5f39ca39e
commit
9d19eeea22
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -39,24 +39,30 @@ class Forklift {
|
||||
}
|
||||
|
||||
setVelocity() {
|
||||
p5.Vector.sub(
|
||||
sections[this.currentTarget],
|
||||
this.positoin,
|
||||
this.direction
|
||||
);
|
||||
debugger;
|
||||
this.direction = this.sub(sections[this.currentTarget], this.positoin);
|
||||
this.velocity = this.direction.setMag(this.speed);
|
||||
}
|
||||
|
||||
move() {
|
||||
this.positoin = p5.Vector.add(this.positoin, this.velocity);
|
||||
this.positoin = this.add(this.positoin, this.velocity);
|
||||
if (
|
||||
Math.abs(this.positoin.x - sections[this.currentTarget].x) <=
|
||||
this.speed &&
|
||||
Math.abs(this.positoin.y - sections[this.currentTarget].y) <=
|
||||
this.speed
|
||||
) {
|
||||
this.positoin = sections[this.currentTarget];
|
||||
this.nextTarget();
|
||||
this.setVelocity();
|
||||
}
|
||||
}
|
||||
|
||||
sub(target, pos) {
|
||||
return createVector(target.x - pos.x, target.y - pos.y);
|
||||
}
|
||||
|
||||
add(target, pos) {
|
||||
return createVector(target.x + pos.x, target.y + pos.y);
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ let target;
|
||||
|
||||
// This runs once at start
|
||||
function setup() {
|
||||
createCanvas(500, 500).parent('canvas');
|
||||
createCanvas(600, 600).parent('canvas');
|
||||
|
||||
frameRate(30);
|
||||
|
||||
@ -44,7 +44,7 @@ function drawMagazine() {
|
||||
sections[road[0]].x,
|
||||
sections[road[0]].y,
|
||||
sections[road[1]].x,
|
||||
sections[road[1]].y
|
||||
sections[road[1]].y,
|
||||
);
|
||||
}
|
||||
noStroke();
|
||||
@ -67,7 +67,7 @@ function deliver() {
|
||||
let data = {
|
||||
graph: magazineToGraph(),
|
||||
start_node: forklift.currentSection,
|
||||
dest_node: int(target.value())
|
||||
dest_node: int(target.value()),
|
||||
};
|
||||
httpPost(
|
||||
'http://localhost:8000/shortestPath',
|
||||
@ -80,21 +80,21 @@ function deliver() {
|
||||
},
|
||||
error => {
|
||||
console.log(error);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
function createMagazineLayout() {
|
||||
unit = width / 5;
|
||||
unit = width / 6;
|
||||
|
||||
sections = {
|
||||
0: { x: unit * 2, y: 0 },
|
||||
1: createVector(unit, unit),
|
||||
2: createVector(unit, 2 * unit),
|
||||
3: createVector(unit, 3 * unit),
|
||||
4: createVector(3 * unit, unit),
|
||||
5: createVector(3 * unit, 2 * unit),
|
||||
6: createVector(3 * unit, 3 * unit)
|
||||
0: { x: 2 * unit, y: unit },
|
||||
1: createVector(unit, 2 * unit),
|
||||
2: createVector(unit, 3 * unit),
|
||||
3: createVector(unit, 4 * unit),
|
||||
4: createVector(3 * unit, 2 * unit),
|
||||
5: createVector(3 * unit, 3 * unit),
|
||||
6: createVector(3 * unit, 4 * unit),
|
||||
};
|
||||
roads = [
|
||||
[1, 5],
|
||||
@ -105,7 +105,7 @@ function createMagazineLayout() {
|
||||
[5, 6],
|
||||
[3, 6],
|
||||
[4, 2],
|
||||
[5, 3]
|
||||
[5, 3],
|
||||
];
|
||||
}
|
||||
|
||||
@ -119,11 +119,11 @@ function magazineToGraph() {
|
||||
end = road[1];
|
||||
graph[start][end] = Math.sqrt(
|
||||
Math.pow(sections[start].x - sections[end].x, 2) +
|
||||
Math.pow(sections[start].y - sections[end].y, 2)
|
||||
Math.pow(sections[start].y - sections[end].y, 2),
|
||||
);
|
||||
graph[end][start] = Math.sqrt(
|
||||
Math.pow(sections[start].x - sections[end].x, 2) +
|
||||
Math.pow(sections[start].y - sections[end].y, 2)
|
||||
Math.pow(sections[start].y - sections[end].y, 2),
|
||||
);
|
||||
}
|
||||
return graph;
|
||||
|
@ -20,7 +20,6 @@ def classify(request):
|
||||
@csrf_exempt
|
||||
def shortestPath(request):
|
||||
loaded_request = json.load(request)
|
||||
print(loaded_request)
|
||||
|
||||
graph = loaded_request["graph"]
|
||||
graph = {int(k): v for k, v in graph.items()}
|
||||
@ -62,4 +61,4 @@ def shortestPath(request):
|
||||
current = predecessor[current]
|
||||
path[node] = p[::-1]
|
||||
|
||||
return HttpResponse(path[dest_node])
|
||||
return HttpResponse(path[dest_node][1:])
|
||||
|
Loading…
Reference in New Issue
Block a user