Controlled ODE-based bipeds/ragdolls

Hello, I’ve managed to create a simple ragdoll human based on that seen here:

http://monsterden.net/software/ragdoll-pyode-tutorial

But now I want to move on to actually controlling this model, making it stand/balance.

Could someone explain: what is the right approach for wielding control over the joints/body? Should I be using

hipJoint.addTorque(x)

or should I be applying forces to the separate bodies? In my mind, the most intuitive way would be to apply forces with respect to joints. I also gather than each click of the simulation the same forces must be applied if you want them to persist, is that right?

I’d like to know how to e.g. make a leg rigid, i.e. a knee joint. Do I apply two opposing torques to the joint, for example?

Any initial guidance in this sort of area would be very helpful thank you.

Greg

Its usually unwise to move a body in a full physics simulation - the vast majority of games surround the character by a large capsule and use that, switching to a ragdoll only on death. This avoids various problems, mostly notably its a lot harder for a single large capsule to get stuck on the geometry, when lots of little capsules will get stuck really easily.

However… if you do decide to go that route the first thing to realise is that you want to do it all via torque and forces - never apply velocity changes directly. What your then likely to do is have an animation and, every frame, calculate the torque/forces to move the current shape to the animations shape. But instead of applying those forces directly you then apply some kind of distortion to those forces, as otherwise the model will follow the animation precisely. Usually this would be a damping term and a limit - damping term so the player character doesn’t quite keep up and gets some physicality, and a force limit so the player take a few frames to recover when you apply ‘hit by bullet’ forces etc.

Personally, I’ld stick to a big capsule - far easier and far less problems to handle.

I think I’ve not made myself clear. I want to develop e.g. a neural net or an algorithm to actually control the body. So ignoring the processing required to do that, the effector side of the algorithm must influence the joints/bodies in some way. My question is how to actually apply corresponding forces to joints. For example, how do I make a joint rigid, so that a huge force would be required to actually ‘bend’ the joint. I’m not interested in keyframe animation.

Some examples/methods would be much appreciated.

Well, in that case I would think about letting the neural net control the torques directly - that is after all what human beings do by sending signals to the muscles. Though you might want to look into either motors or using joints with more constraint and a low erp, and then setting the joint parameters directly. Alternatively you could have the neural network output the desired angles between bones and calculate the torques from that. There are probably several other ways to do it as well. I’ld be more worried about the inputs to the neural network myself though - they are going to influence the ability of the network to do its job far more than the output.

Further to the above what I will say is that getting a neural network to solve that problem is going to be hard, really hard, and getting it to solve it in a ‘human’ way is going to require some extra ‘magic’ in terms of objective functions, and possibly force from angle translation (Smooth rather than jerky movements). I hope you have prior experience in making neural networks, and probably evolutionary algorithms for training, or an equivalent. (I don’t see how typical training is going to work, as scoring is for a sequence of runs.) Otherwise I think you will be biting off far more than you could ever hope to chew.

So you want a simulator that use ODE to simulate the physics and make a balance robot/human, like this one ? :
youtube.com/watch?v=puwZhbTOOqE

Or you just want to know how to program a joint in ODE ?

c4scroller, I’m the author of the tutorial you’ve linked to, and I’ve also made some efforts since writing it to create a full physics animation system (this was actually the original motivation for the project, I just decided to make the tutorial after I got the basic ragdoll working).

Anyways, what you want to do is really hard. However, I recently came across what looks like the best approach that has been developed for this purpose, a project called Dynamo. The site (with paper and videos) is here:

graphics.cs.williams.edu/papers/DynamoVGS06/

The basic idea doesn’t use anything like a neural net, instead it calculates the target position for each joint in world space given a standard animation, calculates ideal direct forces to apply to each joint, and uses these to determine torques to apply to each joint. This method is supposed to be much more stable than the more obvious method of trying to calculate torques directly, which I’ve tried and tends to lead to small errors which quickly accumulate and cause the animation to fall out of sync.

Implementing these techniques is a huge project, but at least this paper shows that it can be done fairly effectively.

Thanks for the replies. I appreciate based on my initial description this is a massive task, but ignoring that for a minute, could you specifically explain what methods I should be using? And what does a torque actually mean? Could I assume say for each hinge joint there are two variables (a,b) such that a is the force of the torque applied in one direction (rotation) and b the torque in the other direction (rotation). Can you just give me an idea of what results to expect e.g.

joint.addTorque(500)

applied each click would cause the joint to bend in a certain direction

or joint.addTorque(500); joint.addTorque(-500) somehow makes the joint more rigid?

I’m generally just not quite clear about what torques mean in the context of say a hinge joint.

Thanks

That is not as hard as you thought.

Human joint can be simulated using robotic like mechanism.

If you move your arm, you add a torque bigger than the load on your arm to the direction of movement. It is too complicated in general to do this.

You can consider the joint as a servo motor like devices. A servo motor maintain a torque to keep the joint to a decided angle, and automatically move the fix the deviation according to the physical parameters of the motor. It usually has a maximum torque, maximum moving velocity and etc.

Human joint can be simplified to a servo motor joint. Actually a nerve system provide a feedback to your brain to allow your brain to fix the deviation of your joint when you move.

The code to move a servo joint is like this:

        # setup
        self.vel = pi/3.0/0.22 # max velocity
        F = 12000 * gravity # max torque
        self.hindgejoint.setParam(ode.ParamFMax, F) # 12 kg-g per cm
        self.hindgejoint.setParam(ode.ParamVel, 0)
        self.err = 0

       # The control loop:
        self.angle = self.hindgejoint.getAngle()
        if self.dt >= self.t:
            targetangle = self.targetangle
        else:
            self.dt += dt
            targetangle = (self.targetangle - self.original) * self.dt / self.t + self.original
        err = self.angle - targetangle
        if err > 0:
            v = -self.vel
        else:
            v = self.vel
        err = abs(err)

        deadband = 0.0
        cutoff = 0.036
        if err <= deadband/1024.0 * pi:
            v = 0
        elif err < cutoff:
            v *= (err) / cutoff / 2
        self.hindgejoint.setParam(ode.ParamVel, v)