node.jssphero-apisphero

Cylon.js and Sphero


Is there a method ( Cylon.js ) for getting Accelerometer and GyroScope data with Cylon Sphero ? I would like to use the Sphero as a controller, and the locator event doesn't return information that is useful. This is what I'm doing at the moment to get locator data ( coffee-script )

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()

Solution

  • After working with the hybrid group on updating setDataStreaming in cylon.js, all sensor data is now available via the git https://github.com/hybridgroup/cylon-sphero