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() {
|
setVelocity() {
|
||||||
p5.Vector.sub(
|
debugger;
|
||||||
sections[this.currentTarget],
|
this.direction = this.sub(sections[this.currentTarget], this.positoin);
|
||||||
this.positoin,
|
|
||||||
this.direction
|
|
||||||
);
|
|
||||||
this.velocity = this.direction.setMag(this.speed);
|
this.velocity = this.direction.setMag(this.speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
move() {
|
move() {
|
||||||
this.positoin = p5.Vector.add(this.positoin, this.velocity);
|
this.positoin = this.add(this.positoin, this.velocity);
|
||||||
if (
|
if (
|
||||||
Math.abs(this.positoin.x - sections[this.currentTarget].x) <=
|
Math.abs(this.positoin.x - sections[this.currentTarget].x) <=
|
||||||
this.speed &&
|
this.speed &&
|
||||||
Math.abs(this.positoin.y - sections[this.currentTarget].y) <=
|
Math.abs(this.positoin.y - sections[this.currentTarget].y) <=
|
||||||
this.speed
|
this.speed
|
||||||
) {
|
) {
|
||||||
|
this.positoin = sections[this.currentTarget];
|
||||||
this.nextTarget();
|
this.nextTarget();
|
||||||
this.setVelocity();
|
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
|
// This runs once at start
|
||||||
function setup() {
|
function setup() {
|
||||||
createCanvas(500, 500).parent('canvas');
|
createCanvas(600, 600).parent('canvas');
|
||||||
|
|
||||||
frameRate(30);
|
frameRate(30);
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ function drawMagazine() {
|
|||||||
sections[road[0]].x,
|
sections[road[0]].x,
|
||||||
sections[road[0]].y,
|
sections[road[0]].y,
|
||||||
sections[road[1]].x,
|
sections[road[1]].x,
|
||||||
sections[road[1]].y
|
sections[road[1]].y,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
noStroke();
|
noStroke();
|
||||||
@ -67,7 +67,7 @@ function deliver() {
|
|||||||
let data = {
|
let data = {
|
||||||
graph: magazineToGraph(),
|
graph: magazineToGraph(),
|
||||||
start_node: forklift.currentSection,
|
start_node: forklift.currentSection,
|
||||||
dest_node: int(target.value())
|
dest_node: int(target.value()),
|
||||||
};
|
};
|
||||||
httpPost(
|
httpPost(
|
||||||
'http://localhost:8000/shortestPath',
|
'http://localhost:8000/shortestPath',
|
||||||
@ -80,21 +80,21 @@ function deliver() {
|
|||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createMagazineLayout() {
|
function createMagazineLayout() {
|
||||||
unit = width / 5;
|
unit = width / 6;
|
||||||
|
|
||||||
sections = {
|
sections = {
|
||||||
0: { x: unit * 2, y: 0 },
|
0: { x: 2 * unit, y: unit },
|
||||||
1: createVector(unit, unit),
|
1: createVector(unit, 2 * unit),
|
||||||
2: createVector(unit, 2 * unit),
|
2: createVector(unit, 3 * unit),
|
||||||
3: createVector(unit, 3 * unit),
|
3: createVector(unit, 4 * unit),
|
||||||
4: createVector(3 * unit, unit),
|
4: createVector(3 * unit, 2 * unit),
|
||||||
5: createVector(3 * unit, 2 * unit),
|
5: createVector(3 * unit, 3 * unit),
|
||||||
6: createVector(3 * unit, 3 * unit)
|
6: createVector(3 * unit, 4 * unit),
|
||||||
};
|
};
|
||||||
roads = [
|
roads = [
|
||||||
[1, 5],
|
[1, 5],
|
||||||
@ -105,7 +105,7 @@ function createMagazineLayout() {
|
|||||||
[5, 6],
|
[5, 6],
|
||||||
[3, 6],
|
[3, 6],
|
||||||
[4, 2],
|
[4, 2],
|
||||||
[5, 3]
|
[5, 3],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,11 +119,11 @@ function magazineToGraph() {
|
|||||||
end = road[1];
|
end = road[1];
|
||||||
graph[start][end] = Math.sqrt(
|
graph[start][end] = Math.sqrt(
|
||||||
Math.pow(sections[start].x - sections[end].x, 2) +
|
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(
|
graph[end][start] = Math.sqrt(
|
||||||
Math.pow(sections[start].x - sections[end].x, 2) +
|
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;
|
return graph;
|
||||||
|
@ -20,7 +20,6 @@ def classify(request):
|
|||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def shortestPath(request):
|
def shortestPath(request):
|
||||||
loaded_request = json.load(request)
|
loaded_request = json.load(request)
|
||||||
print(loaded_request)
|
|
||||||
|
|
||||||
graph = loaded_request["graph"]
|
graph = loaded_request["graph"]
|
||||||
graph = {int(k): v for k, v in graph.items()}
|
graph = {int(k): v for k, v in graph.items()}
|
||||||
@ -62,4 +61,4 @@ def shortestPath(request):
|
|||||||
current = predecessor[current]
|
current = predecessor[current]
|
||||||
path[node] = p[::-1]
|
path[node] = p[::-1]
|
||||||
|
|
||||||
return HttpResponse(path[dest_node])
|
return HttpResponse(path[dest_node][1:])
|
||||||
|
Loading…
Reference in New Issue
Block a user