hybridgroup / cylon-sphero

Cylon adaptor for Sphero robot
http://cylonjs.com
Other
47 stars 16 forks source link

readLocator doesn't return position #25

Closed NielsTalens closed 10 years ago

NielsTalens commented 10 years ago

I'm trying to get the location of the Sphero by using readLocator(). I can't seem to get a proper return.

I tried the following to try and find out what is returned by readLocator:

Cylon.robot
  connection: { name: 'sphero', adaptor: 'sphero', port: '/dev/tty.Sphero-BRB-RN-SPP' }
  device: { name: 'sphero', driver: 'sphero' }

  work: (me) ->

    me.sphero.on 'connect', ->
      console.log "Connecting"
      me.sphero.setDataStreaming 30, 1, 21, 50, 25
      me.sphero.configureLocator 1, 10, 10, 150
      console.log "initial: " + locator()

    every 5.seconds(), ->
      console.log "Object type: " + Object.prototype.toString.call(locator())
      console.log locator()

    locator = ->
      currentLocation = me.sphero.readLocator()
      console.log "Locator type: " + Object.prototype.toString.call(currentLocation)
      console.log "Locator pos:"+Object.keys(currentLocation)
      "Location is: #{currentLocation}"
.start()

Which results in:


initial: Location is: [object Object]
Locator type: [object Object]
Locator pos:domain,_events,_maxListeners,resetTimeout,requestAcknowledgement,open,close,write,ping,getVersioning,_controlUARTTxLine,setDeviceName,getBluetoothInfo,setAutoReconnect,getAutoReconnect,getPowerState,setPowerNotification,sleep,getVoltageTripPoints,_setVoltageTripPoints,setInactivityTimeout,_jumpToBootloader,performLevel1Diagnostics,performLevel2Diagnostics,_clearCounters,assignTimeValue,pollPacketTimes,setHeading,setStabilization,setRotationRate,setApplicationConfigurationBlock,getApplicationConfigurationBlock,getChassisID,_setChassisID,selfLevel,setDataStreaming,configureCollisionDetection,configureLocator,setAccelerometerRange,readLocator,setRGB,setBackLED,getRGB,roll,setBoostWithTime,setRawMotorValues,setMotionTimeout,setPermanentOptionFlags,getPermanentOptionFlags,setTemporaryOptionFlags,getTemporaryOptionFlags,getConfigurationBlock,setDeviceMode,setConfigurationBlock,getDeviceMode,runMacro,saveTemporaryMacro,saveMacro,reInitializeMacroExecutive,abortMacro,getMacroStatus,setMacroParameter,appendMacroChunck,eraseOrbBasicStorage,appendOrbBasicFragment,executeOrbBasicProgram,abortOrbBasicProgram,submitValueToInputStatement
Object type: [object String]

Any ideas on how to get the positions returned from readLocator?

edgarsilva commented 10 years ago

Hi @NielsTalens,

We will take a look into this, have you tried printing the contents of:

console.log(curentLocation[0]) console.log(curentLocation[1])

Regards,

NielsTalens commented 10 years ago

Hi @edgarSilva,

Both result in "undefined".

Regards,

edgarsilva commented 10 years ago

@NielsTalens I will check it out as soon as I'm back home and have a sphero available, which might be in a couple of weeks. I will keep you posted.

deadprogram commented 10 years ago

Perhaps @stewart can look into this sooner?

edgarsilva commented 10 years ago

@NielsTalens Turns out the GetLocator does not work at all in the API with node-serialport. But we've implemented this functionality with an event called locator that is activated the same way as collision detection. Here is an example:

https://github.com/hybridgroup/cylon-sphero/blob/master/examples/locator/locator.js

There is no release of this yet, but you can use the repo to check it out:

my.sphero.on('locator', function(data) {
      console.log("locator:");
      console.log(data);
});

The param returned data contains [y-dist, x-dist, accel, x-vel, y-vel], let me know if you need anything else or if you spot any weird behavior or issues.

NielsTalens commented 10 years ago

Cool @edgarsilva thanks! I'm currently experimenting with this ;-)

palmerabollo commented 10 years ago

I've faced the same issue. To make it clearer, perhaps readLocator could return any of:

I think it would also be useful to include this information in the docs. Thank you !

edgarsilva commented 10 years ago

Hi @palmerabollo,

ReadLocator does not work, neither in sphero itself or spheron module, as explained above, the sphero API does not return anything.

That's why we have to use the events along with setDataStreamming and bitMasks to activate and obtain the information we want.

We'll continue to update the docs that are out of date, but in short reasLocator will never work.

edgarsilva commented 10 years ago

I have some examples for this but I'm not at my computer right now, I will add the example to the docs site and also paste here, then I'll update and remove the confusing info from the docs site tomorrow, thanks for the heads up.

edgarsilva commented 10 years ago

Found an example on how to read the locator info from the sphero, maybe this will work for you.

https://github.com/hybridgroup/cylon-sphero/blob/master/examples/locator/locator.js

palmerabollo commented 10 years ago

Yes, that example is great, thanks. But even in that case, there are some information you can't get with the locator, such as the sphero heading. Is it possible to get the current heading?

edgarsilva commented 10 years ago

Yes you just need to pass that to the setDataStreamming, chech the sphero API or cylon-sphero adaptor for a full list of possible values, there's another setDataStreamming example there.

palmerabollo commented 10 years ago

Thanks Edgar. I am not sure. This is what I get using all the datasources (except 'motorsPWM', 'motorsIMF' and 'quaternion'):

my.sphero.configureLocator(0, 0, 0, 0);
var datasources = ['locator', 'accelOne', 'velocity', 'gyroscope', 'accelerometer', 'imu'];
my.sphero.setDataStreaming(datasources, opts);

my.sphero.on('data', function ondata(data) {
   console.log('data', data);
   // output example [ 2, -5, -1, -445, -143, 4105, 3, 3, 0, 0, 5, 100, 0, 0 ]
});

The heading is provided by the 'imu' datasource, but my.sphero.setHeading(90) doesn't move the backLED. The only method that worked for me was my.shpero.roll(speed, heading), but in this case the heading is relative to the current heading and it is not persistent (the sphero gets back to heading=0 after rolling).

I can move this question to stackoverflow if you don't want to ruin this issue.

edgarsilva commented 10 years ago

Let me go through the sphero API and check the commands and values we are sending. You should be able to change the heading.

I'll update here once I know more about the problem.

edgarsilva commented 10 years ago

@palmerabollo I don't think setHeading does what you think it does. If you want the sphero to keep pointing forward when you roll the sphero and the LED to adjust check the calibrate method and this examples:

https://github.com/hybridgroup/cylon-sphero#how-to-calibrate-sphero https://gist.github.com/zankich/04be4e3468e74ab54c6c

In the example the tailLED moves to set the direction the sphero is heading.

Let me know if this works for you.

edgarsilva commented 10 years ago

@palmerabollo regarding the stackoverflow thing go ahead and do either that or open a new issue for cylon-sphero, since this is getting out of scope of this issue.

Let me know how it goes.