Object Position

Dear friends,

I have made a whole arm with lengths L1,L2 and L3 for the three segments respectively in hierarchical order. Now as I am rotating the arm it is working perfectly fine. Now I am trying to find the XYZ coordinates of the last segment which is the hand while rotating the whole arm.

Is it possible?? my final goal is to grab other objects with the hand and perform some pick and place task.

any suggestion would be great.

thanks
roy

As you have the robot arm rotating, you just need to now the local coordinates of the “hand” segment. Knowing this, just make a translation of the origin of “hand” segment in the direction of where the hand is pointing by length L3.

thanks McLeary, how do i find the local coordinates?

I’m imagining that, when you draw the arm you translate the system to the origin of the arm, draw the arm, then translate the system to the origin of “elbow” segment, draw the elbol, translate the system to the origin of “hand” segment, draw the hand.

If this is the way you’re doing you then you have the coordinates of the hand. You need to know the origin of the hand in order to actually draw the hand.

yes you are right. this is the hand drawan. plz have a look.

glPushMatrix();
glTranslatef(0.0f,0.0f,0.0f);
glRotatef(angle[2],0.0f,1.0f,0.0f);
glRotatef(angle[1],1.0f,0.0f,0.0f);
glRotatef(angle[0],0.0f,0.0f,1.0f);

    glPushMatrix();
	gluDisk(qobj3,0.0f,3.0f,10.0f,10.0f);
	gluCylinder(qobj1,1.5f,1.0f,L1,10.0f,10.0f);
        glPopMatrix();

    glTranslatef(0.0f,0.0f,L1);
	glRotatef(angle[5]-(angle[2]),0.0f,1.0f,0.0f); 
	glRotatef(angle[4]-(angle[1]),1.0f,0.0f,0.0f);
	glRotatef(angle[3]-(angle[0]),0.0f,0.0f,1.0f);
	

glPushMatrix();
	gluCylinder(qobj1,1.0,0.8,L2,10,10);
glPopMatrix();




//hand

glPushMatrix();

    glTranslatef(0.0f,0.0f,L2);

glPushMatrix();
            glScalef(1.0f, 0.42f, 1.0f);
	glutSolidCube(2.5);

    glPopMatrix();

glPopMatrix();

First thing, why do you have glPushMatrix and glPopMatrix wrapping the gluCylinder calls?

A simple way is to keep track of the transformations you’re doing. Another way is to get the inverse model view matrix after you load the final matrix (take a look at glGet). This matrix contains all the transformations that you do.

thanks, i was trying to maintain the hierarchy.

i haven’t got it yet?? anyone??

What he said is that you can use the matrix after your transformations, and use it by yourself, to get the final coordinates of your points.

Another way to do so is by using quaternions. We generally use them for doing skeletal animations.

I think quaternions is a quite more advanced topic. I strongly recommend start understanding well how transformations works

If you want to grab something with your arm you’ll need to know the position AND orientation of the hand. This is basic robotics. They call the hand the ‘end effector’. Finding the position and orientation of the end effector from the joint angles is called ‘Forward Kinematics’. It’s just doing some matrix multiplications. Or, an easier way, is to use glGet (GL_MODELVIEW_MATRIX). Play around with that to get a feel for it. A more difficult problem is: given a position and orientation of an object in space, what are the joint angles necessary to grab that object (if it is possible). That’s called Inverse Kinematics. Many animation packages have I.K. capabilities built in these days.

thanks for your replies. i am getting there i think.

so according to your replies as i understand,

i should first define a

GLdouble MyMatrix[16];

and use

glMatrixMode(GL_MODELVIEW_MATRIX);

before my first transform and use

glGetDoublev(GL_MODELVIEW_MATRIX, MyMatrix);

after the last transform. and then get the inverse of that final matrix??

the modelview matrix stores all the transform you’ve got until the now. If you wanna find the local coordinates of the hand, you need to retrieve the modelview matrix right before you draw the hand itself. With this matrix you can get world coordinates of the hand. Take this plus the hand length and orientation and you have the “finger” coordinates.

If it was me, I’d start with a real simple robot arm, print out the matrix you retrieve in a console window, and try to make sense of it. It should be giving you the position and orientation of the end effector coordinate system. I would also graphically display a unit triad at the origin of the end effector coordinate system and compare it to the values in the matrix. Good luck. Sounds like fun.

thank you guys,actually i can access the coordinates now.

for now the X values seem right but the Z values are messed up. also i have not taken the inveres of the modelview matrix. i have tried but that seems to be very comlicated process for inverse of a 4X4 matrix. any short cut??

also am i on the right track??

Inverse a matrix is a basic linear algebra operation. You should look at this before going direct into OpenGL. If this is an unfamiliar concept, I strongly suggest you take this first or, perhaps take a look in a more high level API (which I don’t even know if there’s any graphics API that don’t use basics linear algebra)

For the matrices used in 3D graphics transformations, the inverse is simply the transpose (i.e.) switch the rows and columns. As I suggested before, start with a very simple version of your arm, maybe with one link only that is not rotated at all. In fact, you don’t even need an arm. All you need for now is an XYZ triad. Translate it 5 units down the X axis and retrieve the modelview matrix. It should show the translation and nothing else (i.e. the upper 3x3 matrix should be the identity matrix).

thanks a lot MaxH and McLeary, it is working now.

Now my next task is to pick and place other objects with the hand.

Can you guys advice me something please ??

It’s not really an OpenGL question.

Your transform will typically look like this:

MV = CTR1R2R3

Where MV = final modelview matrix
T = robot position (translation)
R1, R2, R3 = various rotations

glGet() the current modelview matrix after rendering the hand. When you want to insert an object into the hand at a later point in time, simply glLoad() the saved modelview matrix.