Contact between two kinematic objects / haptics

Hi all

I just started using Physx and have a question about kinematic objects. I want to create a haptics simulation, so I made a kinematic actor representing the haptic device (sphere), which I set with setKinematicTarget at the exaxt position. I now need the othter objects to stay at a given position and to get contact reports when I hit one of these with my device.
I created the objects also as kinematic actors, but when one touches the other, I don’t get a collision callback, I get the message:

…..\SimulationController\src\ScNPhaseCore.cpp (889) : warning : Filtering: Resolving contacts between two kinematic objects is invalid. Contacts will not get resolved.

Fist, is this the correct way, creating kinmatic actors for each object? Second, how do I enable collision detection between them?
I also enabled
_scene->setFlag(physx::PxSceneFlag::eENABLE_KINEMATIC_PAIRS, true);
_scene->setFlag(physx::PxSceneFlag::eENABLE_KINEMATIC_STATIC_PAIRS, true);

Any advice on best practices for haptics?

I use PhsX 3.3.0 Beta 2.

Thanks for your help.

Hi,

You need to set these flags if you want contact report between kinematics. But as the manual says, these flags are not mutables so you need to set them when creating your scene.

Hi

Thanks for the help… But still the same message. I added

sceneDesc.flags |= physx::PxSceneFlag::eENABLE_KINEMATIC_PAIRS;
sceneDesc.flags |= physx::PxSceneFlag::eENABLE_KINEMATIC_STATIC_PAIRS;
_scene = _physics->createScene(sceneDesc);

but it makes no difference…

Thanks

Yes,
I see now. By default, kinematics can’t collide between them, these flags are only used for contact reporting. I don’t know if it is possible to make kinematics collide between each other (If that is what you want to have).

Ok, so is it possible to use static objects and get all the collision events and information? As my objects should not underlie gravity, i guess it’s ok to create them as static objects. Do I have some disadvantages with that?

Thanks for your help.

Hi,

Static objects “can’t” be moved (In reality they can be moved but with some performance penalities).

Hey,

If gravity is the problem to not use dynamic rigid bodies, why not disable gravity for that specific object (like we do for our haptic simulation) or disable gravity for the entire scene?

Besides doing that, I think you really need to start reading the PhysX guide as you ask “how do I enable collision detection between them?” You probably did not implement a “filter shader” function and you do not call this function for every shape you add to the scene. Start reading the following link, look through the example, curse it a few times because it is dame hard to understand and then discover that you can make thinks work:
https://developer.nvidia.com/sites/default/files/akamai/physx/Manual/Callbacks.html. At least that is what I did as non-native programmer :)

Further, you mention to “attach” a kinematic object to your haptic device… can you explain more? How do you close the control loop?

Hope this helps

Hi

I read the callback stuff, I also implemented the filtering and set it during object creation. I guess disabling gravity sounds the best.

I’d like to have my haptic device represented by a mesh, e.g. a surgical instrument, then I want to pick something with that, move around and have the correct collision force feedback.

What do you mean by closing the control loop? Something like this?

_scene->simulate(timeStep);
_scene->fetchResults(true);

Thanks for your help

With the control loop I mean the information flow between the simulation and the haptic device and what you do with that information.

I thought so that you wanted to use the collision forces for the force feedback (info flow from environment to haptic device). That might even work for the sphere on which collision force are likely to go through the centre of the sphere and therefore cause only forces as feedback. Though force sensors have been demonstrated to work in real world applications, I won’t expect it to work for you. Among other things I think that your haptic device is probably not capable of representing the high frequency content and high force magnitude of the collision. If your haptic device is able to feedback torques, you will be facing a great challenge in deriving the torques form the collision (in case of a non-spherical tool).

As you wanted to attach a kinematic object to the device, I guess that you intended to set the positions of the haptic device directly to the virtual object (info flow from haptic device to environment). If so, DON’T DO THAT! You will be faced with objects penetrating each other, simply because you tell them so. This will result in instable simulation and unpleasant force feedback.

