-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnavigator.coffee
92 lines (76 loc) · 2.31 KB
/
navigator.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
five = require 'johnny-five'
util = require 'util'
medibot = require './lib/medibot'
express = require 'express'
http = require 'http'
# io = require('socket.io').listen(app).set('log level', 1);
# Start Express
app = express()
server = http.createServer(app)
io = require('socket.io').listen(server)
app.configure ->
app.set "port", process.env.PORT or 3001
app.set('views', __dirname + '/assets/templates');
app.set('view engine', 'hbs');
app.set 'views', "#{__dirname}/assets/templates"
app.use express.logger()
app.use express.bodyParser()
app.use app.router
app.use express.methodOverride()
app.use(express.static(__dirname + '/public'))
hbsPrecompiler = require('handlebars-precompiler')
hbsPrecompiler.watchDir(
__dirname + "/assets/templates",
__dirname + "/public/javascripts/medibot-templates.min.js",
['handlebars', 'hbs']
)
app.get '/', (req, res) ->
res.render 'index',
locals:
title: 'medibot'
# arduino connected code
board = new five.Board()
board.on "ready", ->
bot = new medibot.Bot
io.sockets.on "connection", (client) ->
bot.start()
bot.camera.record()
bot.on 'read', ->
client.emit 'read', bot.last
client.on 'motors:move', (speeds) ->
# flipped values
bot.motors.move speeds[1], speeds[0]
client.on 'camera:move', (dir) ->
bot.camera.control dir, false
client.on 'camera:move:end', (dir) ->
bot.camera.control dir, true
# testing code
# io.sockets.on "connection", (client) ->
# console.log "connected"
# i = 0
# angle = 0
# setInterval ->
# client.emit 'read',
# battery:
# value: Math.floor(Math.random() *255)
# motors:
# left: Math.floor(Math.random() *255)
# right: Math.floor(Math.random() * 255)
# sensor:
# value: Math.floor(Math.random() *255)
# sonar:
# scanner:
# degrees: Math.floor(Math.random() *255)
# ping:
# distance: Math.floor(Math.random() * 50)
# min: 0
# max: 50
# angle += 20
# , 1000
# client.on 'camera:move', (dir) ->
# console.log 'camera: ' + dir
# client.on 'camera:move:end', (dir) ->
# console.log 'camera end: ' + dir
# client.on 'motors:move', (pos) ->
# console.log 'motors: ' + pos[0] + ' ' + pos[1]
server.listen(3001);