I recently had to put together "yet-another steam engine" and this time I set up the animation in the more up-to-date way that is now possible with the Constraints system. If you're still "mashing Control-P," read on . . .
(1) The essential (moving) parts of any reciprocating steam-engine are, of course: the driven axle; the crank-wheel (with its protruding crank-pin); the connecting rod; and the piston (rod). Although in real life the piston forces the axle to turn, in animation it is easiest to cause the axle to rotate, "dragging along" the rest of the moving parts. Let's also put a "linking pin" cylinder at the end of the piston rod, this being the other short horizontal shaft that the connecting-rod will appear to be connected to.
(2) Begin by building the various parts and setting them in their correct positions in 3D space. Use the "snap to grid" to put all of these parts directly in a straight line: axle, crank-pin, connecting-rod, and piston. The machine is, as steam-buffs would say, "on dead- center." The orientation of each piece is therefore directly in-line with the "X" axis. (This is only important in the case of the connecting-rod, where the local X-axis needs to point directly down the center of the length of the rod.)(Get in the habit of being a lazy modeler: since the only thing you can see is the portion of the piston-rod that sticks out of the end of the cylinder, you don't need to model the piston itself ... just the rod ... unless you plan on doing a cut-away. Don't bother the computer with any geometry that won't actually be seen, even if the real-machine had it.)
(3) Now, begin adding Child Of constraints ... the modern and more-flexible equivalent of "parenting." The crank-pin, the crank and the flywheel are all children of the axle (which is the component that you will actually animate). Now, when you rotate the axle, the crank, pin and flywheel all turn as though they were connected, but the piston and connecting-rod do not.
(4) Now add a constraint to make the piston a child of the crank-pin ... that little "planet" that's orbiting merrily around the center of the axle because it's sticking out of (as though attached to) the crank, which is also rotating. Now, here's the first bit of very-necessary voodoo: un-check all of the influence-buttons except LocX. We only want the X-coordinate of the piston rod to change as it tracks the crank-pin ... which will be orbiting around the axle. "Only the X-coordinate" of the crank-pin influences "only the X-coordinate" of the piston. Since the pin is rotating around the axis, it's automatically providing us with a correct cosine-curve that describes the horizontal motion. Now, when you rotate the axle once again, the piston slides back and forth correctly. The connecting-rod does not move.Important: You'll need to press the "Set Offset" button, on the constraint-pane, each time you add a Child Of constraint. This causes the object to "snap back to where it belongs" (after it undoubtedly "moved somewhere-else" as soon as you added the constraint...).
(5) Now make the linking-pin a child of the piston, so that as the piston moves back and forth, the linking-pin moves along with the piston that it's supposed to be connected to, instead of just sitting there stupidly in space.(As you can plainly see, I am having you test each step as you go... we haven't gotten to the connecting-rod yet.)
(6) Finally, the connecting-rod. Let's start by snapping the cursor to the center of the crank-pin. Then, select the connecting-rod and hit Center Cursor to put the "center of" the rod at that spot. This is what the rod will "rotate around," so make the connecting-rod a child of that rod. If you test the animation now, the connecting-rod will be flying around (incorrectly) in free space as though it were welded to the crank-pin.
(7) Now for the second bit of voodoo: add a Locked Track constraint to the connecting rod. The "target" is the linking-pin. The "To" axis is X, since that's the "nose of the hound-dog" that needs to always point toward that pin. The "Lock" axis, which is what it rotates around, therefore is Y.
Please note the following:
- If all is well, then the connecting-rod is now pointing directly (along its local X-axis) toward the link-pin while its other end moves with its parent, the crank-pin. If you find that it "doesn't line up," it's because the connecting-rod's mesh isn't in-line with its local X-axis. To make adjustments here, temporarily "turn off" the two constraints by setting their Influence sliders to 0.0. Adjust the mesh (or simply replace it), then turn the Influences back to 1.0.
- Since objects customarily rotate around their centers, you may also need to adjust those centers. In this case, it's easiest to remove the Child Of constraint, then adjust the centers, then put the constraint back.
- The order of the constraints does matter: assuming that you just used an "ordinary" Child Of constraint ("no buttons mashed") to link the connecting-rod to the crank pin, the Locked Track constraint needs to appear after it... since this constraint needs to be the final arbiter of RotY of the connecting-rod.
- Yes, you can also use armatures to do this. You used to have to have a lot of "empties." But because the Child Of constraint is more flexible than parenting (it has buttons to individually determine what IPOs are influenced...), you don't need them anymore.
- The "eccentric," and other valve-gear pieces, are actually quite easily added in the same way should the need arise: this piece obviously is an ellipsoidal cylinder (stretched along the "X" axis), and then moved slightly along the "X" axis before being made a Child Of the axle. The valve-rod will then be made to follow (the "center of") the eccentric in the usual way, and once again the motion will magically be correct.