Getting Kinbody COM

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting Kinbody COM

Alex
I am trying to get the center of mass of a Kinbody that I have added to the environment, but I receive the following error:

"'KinBody' object has no attribute 'GetCenterOfMass'"

My code is:

object = env.ReadKinBodyURI(objectfile)
env.Add(object, True)
COM = object.GetCenterOfMass()

From 'kinbody.cpp', line 1125, I found the function definition

Vector KinBody::GetCenterOfMass() const
{
    // find center of mass and set the outer transform to it
    Vector center;
    dReal fTotalMass = 0;

    FOREACHC(itlink, _veclinks) {
        center += ((*itlink)->GetTransform() * (*itlink)->GetCOMOffset() * (*itlink)->GetMass());
        fTotalMass += (*itlink)->GetMass();
    }

    if( fTotalMass > 0 ) {
        center /= fTotalMass;
    }
    return center;
}

It appears that the function is there, but it does not seem to be working.  Am I calling it wrong?  Is the object of a different KinBody class?  Is there another or better way to get the COM?  I don't want to use 'object.GetTransform()' because that returns the objects origin, which may not always be the COM depending on how the object file was created.  I also tried 'object.ComputeAABB()', but I don't know how to extract the data from the AABB object.  I keep getting errors like "'AABB' object has no attribute '__getitem__'"

Any suggestions would be appreciated.  Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Getting Kinbody COM

Rosen Diankov
Administrator
alex,

yup, you are right. it wasn't added to the python bindings. we just added it in this commit on the master branch:

https://github.com/rdiankov/openrave/commit/00ceea3c33c68c7fc8b9b9abee7c11da79d37e10

best,
rosen,


2014-03-09 6:23 GMT+09:00 Alex <[hidden email]>:
I am trying to get the center of mass of a Kinbody that I have added to the
environment, but I receive the following error:

"'KinBody' object has no attribute 'GetCenterOfMass'"

My code is:

object = env.ReadKinBodyURI(objectfile)
env.Add(object, True)
COM = object.GetCenterOfMass()

>From 'kinbody.cpp', line 1125, I found the function definition

Vector KinBody::GetCenterOfMass() const
{
    // find center of mass and set the outer transform to it
    Vector center;
    dReal fTotalMass = 0;

    FOREACHC(itlink, _veclinks) {
        center += ((*itlink)->GetTransform() * (*itlink)->GetCOMOffset() *
(*itlink)->GetMass());
        fTotalMass += (*itlink)->GetMass();
    }

    if( fTotalMass > 0 ) {
        center /= fTotalMass;
    }
    return center;
}

It appears that the function is there, but it does not seem to be working.
Am I calling it wrong?  Is the object of a different KinBody class?  Is
there another or better way to get the COM?  I don't want to use
'object.GetTransform()' because that returns the objects origin, which may
not always be the COM depending on how the object file was created.  I also
tried 'object.ComputeAABB()', but I don't know how to extract the data from
the AABB object.  I keep getting errors like "'AABB' object has no attribute
'__getitem__'"

Any suggestions would be appreciated.  Thanks!



--
View this message in context: http://openrave-users-list.185357.n3.nabble.com/Getting-Kinbody-COM-tp4026929.html
Sent from the OpenRAVE Users List mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works.
Faster operations. Version large binaries.  Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
_______________________________________________
Openrave-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openrave-users


------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Openrave-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openrave-users
Reply | Threaded
Open this post in threaded view
|

Re: Getting Kinbody COM

Diego
Hi Rosen,

I had the same problem that Alex. Now it is working but I had to add this
line to openravepy_kinbody.cpp (line 2844)

     .def("GetCenterOfMass",&PyKinBody::GetCenterOfMass,
DOXY_FN(KinBody,GetCenterOfMass))

otherwise the wrapper does not recognize the function.

Best,
Diego



--
View this message in context: http://openrave-users-list.185357.n3.nabble.com/Getting-Kinbody-COM-tp4026929p4027299.html
Sent from the OpenRAVE Users List mailing list archive at Nabble.com.

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Openrave-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openrave-users
Reply | Threaded
Open this post in threaded view
|

Re: Getting Kinbody COM

Diego
In reply to this post by Rosen Diankov
Hi Rosen,

I had the same problem that Alex. Now it is working but I had to add this line to openravepy_kinbody.cpp (line 2844)

     .def("GetCenterOfMass",&PyKinBody::GetCenterOfMass, DOXY_FN(KinBody,GetCenterOfMass))

otherwise the wrapper does not recognize the function. It would be great if you could commit it.

Best,
Diego