sphero-inc / sphero.js

🚫 DEPRECATED: The Sphero JavaScript SDK to control Sphero robots.
http://sdk.sphero.com
MIT License
342 stars 90 forks source link

Collision Detection Not Working? #48

Closed jhlau closed 8 years ago

jhlau commented 8 years ago

Hi,

I was just testing with collision detection and I am not getting asynchronous messages when BB-8 has a collision. Has anyone tested if it works? I added a line to tell it to roll in the examples/collision-detection.js:

var sphero = require("../");
var orb = sphero(process.env.PORT);

orb.connect(function() {
  orb.detectCollisions();
  orb.color("green");

  orb.on("collision", function(data) {
    console.log("collision detected");
    console.log("  data:", data);

    orb.color("red");

    setTimeout(function() {
      orb.color("green");
    }, 1000);
  }); 

  orb.roll(200, 0);

});

No colour change, no console log output.

I am running on Ubuntu 14.04, nodejs = 0.10.25 and BB-8's firmware = 4.63.

olcar commented 8 years ago

I tried to test the collision detection as well and had to tweak the configuration thresholds in order to get events...

  bb8.configureCollisions({
    meth: 0x01,
    xt: 0x20,
    yt: 0x20,
    xs: 0x20,
    ys: 0x20,
    dead: 0x50
  });
  bb8.on("collision", function(err, data) {
    if (err) {
      console.log(err);
    } else {
      console.log("collision detected!");
    }
  });

...those thresholds might be a little bit too sensitive but you should be able to test it.

deadprogram commented 8 years ago

This makes me wonder if we should add additional key to indicate "preset" defaults per device. For example:

robot.configureCollisions({device: "bb8"});

which would then use default values such as those used by @olcar vs. the current defaults which are optimized for Sphero 2.0 devices.

What do you think?

olcar commented 8 years ago

That would make sense. I wasn't really able to find the sweet spot for BB8, it probably needs further investigation but those settings might be a good starting point. Defining presets would definitely help us improve that as a community.

If I understand correctly, that means BB8 is not a Sphero 2.0 device and handles behaviours in a different manner?

If it's the case, what do you think about defining global device presets for other defaults settings like RotationRate, InactivityTimeout, etc. ?

deadprogram commented 8 years ago

Most of these settings are the same, but the collision detection is one I've noticed a clear difference.

Anyhow, we'd love a PR that added this, or else I can work on it.

olcar commented 8 years ago

OK, let's start with collision detection presets for BB8 then ;)

I can try to work it out during the weekend.

deadprogram commented 8 years ago

Awesome! :bow:

jhlau commented 8 years ago

I spent some time fiddling with the thresholds yesterday. I find that anything larger than 01h for 'dead' makes it very insensitive. I am currently using these thresholds:

xt: 0x20,
yt: 0x20,
xs: 0x10,
ys: 0x10,
dead: 0x01

It's a little sensitive though. I'd get multiple collision events for a collision, and also events for rotating BB8 (in-place).

Oh yes, for the output, undefined values are returned for xMagnitud, yMagnitud, speed and timeStamp.

jhlau commented 8 years ago

Any updates on this?

olcar commented 8 years ago

I submitted a PR yesterday that was merged earlier today to add presets for BB8.

Can you test again on your side using the new example I added (collision-detection-bb8.js)?

Let me know if it works OK for you.

deadprogram commented 8 years ago

The new 0.7.0 release includes this new code.

jhlau commented 8 years ago

Yeap. Tested it a bit and it's working. It occasionally fails to detect some collision, but I think it's good enough.

Quick question - do the other SDKs have these sort of threshold values for BB8? I'd imagine it'd make sense to copy their threshold values.

deadprogram commented 8 years ago

Hi, @jhlau I looked thru the other SDKs and was not able to find any specific default values per type of device. I suppose that means it is up to us to do so! :smile:

deadprogram commented 8 years ago

@jhlau if you need further assist on this issue, please re-open it. Thanks again to you and to @olcar for the code!