Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I41 #113

Merged
merged 26 commits into from
Feb 25, 2019
Merged

I41 #113

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Get Next Job Added to Index.js
  • Loading branch information
Frederick Bawden committed Feb 19, 2019
commit 814948452d099b435162bbe2a4152de98ff28d26
6 changes: 3 additions & 3 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ app.post('/robotcommand/:robotid', (req,res,next) => {
})
app.post('/robotcommand', (req,res,next) => {
model
.addRobot(req.body.id, req.body.home_x, req.body.home_y)
.addRobot(req.body._id, req.body.home_x, req.body.home_y)
.then(robot => res.json({success: true, robot}))
.catch(next)
})
app.get('/robotcommand/getnextjob',(req,res,next) => {
model
.getNextJob()
.then(job => res.json({success:true, robot}))
.getNextJob(req.body.robot_id)
.then(job => res.json({success:true, job}))
.catch(next)
})

Expand Down
31 changes: 25 additions & 6 deletions server/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const factory = db => ({
new Promise((res, rej) => {
db()
.collection('orders')
.find({ _id: new ObjectID(orderId) })
.find({ _id: orderId })
.toArray((err, docs) => {
err ? rej(err) : res(docs[0])
})
Expand Down Expand Up @@ -95,7 +95,7 @@ const factory = db => ({
new Promise((res, rej) => {
db()
.collection('inventory')
.deleteOne({ _id: new ObjectID(item._id) }, (err, item) => {
.deleteOne({ _id: item._id}, (err, item) => {
err ? rej(err) : res(item)
})
}),
Expand Down Expand Up @@ -131,18 +131,28 @@ const factory = db => ({
db()
.collection('robot')
.updateOne({_id : robot_id}, {$set: {"home_x": home_x, "home_y":home_y}}, (err, warehouse) => {
err ? rej(err) :res(warehouse);
err ? rej(err) : res(warehouse);
});
}),
addRobot: (robot_id, home_x, home_y) =>
new Promise((res,rej) => {
db()
.collection('robot')
.insertOne({_id: robot_id, "home_x":home_x, "home_y":home_y}, (err,robot) => {
.insertOne(
{
_id: robot_id,
home_x:home_x,
home_y:home_y,
location: {
x:0,
y:0,
z:0
}
}, (err,robot) => {
err ? rej(err) : res(robot)
});
}),
getNextJob: () =>
getNextJob: (robot_id) =>
new Promise((res,rej) => {
db()
.collection('orders')
Expand All @@ -151,7 +161,16 @@ const factory = db => ({
if (err) {
rej(err)
} else {
res(robotPathfinding.convert_order_to_job(orders[0]))
db().collection('robot')
.find({"_id":robot_id})
.toArray((err,robot) => {
if (err) {
rej(err)
} else {
res(robotPathfinding.convert_order_to_job(orders[0],robot))
}
})

}
})
})
Expand Down
21 changes: 19 additions & 2 deletions server/robot-pathfinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,25 @@ module.exports.pathfind_to_point = (current_pos,end_pos, warehouse_grid) => {
path = PF.Util.compressPath(path);
console.log(path);
}
module.exports.convert_order_to_job = (order) => {
module.exports.convert_order_to_job = (order,robot) => {
console.log(order);

console.log(robot);
var robot_pos = robot["location"]
var item_list = order["items"]
var job = {}
for (var i = 0; i < item_list; i++) {
var current_item = item_list[i]["position"];
var robot_xy = [robot_pos["x"],robot_pos["y"]]
var item_xy = [current_item["x"],current_item["y"]]
var path = pathfind_to_point(robot_pos_arr, item_position);
}
/*
var items_to_collect = order["items"];
var
for (var i =0; i < items_to_collect.length; i++) {
var item_position = items_to_collect[i];

}
*/
return {}
}