View Full Version : Object Position

prashun

03-10-2011, 08:49 AM

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

McLeary

03-10-2011, 08:58 AM

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.

prashun

03-10-2011, 09:11 AM

thanks McLeary, how do i find the local coordinates?

McLeary

03-10-2011, 09:18 AM

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.

prashun

03-10-2011, 09:32 AM

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();

McLeary

03-10-2011, 10:04 AM

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 (http://www.opengl.org/sdk/docs/man/xhtml/glGet.xml)). This matrix contains all the transformations (http://www.cs.uregina.ca/Links/class-info/405/WWW/Lab3/) that you do.

prashun

03-10-2011, 10:17 AM

thanks, i was trying to maintain the hierarchy.

prashun

03-10-2011, 01:47 PM

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

_arts_

03-10-2011, 02:28 PM

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.

McLeary

03-10-2011, 02:49 PM

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

... I am trying to find the XYZ coordinates of the last segment which is the hand while rotating the whole arm.

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.

prashun

03-11-2011, 12:56 AM

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??

McLeary

03-11-2011, 06:01 AM

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.

prashun

03-11-2011, 10:47 AM

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??

McLeary

03-11-2011, 11:08 AM

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)

... 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?? 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).

prashun

03-11-2011, 11:57 PM

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 ??

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

It's not really an OpenGL question.

Zenja

03-15-2011, 07:44 AM

Your transform will typically look like this:

MV = C*T*R1*R2*R3

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.

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.