Robotic arm hinge joint

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Robotic arm hinge joint

Postby SilentAssassin21 » Sat Sep 22, 2012 4:07 pm

Hi what i want is a hinge joint that can be controlled not by force but by setting up the angular velocity, and as the result the robot might fall or something, i'm creating a simulator where i can teach a robot to walk,

I can't figure out a way how to set the angle or angular velocity for the hinge joint
SilentAssassin21
 
Posts: 32
Joined: Sat Sep 22, 2012 4:05 pm

Re: Robotic arm hinge joint

Postby JoeJ » Sat Sep 22, 2012 4:34 pm

You need to learn about custom joints.
See the joint library coming with newton for examples.
Following code works for me for the same purpose,
Just look at the end, where after some calculation the needed acceleration is given to newton solver.


Code: Select all
float strength = propsPhysics::f[propsPhysics::rjStrength]; // some constant
               float m_maxAngularFriction = 1200.0 * strength;
               sVec3 omega0, omega1;
               BodyGetAngVel(body0, omega0);
               BodyGetAngVel(body1, omega1);
               sQuat offsetOrn = targetOrn;
               
               sVec3 axis = matrix1[2]; // axis of the hinge joint in world space
               float relAccel;
               

                  float motorAngle = 2.0 * atan (offsetOrn[2] / offsetOrn[3]); // the target angle
                  relAccel = (motorAngle - limitAngle); // limit Angle = current angle
                  relAccel -= sVec3(omega0 - omega1).Dot(axis) * propsPhysics::f[propsPhysics::rjRemoveCur]; // something between 0 and 1 (0.33)
                  relAccel *= propsPhysics::f[propsPhysics::rjAccMul] / timestep; // (0.8)
               

               NewtonUserJointAddAngularRow (joint, 0.0f, &axis[0]);
               NewtonUserJointSetRowAcceleration (joint, relAccel);
               NewtonUserJointSetRowMinimumFriction (joint, -m_maxAngularFriction);
               NewtonUserJointSetRowMaximumFriction (joint,  m_maxAngularFriction);
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Robotic arm hinge joint

Postby SilentAssassin21 » Sat Sep 22, 2012 4:41 pm

I would like to learn about it but I can't find any decent source on how where when what is called for the custom joint :\
SilentAssassin21
 
Posts: 32
Joined: Sat Sep 22, 2012 4:05 pm

Re: Robotic arm hinge joint

Postby SilentAssassin21 » Sat Sep 22, 2012 4:47 pm

by the way where is this code called???
SilentAssassin21
 
Posts: 32
Joined: Sat Sep 22, 2012 4:05 pm

Re: Robotic arm hinge joint

Postby JoeJ » Sat Sep 22, 2012 5:05 pm

Some documentation here: http://newtondynamics.com/wiki/index.php5?title=Joints#Userdefined_bilateral
So, User Joint is the correct name for it.

Jount Lib is buld on top of that.
After svn download joint lib is in: newton-dynamics-read-only\packages\dCustomJoints.
Its always the SubmitConstraints Function that is interesting.
Tutorial on how to use joint lib: http://newtondynamics.com/wiki/index.php5?title=Tutorial_103:_-_Adding_Joints

There should be examples in the Demos Sandbox (newton-dynamics-read-only\applications\demosSandbox) too.


You'll need some time to get it using, but it's very flexible and stable if you do it right.
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Robotic arm hinge joint

Postby JoeJ » Sat Sep 22, 2012 5:20 pm

SilentAssassin21 wrote:by the way where is this code called???


Basically it works like this:

Create your joint with NewtonConstraintCreateUserJoint, there you give:
Bodies, callback function, pointer to your data etc.

Than, at runtime Newton calls the Callback, in which you do:
Get bodies tranformations, velocities etc. and build some constraints that you want.
Feed the constraints to solver by setting Rows.
My example code is a piece from that callback.
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Robotic arm hinge joint

Postby SilentAssassin21 » Sat Sep 22, 2012 6:05 pm

Thanks very much, and the last question is what is this pin vector... is it a synonymum for the the vector around which is the pivot rotating?
SilentAssassin21
 
Posts: 32
Joined: Sat Sep 22, 2012 4:05 pm

Re: Robotic arm hinge joint

Postby JoeJ » Sun Sep 23, 2012 5:08 am

As far as i know pin vector in custom hinge ist the raxis of allowed rotation, yes.
But i'm not sure, in ball and socket it is the direction of the limit cone for example.
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Robotic arm hinge joint

Postby Julio Jerez » Sun Sep 23, 2012 12:26 pm

when you make a constraint between two bodies, the constrain is define in a local coordinate system the is common the two bodies.
the job of the joint is to minimize the error between these two local system when transform they are transformed to the common global space.
I call the pin axis to the x axis of these local coordinate systems.
for example for a contact, the pin is automatically created using the normal as pin, and the two friction tangent.
for hinge, the pin parameter is use to make the x axis, and when the join has limit the other axis is use as the y axis.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Robotic arm hinge joint

