## pyode-user

 [Pyode-user] force,mass and geomtransform problem From: Ting Li - 2007-04-30 16:43:31 Attachments: Message as HTML ```Hello, I'm learning Pyode now. I'm blocked by the usage of 'geomtransform' and the mass property. I intended to make a dumbell in the ode world, composed of two geoms connecting to one ode body. When I touch or something hits one of the two balls, the dumbbell should rotate. (as the center of mass is in the middle) I made the following program to test if a force acting on a point other than the center of mass can make body1 rotate about its center of mass? I first move the center of mass of body1 to M1.translate((0.0, 5.0, 0.0)) Then I add a force in x direction at a relative position (0,1,0) ode_body1.addForceAtRelPos((-100.0,0.0,0.0),(0.0,1.0,0.0)) I expect the sphere1 should move in an arc. But I cannot see the change in y-axis. what's wrong here? BTW, can anyone give an example of a dumbbell I described above using geomtransform? Thanks in advance! ################################################################# import ode def near_callback(args,geom1,geom2): '''callback function for ODE collision detect''' #check if two geoms do collide contacts = ode.collide(geom1, geom2) #get args world,contactgroup = args for c in contacts: c.setBounce(1.0) #bounceness 0-1 c.setMu(0) #friction #create contact joint and add it to two bodies j = ode.ContactJoint(world,contactgroup,c) j.attach(geom1.getBody(),geom2.getBody()) pass # Create a ODE world object ode_world = ode.World() ode_world.setERP(0.8) ode_world.setCFM(1E-5) # Create a space object ode_space = ode.Space() # A joint group for the contact joints that are generated whenever # two bodies collide ode_contactgroup = ode.JointGroup() #add ode bodies ode_body1 = ode.Body(ode_world) M1 = ode.Mass() M1.setSphere(1000.0, 1.0) M1.mass = 1.0 #move the center of gravity M1.translate((0.0, 5.0, 0.0)) print M1 ode_body1.setMass(M1) #add geom for body1 geom1 = ode.GeomSphere(ode_space, radius = 1.0) geom1.setBody(ode_body1) #add ode bodies ode_body2 = ode.Body(ode_world) M2 = ode.Mass() M2.setSphere(1000.0, 1.0) M2.mass = 1.0 print M2 ode_body2.setMass(M2) #add geom for body2 geom2 = ode.GeomSphere(ode_space, radius = 1.0) geom2.setBody(ode_body2) #place two bodies along x axis geom1.setPosition((-1.5, 0.0, 0.0)) geom2.setPosition((1.5, 0.0, 0.0)) #add some force ##ode_body1.addForceAtPos((-100.0,0.0,0.0),(0.0,0.0,0.0)) ode_body1.addForceAtRelPos((-100.0,0.0,0.0),(0.0,1.0,0.0)) #assign a negative velcocity in x-axis to collide with body1 ##ode_body2.setLinearVel((-0.5,0,0)) dt=0.0001 while 1: print ode_body1.getPosition(),ode_body2.getPosition() ode_space.collide((ode_world,ode_contactgroup),near_callback) ode_world.step(dt) ode_contactgroup.empty() ############################################################################ ```
 Re: [Pyode-user] force,mass and geomtransform problem From: Ethan Glasser-Camp - 2007-05-01 06:12:58 Attachments: signature.asc ```Sorry to Ting Li for the duplicate messages -- I do this all the time, I'm really sorry. Ting Li wrote: > I expect the sphere1 should move in an arc. But I cannot see the change= > in y-axis. > what's wrong here? BTW, can anyone give an example of a dumbbell I > described above > using geomtransform? Thanks in advance! Hi, I just started looking at your program and haven't found anything yet, but one suggestion I would make: when troubleshooting, take out as much code as you can, and see if you still have the error. In ODE, the dynamics is done separately from the collision detection. You could take out the collision detection, the contactGroup, the GeomSpheres, and see if you still have the same problem. Basically, I think the behavior you are seeing is "correct", but not what you want. The center of mass of a body is always at that object's center, as far as I know, even when you use mass.translate(). I think mass.translate() is only useful for combining masses and finding out where their combined center of mass will be. You might want to try joining the two bodies together using a joint, or using GeomTransform. I don't have an example handy right now, sorry. Ethan ```