How to extract contact force solution and supply own warm start iterate

Discuss issues specific the Python port of Box2D
kenny
Posts: 2
Joined: Tue Jan 23, 2018 8:38 am

How to extract contact force solution and supply own warm start iterate

Postby kenny » Wed Jan 24, 2018 1:08 am

Hi,

I have been looking into the API code, python manual and examples to learn how to iterate over all active contacts and extract the contact force solution computed during the last time-step.

I would also very much like to supply my own warm start iterate for the next time-step. It this possible at all? I could only find a boolean flag argument that can be passed to the Step method. I would also like to specify the normal/friction force values to use for the warm-starting?

Thx

Kenny

kenny
Posts: 2
Joined: Tue Jan 23, 2018 8:38 am

Re: How to extract contact force solution and supply own warm start iterate

Postby kenny » Tue Jan 30, 2018 2:29 am

After substantial code digging, this is the closest I have been on extrating the contract graph from pyBox2D.

Something is not quite right. I can not quite figure out how to uniquely identify a body. Using id() does not quite work. Same problem for shapes. I guess these are copied internally and are not unique allocated instances?

  • Is there some way to get a unique id of shapes and bodies?
  • What happens if I force simulator to single step, turn on warm-starting and overwrite the normal- and tangentialImpulse values stored in the manifold points. Can I force my own warm-start solution this way?

Code: Select all

 
    print('-------------------------------------------------------------------')
        for body in self.world.bodies:
            if len(body.fixtures) > 0:
                print('body:')
                print('\tbody ID   = ', id(body))
                for fixture in body.fixtures:
                    print('\t\tshape id = ', id(fixture.shape))
                    if fixture.shape.type is 1:
                        print('\t\tedge vertices = ', fixture.shape.vertices)
                    else:
                        print('\t\tcircle radius = ', fixture.shape.radius)
                print('\ttype    = ', 'free' if body.type is b2_dynamicBody else 'fixed')
                print('\tx       = ', body.position(0))
                print('\ty       = ', body.position(1))
                print('\ttheta   = ', body.angle)
                print('\tmass    = ', body.mass)
                print('\tinertia = ', body.inertia)
                print('\tvx      = ', body.linearVelocity(0))
                print('\tvy      = ', body.linearVelocity(1))
                print('\tomega   = ', body.angularVelocity)

        for contact in self.world.contacts:
            master = contact.fixtureA.body
            slave = contact.fixtureB.body
            master_shape = contact.fixtureA.shape
            slave_shape = contact.fixtureB.shape
            for i in range(contact.manifold.pointCount):
                point = contact.worldManifold.points[i]
                normal = contact.worldManifold.normal
                manifold_point = contact.manifold.points[i]
                impulse = (manifold_point.normalImpulse, manifold_point.tangentImpulse)
                print('contact:')
                print('\tmaster          = ', id(master))
                print('\tmaster shape id = ', id(master_shape))
                print('\tslave           = ', id(slave))
                print('\tslave shape id  = ', id(slave_shape))
                print('\t\tpx     =', point[0])
                print('\t\tpy     =', point[1])
                print('\t\tnx     =', normal.x)
                print('\t\tny     =', normal.y)
                print('\t\tFn     =', impulse[0])
                print('\t\tFt     =', impulse[1])


Return to “Python”



Who is online

Users browsing this forum: No registered users and 1 guest