[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.&nbsp; 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>&nbsp;</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&nbsp;to=20
an object other than at its center of mass.&nbsp; At least I couldn't =
get it to=20
work.&nbsp; This was the fundamental problem I kept bumping into.&nbsp; =
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>&nbsp;</DIV>
<DIV><FONT color=3D#0000ff face=3DArial size=3D2><SPAN =
class=3D390552502-05062003>So, as=20
a workaround, I created a second body.&nbsp; I attach the hinge joint to =
the=20
first body, connecting it to the static environment.&nbsp; Then I attach =
the=20
second body to the first with a fixed joint.&nbsp; 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>&nbsp;</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>&nbsp;</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>&nbsp;&nbsp;</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.&nbsp; I want to have a sphere with =

  non-uniform mass rotating around an axis going throught the center of =
the=20
  sphere.&nbsp; I've modified test_boxstack.cpp to try this out, and no=20
  luck.&nbsp; </SPAN></FONT></DIV>
  <DIV><SPAN class=3D211241820-01062003></SPAN><FONT face=3DArial=20
  size=3D2>&nbsp;</FONT></DIV>
  <DIV><FONT size=3D2><FONT face=3DArial><SPAN =
class=3D211241820-01062003>Th<SPAN=20
  class=3D993475700-03062003>e</SPAN> sphere&nbsp;<SPAN=20
  class=3D993475700-03062003>in&nbsp;</SPAN><SPAN =
class=3D993475700-03062003>the=20
  code sample below </SPAN>should&nbsp;<SPAN =
class=3D993475700-03062003>start off=20
  rotating immediately - due to its displaced mass</SPAN>, but instead=20
  it&nbsp;<SPAN class=3D993475700-03062003>doesn't move at=20
  all!</SPAN></SPAN></FONT></FONT></DIV>
  <DIV><SPAN class=3D211241820-01062003></SPAN>&nbsp;</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.&nbsp; 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>&nbsp;</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>&nbsp;&nbsp;</FONT></DIV><FONT =
face=3DArial>
  <DIV><FONT size=3D2>else if (cmd =3D=3D 's') =
{<BR>&nbsp;&nbsp;&nbsp;sides[0] *=3D=20
  0.5;<BR>&nbsp;&nbsp;&nbsp;dMassSetSphere=20
  (&amp;m,DENSITY,sides[0]);<BR>&nbsp;&nbsp;&nbsp;obj[i].geom[0] =3D =
dCreateSphere=20
  (space,sides[0]);</FONT></FONT></DIV></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;dMass=20
  m2;<BR>&nbsp;&nbsp;&nbsp;dMassSetSphere=20
  (&amp;m2,DENSITY*3,sides[0]);<BR>&nbsp;&nbsp;&nbsp;dMassTranslate=20
  (&amp;m2,0,5,0);<BR>&nbsp;&nbsp;&nbsp;dMassAdd =
(&amp;m,&amp;m2);</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;printf ("Center of =
mass at:=20
  =
%f,%f,%f\n",m.c[0],m.c[1],m.c[2]);<BR>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&=
nbsp;dGeomSetPosition=20
  (obj[i].geom[0], -m.c[0], -m.c[1],=20
  -m.c[2]);<BR>&nbsp;&nbsp;&nbsp;dMassTranslate=20
  (&amp;m,-m.c[0],-m.c[1],-m.c[2]);</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;dJointID =
mHingeJoint =3D=20
  =
dJointCreateHinge(world,0);&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;dJointAttach=
(mHingeJoint,0,obj[i].body);<BR>&nbsp;&nbsp;&nbsp;const=20
  dReal* pos =3D=20
  =
dBodyGetPosition(obj[i].body);<BR>&nbsp;&nbsp;&nbsp;dJointSetHingeAnchor(=
mHingeJoint,pos[0],pos[1],pos[2]);<BR>&nbsp;&nbsp;&nbsp;printf=20
  ("Creating hinge at:=20
  =
%f,%f,%f\n",pos[0],pos[1],pos[2]);<BR>&nbsp;&nbsp;&nbsp;dJointSetHingeAxi=
s(mHingeJoint,1,0,0);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&n=
bsp;}</FONT></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0022_01C32AE0.5CD771D0--