Postby SilentAssassin21 » Sat Sep 29, 2012 10:38 am

I dont get this that SubmitConstraints is never called in my custom joint class and i do make a call to newton update
SilentAssassin21
 
Posts: 32
Joined: Sat Sep 22, 2012 4:05 pm

Re: Robotic arm hinge joint

Postby JoeJ » Sat Sep 29, 2012 11:50 am

Here a pseudo-code example for a point to point joint:
Code: Select all
struct P2PJoint
{
body *a, *b;

void Submit (const NewtonJoint* joint)
{
matrix ma; NewtonBodyGetMatrix(a, &ma);
matrix mb; NewtonBodyGetMatrix(b, &mb);
// construct joint position that we want to link
vec pa = ma[3] + ma[0] * 10; // center + xaxis *10
vec pb = mb[3] + mb[0] * -10;
// fuse those two points at 3 orthonormal directions
NewtonUserJointAddLinearRow (joint, (float*)&pa, (float*)&pb, (float*)&vec(1,0,0));
NewtonUserJointAddLinearRow (joint, (float*)&pa, (float*)&pb, (float*)&vec(0,1,0));
NewtonUserJointAddLinearRow (joint, (float*)&pa, (float*)&pb, (float*)&vec(0,0,1));
}
}



void P2PCallback (const NewtonJoint* joint, float timestep, int threadIndex)
{
P2PJoint *j = (P2PJoint *) NewtonJointGetUserData (joint);
j->Submit (joint); // call func from our class
}



void main ()
{
// create 2 bodies, collision shapes, mass props...
body *a = CreateBox(...);
body *b = CreateBox(...);
// create joint
NewtonJoint *joint = NewtonConstraintCreateUserJoint (world, 3, P2PCallback, 0, a, b);
P2PJoint p2p; p2p.a = a; p2p.b = b;
NewtonJointSetUserData (joint, &p2p); // set link to our class

// runtime
while (1) NewtonUpdate():
}
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Robotic arm hinge joint

Postby SilentAssassin21 » Sun Sep 30, 2012 3:52 pm

Thanks I've been trying all kinds of code to see how these joints work.

In my testings i tried to make something like a rop with the following code in the submitConstraints

Code: Select all
   
       virtual void SubmitConstraints( dFloat timestep, int threadIndex )
   {
      tBox *parentBox=(tBox *)NewtonBodyGetUserData(m_parent);
      tBox *childBox=(tBox *)NewtonBodyGetUserData(m_child);

      dVector vec1(1,0,0,0.f);
      dVector vec2(0,1,0,0.f);
      dVector vec3(0,0,1,0.f);

      NewtonUserJointAddLinearRow(m_joint,&childBox->matrix.m_posit[0],&parentBox->matrix.m_posit[0],&vec1[0]);
      NewtonUserJointAddLinearRow(m_joint,&childBox->matrix.m_posit[0],&parentBox->matrix.m_posit[0],&vec2[0]);
      NewtonUserJointAddLinearRow(m_joint,&childBox->matrix.m_posit[0],&parentBox->matrix.m_posit[0],&vec3[0]);
   }


I ran this code on 2 boxes connected together and pivots are at the boxes centers, the boxes they collide in the way that they come in the same place and there is no collision reaction
SilentAssassin21
 
Posts: 32
Joined: Sat Sep 22, 2012 4:05 pm

Re: Robotic arm hinge joint

Postby JoeJ » Mon Oct 01, 2012 9:44 am

SilentAssassin21 wrote:I ran this code on 2 boxes connected together and pivots are at the boxes centers, the boxes they collide in the way that they come in the same place and there is no collision reaction


This is correct. By default newton disables collision betwwen bodies, whan you creat a joint between them.
Also, since pivots are at both boxes centers, result is that they connect with zero distance.
If you want some distance to build a rope, you need at least one point at a offset from center, like i did in my example:

vec pa = ma[3] + ma[0] * 10; // center + xaxis *10

With newton mathlib that would look like:

dVector vec1(1,0,0,0.f);
dVector vec2(0,1,0,0.f);
dVector vec3(0,0,1,0.f);

dVector offset = &childBox->matrix.m_posit + childBox->matrix.m_front.scale(10); // not 100% sure about syntax

NewtonUserJointAddLinearRow(m_joint,&offset [0],&parentBox->matrix.m_posit[0],&vec1[0]);
NewtonUserJointAddLinearRow(m_joint,&offset [0],&parentBox->matrix.m_posit[0],&vec2[0]);
NewtonUserJointAddLinearRow(m_joint,&offset [0],&parentBox->matrix.m_posit[0],&vec3[0]);
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest