Connect website to shortestPath endpoint
This commit is contained in:
parent
0521035af3
commit
e5e8669663
Binary file not shown.
@ -35,16 +35,16 @@ class Forklift {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setVelocity() {
|
setVelocity() {
|
||||||
this.direction = p5.Vector.sub(
|
p5.Vector.sub(
|
||||||
sections[this.currentTarget],
|
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 = p5.Vector.add(this.positoin, this.velocity);
|
||||||
debugger;
|
|
||||||
if (
|
if (
|
||||||
Math.abs(this.positoin.x - sections[this.currentTarget].x) <=
|
Math.abs(this.positoin.x - sections[this.currentTarget].x) <=
|
||||||
this.speed &&
|
this.speed &&
|
||||||
|
@ -4,6 +4,8 @@ let packageClaim;
|
|||||||
let going = false;
|
let going = false;
|
||||||
let forklift;
|
let forklift;
|
||||||
|
|
||||||
|
let target;
|
||||||
|
|
||||||
// This runs once at start
|
// This runs once at start
|
||||||
function setup() {
|
function setup() {
|
||||||
createCanvas(500, 500).parent('canvas');
|
createCanvas(500, 500).parent('canvas');
|
||||||
@ -13,9 +15,9 @@ function setup() {
|
|||||||
createMagazineLayout();
|
createMagazineLayout();
|
||||||
|
|
||||||
select('#button').mousePressed(deliver);
|
select('#button').mousePressed(deliver);
|
||||||
|
target = select('#target');
|
||||||
// Create a forklift instance
|
// Create a forklift instance
|
||||||
forklift = new Forklift(sections[0].x, sections[0].y);
|
forklift = new Forklift(sections[0].x, sections[0].y);
|
||||||
console.log(magazineToGraph());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This runs every frame
|
// This runs every frame
|
||||||
@ -62,9 +64,25 @@ function drawMagazine() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function deliver() {
|
function deliver() {
|
||||||
path = [2, 1, 5, 4];
|
let data = {
|
||||||
|
graph: magazineToGraph(),
|
||||||
|
start_node: 0,
|
||||||
|
dest_node: int(target.value())
|
||||||
|
};
|
||||||
|
console.log(data);
|
||||||
|
httpPost(
|
||||||
|
'http://localhost:8000/shortestPath',
|
||||||
|
data,
|
||||||
|
response => {
|
||||||
|
path = response.split('').map(Number);
|
||||||
|
forklift.currentTarget = path[0];
|
||||||
forklift.setPath(path);
|
forklift.setPath(path);
|
||||||
going = true;
|
going = true;
|
||||||
|
},
|
||||||
|
error => {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createMagazineLayout() {
|
function createMagazineLayout() {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<head>
|
<head>
|
||||||
{% load static %}
|
{% load static %}
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.3/p5.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.3/p5.js"></script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.3/addons/p5.dom.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.3/addons/p5.dom.min.js"></script>
|
||||||
<script src="{% static 'magazine/forklift.js' %}"></script>
|
<script src="{% static 'magazine/forklift.js' %}"></script>
|
||||||
<script src="{% static 'magazine/sketch.js' %}"></script>
|
<script src="{% static 'magazine/sketch.js' %}"></script>
|
||||||
@ -59,6 +59,8 @@
|
|||||||
<input type="radio" name="material"> Hard
|
<input type="radio" name="material"> Hard
|
||||||
<input type="radio" name="material"> Soft
|
<input type="radio" name="material"> Soft
|
||||||
</div>
|
</div>
|
||||||
|
<label for="target">Target</label>
|
||||||
|
<input type="number" id="target" name="target">
|
||||||
<button id="button">Send Package</button>
|
<button id="button">Send Package</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="canvas" style="margin: 10px;"></div>
|
<div id="canvas" style="margin: 10px;"></div>
|
||||||
|
@ -20,6 +20,7 @@ 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()}
|
||||||
@ -55,7 +56,7 @@ def shortestPath(request):
|
|||||||
|
|
||||||
for node in graph:
|
for node in graph:
|
||||||
current = node
|
current = node
|
||||||
p = [current + 1]
|
p = [current]
|
||||||
while current != start_node:
|
while current != start_node:
|
||||||
p.append(predecessor[current])
|
p.append(predecessor[current])
|
||||||
current = predecessor[current]
|
current = predecessor[current]
|
||||||
|
Loading…
Reference in New Issue
Block a user