Changed flower message

This commit is contained in:
Jacob 2019-06-03 15:53:24 +02:00
parent 6be0b47f9e
commit 729ea72579
11 changed files with 48 additions and 35 deletions

Binary file not shown.

Binary file not shown.

View File

@ -20,6 +20,7 @@ class Forklift {
}
setPath(path) {
debugger;
this.end = false;
this.path = path;
this.currentTarget = this.path[this.targetId];
@ -27,8 +28,8 @@ class Forklift {
}
nextTarget() {
if (this.targetId < this.path.length - 1) {
this.targetId += 1;
if (this.targetId < this.path.length) {
this.currentTarget = this.path[this.targetId];
} else {
// Final destination reached
@ -36,7 +37,6 @@ class Forklift {
//this.removeCargo();
this.end = true;
this.targetId = 0;
}
}
@ -63,7 +63,7 @@ class Forklift {
}
}
async findPath(targetSection) {
findPath(targetSection) {
let data = {
graph: magazineToGraph(),
start_node: forklift.currentSection,
@ -73,6 +73,7 @@ class Forklift {
serverUrl + '/shortestPath',
data,
response => {
console.log('Find path request data: ', data);
let path = response.split('').map(Number);
this.currentTarget = path[0];
this.setPath(path);
@ -86,13 +87,17 @@ class Forklift {
completeOrder(order) {
this.waitUntilJobIsDone()
.then(() => this.findPath(order.from))
.then(() => {
if (this.currentSection != order.from) {
this.findPath(order.from);
}
})
.then(() => this.waitUntilJobIsDone())
.then(() => {
this.setCargo(order.what)
magazineState[order.from] = magazineState[order.from].filter((flower) => {
this.setCargo(order.what);
magazineState[order.from] = magazineState[order.from].filter(flower => {
return flower != order.what;
})
});
this.findPath(order.to);
})
.then(() => this.waitUntilJobIsDone())
@ -131,6 +136,7 @@ class Forklift {
}
sub(target, pos) {
console.log(target, pos);
return createVector(target.x - pos.x, target.y - pos.y);
}

View File

@ -22,7 +22,7 @@ function setup() {
// Create a forklift instance
forklift = new Forklift(sections[0].x, sections[0].y);
setInterval(ageFlowers, 5000)
setInterval(ageFlowers, 5000);
select('#completeOrdersButton').mousePressed(forklift.completeOrders());
}
@ -81,10 +81,12 @@ function addOrder() {
petalWidth: pw,
petalLength: pl,
};
console.log(data)
console.log(data);
httpPost(serverUrl + '/classify', data, response => {
magazineState[0].push(new Flower(response));
forklift.completeOrder(new Order(0, magazineState[0][0], magazineState[0][0].type, 'cycki'));
forklift.completeOrder(
new Order(0, magazineState[0][0], magazineState[0][0].type, 'msg'),
);
});
}
@ -141,13 +143,18 @@ function ageFlowers() {
let order;
let priority;
if (int(key) == 0) {
order = new Order(0, flower, int(flower), "Delivering new flower");
order = new Order(0, flower, int(flower), 'Delivering new flower');
priority = 1;
} else if (int(key) > 3) {
order = new Order(int(key), flower, 0, "Fully grown flower ready");
order = new Order(int(key), flower, 0, 'Fully grown flower ready');
priority = 3;
} else {
order = new Order(int(key), flower, (int(key) + 3), "Moving grown flower seedling");
order = new Order(
int(key),
flower,
int(key) + 3,
'Moving grown flower seedling',
);
priority = 2;
}
forklift.queue.enqueue([order, priority]);