Skip to content
This repository has been archived by the owner on Dec 20, 2019. It is now read-only.

Collision Detection Not Working? #48

Closed
jhlau opened this issue Jan 8, 2016 · 13 comments
Closed

Collision Detection Not Working? #48

jhlau opened this issue Jan 8, 2016 · 13 comments

Comments

@jhlau
Copy link

jhlau commented Jan 8, 2016

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.

@jhlau jhlau changed the title Collision Detection Working Collision Detection Not Working? Jan 8, 2016
@olcar
Copy link

olcar commented Jan 8, 2016

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
Copy link
Contributor

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
Copy link

olcar commented Jan 8, 2016

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
Copy link
Contributor

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
Copy link

olcar commented Jan 8, 2016

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

I can try to work it out during the weekend.

@deadprogram
Copy link
Contributor

Awesome! 🙇

@jhlau
Copy link
Author

jhlau commented Jan 9, 2016

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
Copy link
Author

jhlau commented Jan 11, 2016

Any updates on this?

@olcar
Copy link

olcar commented Jan 11, 2016

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
Copy link
Contributor

The new 0.7.0 release includes this new code.

@jhlau
Copy link
Author

jhlau commented Jan 12, 2016

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
Copy link
Contributor

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! 😄

@deadprogram
Copy link
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants