Explanation

import pygame
from pygame.locals import *
import ode

In this example we'll start creating an output that's visually a bit more
appealing than the output of the first tutorial. We'll use the
pygame package to open a window which we'll use to display a 2D animation
of the simulated bodies. So here we import the necessary pygame stuff
and, of course, we also import ode.

We create another ball joint and connect body2 with body1. The joint
is placed at the same position than body1. So this means we have another
pendulum which we attach to the first pendulum.

# Simulation loop...
fps = 50
dt = 1.0/fps
...

Here you can set the desired frame rate (fps) which also
determines the simulation time step (dt).

The remainder of the program is actually nothing new, there's just a bit
more code since we have to deal with a graphics window where we draw the
bodies and which receives user events.

If you run the program you see a swinging double pendulum.

Using Motors

Now we modify the program and make the first joint a motor driven
joint. To do so, we have to replace the ball joint with another joint
since ball joints don't support motors. We'll use a hinge joint instead.
So please replace the definition of the first joint j1 with
the following lines:

The first three lines are almost identical to the previous version,
we just used a HingeJoint instead of a BallJoint. The last line sets
the Z axis as rotation axis (by default the X axis is used). The Z axis
is the one that's perpendicular to your monitor screen. If you run the
program now, you won't notice a big difference since we're in 2D anyway.
But now add these lines:

j1.setParam(ode.ParamVel, 3)
j1.setParam(ode.ParamFMax, 22)

The first line sets the angular speed that the motor should maintain
and the second is the maximum force the motor allowed to apply. Now run the
program and you'll see the joint is driven by a motor, a rather weak one
in this case since it has difficulties to maintain the velocity. Please
try different values for the velocity and maximum force and see
what happens.

So you've seen, all you have to do to switch on a motor is to set
the maximum force to something else than zero, then it will try to
maintain the currently set velocity value. The motor is switched off
again by setting FMax back to zero.