Collision detection concept

Typically: "How do I... ", "How can I... " questions
Post Reply
martin
Posts: 24
Joined: 15 Mar 2016, 10:38

Collision detection concept

Post by martin »

Hello,

I am interested in performing a simulation consisting of a robotic arm learning to hit a ball with a racket. For this I use the Python legacy remoteAPI.

To develop the learning task, I need to know if the racket has hit the ball or not at some point. I think the best way to do this is to try to identify if there is a collision between two objects.

For this I have made a conceptual scene where I place two objects on top of each other and analyze the collision between them. In this scene that I have done, if I simply run it pressing the "play" buttom, I can observe the collision thanks to the color change and the signal of contact points.

If i run the scene in synchronous mode, I can also see that in the VREP. However, if I run the following code; I am not able to see a "True" in the "collisionState".

Code: Select all

    vrep.simxSynchronous(clientID, True)
    vrep.simxStartSimulation(clientID, vrep.simx_opmode_blocking)

    retCode,colhandle = vrep.simxGetCollisionHandle(clientID, 'col_object', vrep.simx_opmode_blocking)
    retCode, collisionState = vrep.simxReadCollision(clientID, colhandle, vrep.simx_opmode_streaming)
    retCode = vrep.simxSynchronousTrigger(clientID)
    retCode = vrep.simxGetPingTime(clientID)
    for n in xrange(0, 50):
        retCode, collisionState = vrep.simxReadCollision(clientID, colhandle, vrep.simx_opmode_buffer)
        print n ,collisionState
        retCode = vrep.simxSynchronousTrigger(clientID)
        retCode = vrep.simxGetPingTime(clientID)
I presume that I am missunderstanding something. Would you mind to help me to understand what I am doing wrong with the collision detection functions?

Cheers.

coppelia
Site Admin
Posts: 7936
Joined: 14 Dec 2012, 00:25

Re: Collision detection concept

Post by coppelia »

Hello,

I don't see any obvious problem in your code...
So you see the collision in CoppeliaSim but you can't detect it from your remote API client? That could happen if you run in asynchronous mode, but shouldn't happen if you run in synchronous mode.
Keep in mind that the physics engine's collision detection is different and independent from CoppeliaSim's collision detection. In the first case we prefer to talk about collision response, rather than collision detection, as in the second case.

What happens if you print the collision state (i.e. the result of sim.readCollision) from within a non-threaded child script? Does it notice the collision?

Finally, if you need to detect a trigger, then it is often anyway better to handle the collision reading from within a non-threaded child script, and forward the result (processer or raw) to the remote API client by incrementing a signal counter for instance. This way you can easily add some threshold time, or only react to a rising edge.

Cheers

martin
Posts: 24
Joined: 15 Mar 2016, 10:38

Re: Collision detection concept

Post by martin »

I've found what I was missunderstanding. I was missunderstanding the concept of object:
- The computational object of the calculation model properties build by two shapes and
- what I understood as "object": which for me was a shape.

Now my code works. It works with the remote API and with the Lua functions about collisions in non-thread child scripts.

Thanks for your response!

Regards!

Post Reply