user2471762
user2471762

Reputation: 21

How can I emulate 2D collisions in the physical world with Sphero using CollisionDetectedAsyncData?

I'm using the sphero Android SDK.

Consider a breakout clone (like Arkanoid) and how the ball in the 2D game bounces off the lateral edges of the screen and also the top of the screen. I believe that the way it bounces uses basic "reflection" and that everything is frictionless and there is no rotational force or gravity, etc. The speed of the ball is only affected by how the ball hits the paddle and maybe some special bricks that speed it up. Suppose we setup something similar in the real world where we have a fairly narrow hallway, and maybe the walls are only 1 meter apart. Let's throw away the bricks and the paddle and just have the 2 walls and 1 ball (The ball is the Sphero, of course) Consider the linked to image. Sphero 2D collision emulation with real physical walls

Assuming that I start the ball off in some direction with a swipe or joystick maneuver or even just programmatically sending it off in said direction at a certain speed, so that it has some Velocity (x, y) when it hits the first wall, is there some way that I can use the data contained in CollisionDetectedAsyncData to determine what that Velocity was at the time of impact and also the angle between the wall and the line that goes through the center of the ball and the point of impact on the ball, so that I could make the ball "bounce" as it would in a 2D breakout clone as illustrated in the image? If I can figure out what the velocity is at the time of impact and that angle, then I should be able to do it. The speed of the ball after the "bounce" will be the same as it was just before impact upon the wall.

I have a project setup where I'm listening for collisions and I'm also getting the streaming LocatorData. So I have both the LocatorData and CollisionDetectedAsyncData available to me. I log the CollisionDetectedAsyncData instance when a collision has been detected according to the threshold that I have set, and then try to make some calculation based on it. The trouble is that I still don't get it when it comes to what exactly CollisionDetectedAsyncData holds. I don't understand what powerX and powerY are. The doc says it's the magnitude, but the magnitude of what? Please forgive my ignorance here. As you can tell, I'm very weak in the physics department. Anyway, I also log the LocatorData when the difference of the current acceleration vector and the previous acceleration vector exceeds 15000. Here's a snippet of my log.

(CollisionDetectedAsyncData)

01-20 22:35:58.559: WARN/CollisionCalculator(15101): Begin calculateReactionHeading
01-20 22:35:58.559: WARN/CollisionCalculator(15101): Calculating Reaction Heading with Algorithm 3
01-20 22:35:58.559: WARN/CollisionCalculator(15101): Angle relative to [X:13.970461890040886, Y:76.02953810995912]
01-20 22:35:58.559: WARN/CollisionCalculator(15101): Result Angle: 76.02953810995912
01-20 22:35:58.559: WARN/CollisionCalculator(15101): Impact Heading: 0.0
01-20 22:35:58.559: WARN/CollisionCalculator(15101): Power X: 205
01-20 22:35:58.559: WARN/CollisionCalculator(15101): Power Y: 51
01-20 22:35:58.559: WARN/CollisionCalculator(15101): Acceleration X: -0.562255859375
01-20 22:35:58.559: WARN/CollisionCalculator(15101): Acceleration Y: -2.44140625E-4
01-20 22:35:58.559: WARN/CollisionCalculator(15101): Calculated Heading: 283.9704618900409
01-20 22:35:58.559: WARN/CollisionCalculator(15101): Calculated Heading Mod Abs 360: 283.9704618900409
01-20 22:35:58.559: WARN/CollisionCalculator(15101): End calculateReactionHeading

(LocatorData)

01-20 22:35:58.679: WARN/CollisionCalculator(15101): Significant acceleration magnitude found! Magnitude: 48047.68312045681
01-20 22:35:58.679: WARN/CollisionCalculator(15101): Previous Vectors [Velocity: x=5.300000190734863, y=-1.2000000476837158], [Acceleration: x=-399.99961853027344, y=99.99990463256836]
01-20 22:35:58.679: WARN/CollisionCalculator(15101): Current Vectors [Velocity: x=27.899999618530273, y=92.19999694824219], [Acceleration: x=11299.999713897705, y=46699.99849796295]
01-20 22:35:58.679: WARN/CollisionCalculator(15101): Angle theta=3.2335627660548973
01-20 22:35:58.679: WARN/CollisionCalculator(15101): Angle of current Velocity vector relative to [X=73.16402521005779, Y=16.835974789942213]

OK, I know that there is a ton of information in this question, but I felt that it is a complex enough question where I should include as much detail as possible.

But basically what it comes down to this: Can I achieve what is illustrated in my attached image, in the real world with Sphero and two walls?

Thanks so much.

Upvotes: 2

Views: 330

Answers (1)

nodnarb
nodnarb

Reputation: 136

The X and Y magnitude represent a 2D vector of the collision along the plane of the ground. The problem with your set up is that it is much easier to know where the walls are in order to accurately calculate the reflection angle. You can try to reflect the angle across the front of the robot and then adding it to your current heading. So, if you are driving at heading 0 receive a collision at 45 degrees, first reflect the angle across the front of the robot (-45 or 315), then add the current heading (0 + 315 = 315). That should give you a rough idea of what angle to travel along to make it seem like the ball "bounced" off the wall.

Upvotes: 1

Related Questions