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) { setPath(path) {
debugger;
this.end = false; this.end = false;
this.path = path; this.path = path;
this.currentTarget = this.path[this.targetId]; this.currentTarget = this.path[this.targetId];
@ -27,8 +28,8 @@ class Forklift {
} }
nextTarget() { nextTarget() {
this.targetId += 1; if (this.targetId < this.path.length - 1) {
if (this.targetId < this.path.length) { this.targetId += 1;
this.currentTarget = this.path[this.targetId]; this.currentTarget = this.path[this.targetId];
} else { } else {
// Final destination reached // Final destination reached
@ -36,7 +37,6 @@ class Forklift {
//this.removeCargo(); //this.removeCargo();
this.end = true; this.end = true;
this.targetId = 0; this.targetId = 0;
} }
} }
@ -63,7 +63,7 @@ class Forklift {
} }
} }
async findPath(targetSection) { findPath(targetSection) {
let data = { let data = {
graph: magazineToGraph(), graph: magazineToGraph(),
start_node: forklift.currentSection, start_node: forklift.currentSection,
@ -73,6 +73,7 @@ class Forklift {
serverUrl + '/shortestPath', serverUrl + '/shortestPath',
data, data,
response => { response => {
console.log('Find path request data: ', data);
let path = response.split('').map(Number); let path = response.split('').map(Number);
this.currentTarget = path[0]; this.currentTarget = path[0];
this.setPath(path); this.setPath(path);
@ -86,22 +87,26 @@ class Forklift {
completeOrder(order) { completeOrder(order) {
this.waitUntilJobIsDone() this.waitUntilJobIsDone()
.then(() => this.findPath(order.from)) .then(() => {
.then(() => this.waitUntilJobIsDone()) if (this.currentSection != order.from) {
.then(() => { this.findPath(order.from);
this.setCargo(order.what) }
magazineState[order.from] = magazineState[order.from].filter((flower) => {
return flower != order.what;
}) })
this.findPath(order.to); .then(() => this.waitUntilJobIsDone())
}) .then(() => {
.then(() => this.waitUntilJobIsDone()) this.setCargo(order.what);
.then(() => { magazineState[order.from] = magazineState[order.from].filter(flower => {
magazineState[order.to].push(order.what); return flower != order.what;
order.what.setMaxMaturity(5 + 2*order.to); });
console.log(order.message); this.findPath(order.to);
this.busy = false; })
}); .then(() => this.waitUntilJobIsDone())
.then(() => {
magazineState[order.to].push(order.what);
order.what.setMaxMaturity(5 + 2 * order.to);
console.log(order.message);
this.busy = false;
});
} }
waitUntilJobIsDone() { waitUntilJobIsDone() {
@ -116,7 +121,7 @@ class Forklift {
} }
completeOrders() { completeOrders() {
while(!this.queue.isEmpty()) { while (!this.queue.isEmpty()) {
let order = queue.dequeue(); let order = queue.dequeue();
this.completeOrder(order); this.completeOrder(order);
} }
@ -131,6 +136,7 @@ class Forklift {
} }
sub(target, pos) { sub(target, pos) {
console.log(target, pos);
return createVector(target.x - pos.x, target.y - pos.y); return createVector(target.x - pos.x, target.y - pos.y);
} }

View File

@ -4,7 +4,7 @@ let roads;
let packageClaim; let packageClaim;
let going = false; let going = false;
let forklift; let forklift;
let magazineState = {0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [] }; let magazineState = { 0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [] };
// This runs once at start // This runs once at start
function setup() { function setup() {
@ -22,7 +22,7 @@ function setup() {
// 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);
setInterval(ageFlowers, 5000) setInterval(ageFlowers, 5000);
select('#completeOrdersButton').mousePressed(forklift.completeOrders()); select('#completeOrdersButton').mousePressed(forklift.completeOrders());
} }
@ -81,10 +81,12 @@ function addOrder() {
petalWidth: pw, petalWidth: pw,
petalLength: pl, petalLength: pl,
}; };
console.log(data) console.log(data);
httpPost(serverUrl + '/classify', data, response => { httpPost(serverUrl + '/classify', data, response => {
magazineState[0].push(new Flower(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'),
);
}); });
} }
@ -137,17 +139,22 @@ function ageFlowers() {
for (let key of Object.keys(magazineState)) { for (let key of Object.keys(magazineState)) {
for (let flower of magazineState[key]) { for (let flower of magazineState[key]) {
flower.grow(); flower.grow();
if(flower.isReady() && !flower.isOrdered()) { if (flower.isReady() && !flower.isOrdered()) {
let order; let order;
let priority; let priority;
if(int(key) == 0) { 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; priority = 1;
} else if(int(key) > 3) { } 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; priority = 3;
} else { } 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; priority = 2;
} }
forklift.queue.enqueue([order, priority]); forklift.queue.enqueue([order, priority]);