PhysX icon indicating copy to clipboard operation
PhysX copied to clipboard

Gear simulation

Open hazidh opened this issue 3 months ago • 0 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.

https://github.com/user-attachments/assets/6b50ae97-04c7-4510-b55b-ad1b847092de

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 03:10 hazidh