Cylon.js和Sphero

时间:2014-06-12 16:45:56

标签: node.js sphero-api sphero

是否有方法(Cylon.js)用Cylon Sphero获取Accelerometer和GyroScope数据?我想使用Sphero作为控制器,locator事件不会返回有用的信息。这就是我目前正在做的locator数据(咖啡脚本)

Cylon = require 'cylon'

connectionDefaults = 
  name    : 'sphero'
  adaptor : 'sphero'
  port    : '/dev/tty.Sphero-WYW-AMP-SPP' 

deviceDefaults = 
  name    : 'sphero'
  driver  : 'sphero'

spheroDoWork = ( robot )->
SPHERO          = robot.sphero 
DATA            = {}

sampleRateHz    = 420 
intN            = 20
intM            = 1
packetCount     = 20 
mask            = 21
mask2           = packetCount * 2

velMin          = 50 
distance        = 0
timeBetweenData = intN / sampleRateHz

handleConnect =->
    console.log '== SPHERO READY...'
    SPHERO.setDataStreaming( intN, intM, mask, packetCount, mask2 )
    SPHERO.detectLocator()
    SPHERO.stop()

handleLocator =( data )->
    raw = 
        yDist  :  data[0]
        xDist  :  data[1]
        accel  :  data[2]
        yVel   :  data[3]
        xVel   :  data[4]

    DATA.prev = DATA.curr
    DATA.curr = raw 

    console.log '=== PREV DATA', DATA.prev  
    console.log '=== CURR DATA', DATA.curr 

SPHERO.on 'connect',  handleConnect 
SPHERO.on 'locator',  handleLocator 


Cylon.robot
  connection  : connectionDefaults 
  device      : deviceDefaults
  work        : spheroDoWork

.start()

1 个答案:

答案 0 :(得分:1)

在使用hybrid小组处理setDataStreaming更新cylon.js后,现在可以通过git https://github.com/hybridgroup/cylon-sphero

获取所有传感器数据