physx-jni icon indicating copy to clipboard operation
physx-jni copied to clipboard

Gear simulation

Open hazidh opened this issue 3 months ago • 5 comments

Hello, I have a problem. When I was simulating gears, I defined the two gear models and the PxArticulationLink of the gear shaft as eREVOLUTE type. When I connected the two PXArticulationLinks using PxGearJoint, When I drive one gear to turn but the other gear does not follow, I noticed that you made an example of a gear link below, could you please refer to your code.

https://github.com/user-attachments/assets/0cde8516-3c2a-49da-84d0-fe947cb85460


PxArticulationLink inputGearlink = inputArticulationControl.createLink(inputShaftlink,
                inputGear.getWorldTransform(), inputGear, gMaterial, 1, null, true, true);
driveJoint = inputGearlink.getInboundJoint();
driveJoint.setJointType(PxArticulationJointTypeEnum.eREVOLUTE);
parentPose = PhysxMathUtil.getRelativeTransform(inputGear, inputShaft);
childPose = PhysxMathUtil.getRelativeTransform(inputGear, inputGear);
inputArticulationControl.setJointParentAndChildPose(driveJoint, parentPose, childPose);
driveJoint.setMotion(PxArticulationAxisEnum.eSWING2, PxArticulationMotionEnum.eFREE);
PxArticulationDrive drive = new PxArticulationDrive();
drive.setStiffness(1000f);      
drive.setDamping(10f);         
drive.setMaxForce(100000.0f);   
drive.setDriveType(PxArticulationDriveTypeEnum.eVELOCITY);
driveJoint.setDriveParams(PxArticulationAxisEnum.eSWING2, drive);

PxArticulationLink middle1Gearlink = middle1ArticulationControl.createLink(middle1Shaftlink,
                outputGear.getWorldTransform(), outputGear, gMaterial, 1, null, true, true);
joint = middle1Gearlink.getInboundJoint();
joint.setJointType(PxArticulationJointTypeEnum.eREVOLUTE);
parentPose = PhysxMathUtil.getRelativeTransform(outputGear, speedShaft);
childPose = PhysxMathUtil.getRelativeTransform(outputGear, outputGear);
middle1ArticulationControl.setJointParentAndChildPose(joint, parentPose, childPose);
joint.setMotion(PxArticulationAxisEnum.eSWING2, PxArticulationMotionEnum.eFREE);

parentPose = PhysxMathUtil.getRelativeTransform(outputGear, inputGear);
childPose = PhysxMathUtil.getRelativeTransform(outputGear, outputGear);
PxGearJoint gearJoint1 = PxTopLevelFunctions.GearJointCreate(physxAppState.getPhysics(), inputGearlink,
        PhysxMathUtil.updatePxTransform(parentPose, null),
        middle1Gearlink, PhysxMathUtil.updatePxTransform(childPose, null));
gearJoint1.setHinges(inputGearlink.getInboundJoint(), middle1Gearlink.getInboundJoint());
gearJoint1.setGearRatio(-14f / 45f);

hazidh avatar Oct 14 '25 02:10 hazidh

Hi, actually I never actually used PxGearJoint and also didn't do an example for that (if you refer to the chain running across the two wheels, that one uses only revolute joints no PxGearJoint, code is here)

So I'm afraid I can't give you any more advice than to look into the PhysX documentation for gear joints: https://nvidia-omniverse.github.io/PhysX/physx/5.6.1/docs/Joints.html#gear-joint

There is also an cpp example in the original PhysX demos here: https://github.com/NVIDIA-Omniverse/PhysX/tree/main/physx/snippets/snippetgearjoint Maybe that helps.

fabmax avatar Oct 14 '25 19:10 fabmax

Hi, actually I never actually used PxGearJoint and also didn't do an example for that (if you refer to the chain running across the two wheels, that one uses only revolute joints no PxGearJoint, code is here)

So I'm afraid I can't give you any more advice than to look into the PhysX documentation for gear joints: https://nvidia-omniverse.github.io/PhysX/physx/5.6.1/docs/Joints.html#gear-joint

There is also an cpp example in the original PhysX demos here: https://github.com/NVIDIA-Omniverse/PhysX/tree/main/physx/snippets/snippetgearjoint Maybe that helps.

Ok, thank you very much for your reply!

hazidh avatar Oct 15 '25 02:10 hazidh

Hello, I am now in PxArticulationLink stress test, I will create 10000 group PxArticulationReducedCoordinate and define good PxArticulationLink, but when I created at the bottom of the encounter this problem, Is there any way to solve it? [ABORT] User allocator returned NULL. (F:\11_Physx\PhysxJniGithub2.4.2\physx-jni\PhysX\physx\include\foundation/PxBroadcast.h:196)

hazidh avatar Oct 16 '25 03:10 hazidh

Hmm never saw that error. It sounds as if it fails to allocate memory for something. 10000 articulations sounds like a lot. Does it work with a smaller number?

fabmax avatar Oct 16 '25 21:10 fabmax

Yes, maybe my computer ran out of DRAM

hazidh avatar Oct 17 '25 00:10 hazidh