[ODE] Need help with hinge and non-uniformly distributed mass
Keith Johnston
kjohnston at pinolisoftware.com
Wed Jun 4 19:32:01 2003
This is a multi-part message in MIME format.
------=_NextPart_000_0022_01C32AE0.5CD771D0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Well, I found a way to do it. I hope someone will tell me if there is a
better way.
First of all, I do not think it is possible to attach a hinge joint
anywhere to an object other than at its center of mass. At least I
couldn't get it to work. This was the fundamental problem I kept
bumping into. I wanted to have a single mass swing back and forth like
a pendulum.
So, as a workaround, I created a second body. I attach the hinge joint
to the first body, connecting it to the static environment. Then I
attach the second body to the first with a fixed joint. I don't draw
the second body or let it have anything to do with collisions - it is
basically just allowing the first object to act as if its center of mass
was displaced.
This allowed me to have a single object swing back and forth like a
pendulum.
-----Original Message-----
From: ode-admin@q12.org [mailto:ode-admin@q12.org] On Behalf Of Keith
Johnston
Sent: Monday, June 02, 2003 8:02 PM
To: ode@q12.org
Subject: [ODE] Need help with hinge and non-uniformly distributed mass
I'm hoping someone can spot what I'm doing wrong here. I want to have a
sphere with non-uniform mass rotating around an axis going throught the
center of the sphere. I've modified test_boxstack.cpp to try this out,
and no luck.
The sphere in the code sample below should start off rotating
immediately - due to its displaced mass, but instead it doesn't move at
all!
If I remove the hinge, the sphere rolls around on the floor as if its
mass was distributed unevenly, which I would expect. So why does it not
rotate unevenly with the hinge in place?
Thanks,
Keith
else if (cmd == 's') {
sides[0] *= 0.5;
dMassSetSphere (&m,DENSITY,sides[0]);
obj[i].geom[0] = dCreateSphere (space,sides[0]);
dMass m2;
dMassSetSphere (&m2,DENSITY*3,sides[0]);
dMassTranslate (&m2,0,5,0);
dMassAdd (&m,&m2);
printf ("Center of mass at: %f,%f,%f\n",m.c[0],m.c[1],m.c[2]);
dGeomSetPosition (obj[i].geom[0], -m.c[0], -m.c[1], -m.c[2]);
dMassTranslate (&m,-m.c[0],-m.c[1],-m.c[2]);
dJointID mHingeJoint = dJointCreateHinge(world,0);
dJointAttach(mHingeJoint,0,obj[i].body);
const dReal* pos = dBodyGetPosition(obj[i].body);
dJointSetHingeAnchor(mHingeJoint,pos[0],pos[1],pos[2]);
printf ("Creating hinge at: %f,%f,%f\n",pos[0],pos[1],pos[2]);
dJointSetHingeAxis(mHingeJoint,1,0,0);
}
------=_NextPart_000_0022_01C32AE0.5CD771D0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<TITLE>Message</TITLE>
<META content=3D"MSHTML 5.00.3502.5390" name=3DGENERATOR></HEAD>
<BODY>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D390552502-05062003>Well,=20
I found a way to do it. I hope someone will tell me if there is a =
better=20
way.</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D390552502-05062003></SPAN></FONT> </DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D390552502-05062003>First=20
of all, I do not think it is possible to attach a hinge joint =
anywhere to=20
an object other than at its center of mass. At least I couldn't =
get it to=20
work. This was the fundamental problem I kept bumping into. =
I wanted=20
to have a single mass swing back and forth like a =
pendulum.</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D390552502-05062003></SPAN></FONT> </DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D390552502-05062003>So, as=20
a workaround, I created a second body. I attach the hinge joint to =
the=20
first body, connecting it to the static environment. Then I attach =
the=20
second body to the first with a fixed joint. I don't draw the =
second body=20
or let it have anything to do with collisions - it is basically just =
allowing=20
the first object to act as if its center of mass was=20
displaced.</SPAN></FONT></DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN=20
class=3D390552502-05062003></SPAN></FONT> </DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D390552502-05062003>This=20
allowed me to have a single object swing back and forth like a=20
pendulum.</SPAN></FONT></DIV>
<DIV> </DIV>
<BLOCKQUOTE=20
style=3D"BORDER-LEFT: #0000ff 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT: =
0px; PADDING-LEFT: 5px">
<DIV></DIV>
<DIV align=3Dleft class=3DOutlookMessageHeader dir=3Dltr =
lang=3Den-us><FONT=20
face=3DTahoma size=3D2>-----Original Message-----<BR><B>From:</B>=20
ode-admin@q12.org [mailto:ode-admin@q12.org] <B>On Behalf Of </B>Keith =
Johnston<BR><B>Sent:</B> Monday, June 02, 2003 8:02 PM<BR><B>To:</B>=20
ode@q12.org<BR><B>Subject:</B> [ODE] Need help with hinge and =
non-uniformly=20
distributed mass<BR><BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2> </FONT>=20
<DIV><FONT face=3DArial size=3D2><SPAN class=3D211241820-01062003>I'm =
hoping someone=20
can spot what I'm doing wrong here. I want to have a sphere with =
non-uniform mass rotating around an axis going throught the center of =
the=20
sphere. I've modified test_boxstack.cpp to try this out, and no=20
luck. </SPAN></FONT></DIV>
<DIV><SPAN class=3D211241820-01062003></SPAN><FONT face=3DArial=20
size=3D2> </FONT></DIV>
<DIV><FONT size=3D2><FONT face=3DArial><SPAN =
class=3D211241820-01062003>Th<SPAN=20
class=3D993475700-03062003>e</SPAN> sphere <SPAN=20
class=3D993475700-03062003>in </SPAN><SPAN =
class=3D993475700-03062003>the=20
code sample below </SPAN>should <SPAN =
class=3D993475700-03062003>start off=20
rotating immediately - due to its displaced mass</SPAN>, but instead=20
it <SPAN class=3D993475700-03062003>doesn't move at=20
all!</SPAN></SPAN></FONT></FONT></DIV>
<DIV><SPAN class=3D211241820-01062003></SPAN> </DIV>
<DIV><FONT size=3D2><FONT face=3DArial><SPAN =
class=3D211241820-01062003>If I remove=20
the hinge, the sphere rolls around on the floor as if its mass was =
distributed=20
unevenly, which I would expect. So why does it not rotate =
unevenly with=20
the hinge in place?</SPAN></FONT></FONT></DIV>
<DIV><SPAN class=3D211241820-01062003></SPAN><FONT face=3DArial=20
size=3D2> </FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D211241820-01062003>Thanks,</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D211241820-01062003>Keith</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2> </FONT></DIV><FONT =
face=3DArial>
<DIV><FONT size=3D2>else if (cmd =3D=3D 's') =
{<BR> sides[0] *=3D=20
0.5;<BR> dMassSetSphere=20
(&m,DENSITY,sides[0]);<BR> obj[i].geom[0] =3D =
dCreateSphere=20
(space,sides[0]);</FONT></FONT></DIV></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> dMass=20
m2;<BR> dMassSetSphere=20
(&m2,DENSITY*3,sides[0]);<BR> dMassTranslate=20
(&m2,0,5,0);<BR> dMassAdd =
(&m,&m2);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> printf ("Center of =
mass at:=20
=
%f,%f,%f\n",m.c[0],m.c[1],m.c[2]);<BR> <BR> &=
nbsp;dGeomSetPosition=20
(obj[i].geom[0], -m.c[0], -m.c[1],=20
-m.c[2]);<BR> dMassTranslate=20
(&m,-m.c[0],-m.c[1],-m.c[2]);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> dJointID =
mHingeJoint =3D=20
=
dJointCreateHinge(world,0); <BR> dJointAttach=
(mHingeJoint,0,obj[i].body);<BR> const=20
dReal* pos =3D=20
=
dBodyGetPosition(obj[i].body);<BR> dJointSetHingeAnchor(=
mHingeJoint,pos[0],pos[1],pos[2]);<BR> printf=20
("Creating hinge at:=20
=
%f,%f,%f\n",pos[0],pos[1],pos[2]);<BR> dJointSetHingeAxi=
s(mHingeJoint,1,0,0);<BR> <BR> &n=
bsp;}</FONT></DIV></BLOCKQUOTE></BODY></HTML>
------=_NextPart_000_0022_01C32AE0.5CD771D0--