The most easy way to setup a first test with a haptic device is the use of a so called position error controller (PERR → is what you do with the information) with which you close the loop in the information flow. That basically means that you compare at the simulation side the position of the device and the object, multiply the difference by some gain (spring stiffness) to get a force, add damping force on the objects velocity and set that force to the object.
(P_dev-P_obj)K_obj – V_objD_obj = F_obj
And reverse at the haptic device side
(P_obj-P_dev)K_dev – V_devD_dev = F_dev
Note that the stiffness and damping can be different for the device and the object.

My advice is to try this first, it will already be a challenge to master and it will probably fit your needs, if not then test more advanced controllers.

Have you settle this problem?I am also confused about it

Why do you want to use kinematic objects for haptic devices ?..
I’ve used some haptic devices with physX a few years ago, for a surgery project, and I’ve used dynamic objects for the instrument.
Just don’t enable gravity and your object will not have any weight (but a mass)
The simulation was far away from perfect but maybe it can do th job for you ?

Anyway Jot’s solution may be a good idea…

Because the control of a pure dynamic rigid is not accurate using a speed(or if you have a better solution ?do please enlight me), I want to use it in a virtual-reality system to control a machine-arm.I managed to use simulationcallback and filtercallback, but it can only notify, I need to come up with solution as to how to avoid penetration.

OK, I understand.
Then Jot’s solution is probably the best way to look at.
Nevertheless, keep in mind that PhysX is a game engine, so this is not perfect, you will have errors (there are professional colision engines for mechanics).
Furthermore, going with the physicBody way will give you as little errors as your update frequency is High
It’s all about compromises.
As I said, with a high update frequency, you can manipulate a robot arm with minimum errors.

I am aware of velocity control schemes for haptic interaction. Though you need very accurate sensors for that or use some sort of position compensation scheme. What is not accurate about it? Drifting? shaking? Joystick? Phantom omni? The more information you give the better I can help. Most simple solution remains position error control (with a high and stable update frequency, e.g. 0.001 s).

Ah, new information :-)

So some more information. As JOT suggested, I have a haptic algorithm based on a proxy and a coupling between the real position of the device and the virtual object, which stays on the surface of the colliding object. I don’t use the force I get from physX directly, I only use the collision points and use it in my own algorithm to compute force and torque.

So I still use a kinematic object for my virtual object (left over from my first implementation), as I can set the position directly, as I also get pos and rot from the haptic device (I use impedance controlled devices). But I see I can also set the position direclty on dynamic objects with setGlobalPose.

So best would be using dynamic objects, disable gravity (I handle gravity in my own haptic algorithm), filter the collisions of the real position of the haptic device out, and set the virtual object with setGlobalPose?

Still there remain some ugly locking mechanism as I access the physics objects from different threads. So I use mutexes. Any better idea? I have three asynchronous threads (haptics, collision detection, visual rendering) get lots of concurrent API read/write messages from physx, therefore the mutexes. But performance is obviously affected.

Thanks

Robert6666 wrote: “So best would be using dynamic objects, disable gravity (I handle gravity in my own haptic algorithm), filter the collisions of the real position of the haptic device out, and set the virtual object with setGlobalPose?”

Again, NO. From your description I think you currently have two objects in the scene: 1 a floor (being static or kinematic); 2 the objects you manipulate (being currently kinematic). Have you added more objects and tested if/how you can move them? You probably have some application in mind in which you want to add more objects. Try adding a third object and manipulate it. Moreover try to squeeze it between the floor and the virtual object via the haptic interface. I bet you cannot squeeze the object in a stable way. It will also not behave properly if you change the virtual object to a dynamic actor. That is because you force two objects inside each other.

I bet that a first implementation of a PERR controller will give worse results. If so, consult a control engineer. He/she can guide you to implement the controller correctly. Then it will work much better compared to kinematic control.

Multithreading is not uncommon, though I cannot help on that part.

Good luck