3D, Graphics, Mechanical

Making a printable Cam

In this post we are going to explain the process of making a 3D printable Cam with OpenSCAD and a little bit of code I wrote.

In a nutshell, the code I wrote takes in a standard displacement diagram used to describe the increase and decrease in displacement of a Cam over time. Something that looks like this:

And uses that information to create a 3D model like this:

A cam on a cylinder (known as a disc cam).

A cam on a ramp (also known as an end cam).

If you don’t know what a Cam is then please read the previously linked Wikipedia page. But just because you know what it is does not explain why you would want to make one.

A Cam is an device that turns rotational motion into linear motion an many different ways; this is extremely powerful. In mechanical engineering is is pretty easy to create rotational motion (Electric Motor, Steam, Windmill, Treadmill with mice, etc). This is great and already useful but, in many cases, we then want to perform some kind of linear movement based on this rotation. For example, maybe we want to use the rotational motion to trigger a button a certain number of times per second (like an odometer). In this scenario the rotational motion needs to be turned into the linear motion of pushing the button up and down. This conversion is extremely useful and almost every modern petrol based engine uses a Cam via the aptly named Camshaft; the thing in your car which make the engine pistons go up and down.

However, I am personally very excited by the combination of combining a cam with a spring follower. This allows you to slowly store more and more energy in a spring and then release it all at once explosively, letting you create an automatic catapult. For a rudimentary example of what I mean please see this olive slinging device:

So, with that in mind I wrote a quick program in OpenSCAD to generate Cam for you. At this point in time you can generate two different types of Cam’s: a disc cam and an end cam. The two methods that allow that let you specify:

  • The displacement diagram of the Cam
    Given as a list of points from (0, 0) -> (1, 1) with linear interpolation between the points and points that retain the same displacement to infinity on either end of the diagram.
  • The number of segments
    Ultimately the Cam will not have a smooth surface but rather be built from a number of segments. The more segments then the more precision your Cam will have and the smoother the finish will be
  • The dimensions of the Cam
    How high should it be? How big should the radii be?

Lets run through a quick example to show you how it works. With these variables under your control you can then write openscad code that looks like this:

end_cam(displacement = [ [0, 0], [0.2, 0.8], [0.6, 0.5], [1, 1] ], 
   segments = 360, 
   baseHeight = 1, 
   peakHeight = 3, 
   radius = 2, 
   width = 0.5);

And it would produce a Cam that looked like this:

And here is an even more complex example where we made the displacement diagram be the (sin(x)) ^ 2 function.

[ for(i = [0 : 360]) [i / 360, sin(i) * sin(i)] ]

It looks great:

An edge cam generated with the sin(x) ^ 2 function.

And this is very very powerful, you can now create a cam for your own hobby purposes. Here is the full example of test Cams that you can view just by loading up the test-cam.scad file that exists in the source code:

If you wish to add extra fixtures to the Cam’s so that you can attach them to your motors or rotating mechanical devices then the union and difference functions from OpenSCAD are your friends. Good luck. I hope that this helps you on your mechanical endeavours and please post your creations made using this code in the comments section below. I can’t wait to see them!