I create robot arm using dynamic actors and mainly PxRevoluteJoint. Now I’d like to control every single joint through set angle. Here’s my sample code:
PxRevoluteJoint *j; // my joint
// if angle is less than current degree
while(degrees >= angle)
{
j->setDriveVelocity(0.25);
actor0->getGlobalPose().q.toRadiansAndUnitAxis(angleq,axisq); // ACTOR2 on picture
instance->onRenderCallback(); // render and simulate()
degrees = angleq * 180/PI;
}
j->setDriveVelocity(0.0);
setAllKinematicJoints(pPhx->joints, true); // set up all joints to kinematic because I dont’t wont to // move them
My problem is that sometimes everythings works fine but often the ‘degrees’ variable is 180 and axisq changes. I want to rotate my actor0 (actor2 on picture) only in X axis and get always current angle. How I can do that?
Look at my answer here to limit a PxD6Joint - its similiar for other joints.
In short:
Create a joint and connect them with your actors:
(This code will add a joint to only one actor - thus the actor rotation / movement itself can be locked or limited)
mJoint->setMotion(PxD6Axis::eX,PxD6Motion::eLIMITED); // Limited on X allowed
//Limit rotations:
mJoint->setSwingLimit(PxJointLimitCone(...));
mJoint->setTwistLimit(PxJointLimitPair(...));
Look into the Bridge sample - the bridge use different type of joints and rotation limits.
Also look into the PhysXGuide for more information.
Its also usefull to read the comments for the desired method.
(In VS 2012: Click the mouse on the methode name and push F12 to go to the definition / declaration)
I checked D6Joint and it works the same as RevoluteJoint. Sometimes everythings ok but sometimes there’s error. It is because in line:
actor0->getGlobalPose().q.toRadiansAndUnitAxis(angleq,axisq); // ACTOR2 on picture
variable ‘angleq’ is 180 degrees instead of true current angle in X axis. Maybe this is cause all joints aren’t fit properly and there some jittering. Is there other way to get this angle?
Or you calculate the angle between a fixed axis - sample code:
PxTransform pos;
PxReal angle = pos.q.getBasisVector0().dot(PxVec3(0,1,0)); //Just change the values you to your needs
Or calculate it via the cross product (inner product) combined with the outer product.