Summary
The purpose of this blog is two-fold. First, to successfully automate the generation of a camshaft lobe profile using Python scripting within ANSYS SpaceClaim. Second, to learn to avoid certain pitfalls related to Python scripting within ANSYS SpaceClaim.
Details
Now, let’s talk about “why” one would want to automate the generation of a camshaft lobe?
Within 4-stroke internal combustion engines, the camshaft is responsible for opening and closing the intake and exhaust valves relative to the rotation of the engine’s crankshaft. The camshaft is part of the “valvetrain”, which is a system of components which dictate when these valves open and close, how far they open, and the rate at which that valve opens and closes. Depending on the valvetrain configuration, there may be different components involved, and all of those components must be evaluated together to understand the details of the valve timing event. Creating the camshaft lobe profile is not entirely arbitrary, and at times can be quite complex. By automating the process of generating this profile allows one to subsequently evaluate the valve timing event more expeditiously during the valvetrain design process.
What are we going to do now?
We will first understand the type of camshaft profile we are going to model, then generate the geometry manually, while recording our actions within SpaceClaim Scripting to generate native Python code.
Next, we will “try” to use that same code within a new instance of SpaceClaim to learn what obstacles present themselves and prescribe remedies to those obstacles. Then successfully use Python scripting to replicate our originally designed camshaft lobe.
Finally, we will parameterize the Python scripting to allow one to rapidly generate new variations of this profile.
Our Camshaft Profile
Camshaft lobe profiles can range from simple to complex, symmetrical or asymmetrical. This blog will focus on one of the most fundamental designs which is based on a base circle and a nose circle. The two circles are connected by lines tangential to both circles.
We will start with a base circle of 38 mm, and a nose circle of 26 mm, with its center located 14 mm above the base circle center. Our first action will be to open SpaceClaim, then access the scripting interface.
By default, the “Record” mode will be active.
First, let’s understand what is recorded after adding our base circle.
Specifically, we see that a sketch plane has been define, then a circle has been generated, then a constraint has been generated. Let’s copy this same Python code into a new instance of SpaceClaim and learn if we can run it successfully?
The answer is “No”. Why? Because of how one normally selects the sketch plane. Let’s close this instance of SpaceClaim and open a new instance. We will make a change on how we record our script, generate a new circle and repeat our test.
First, we will activate the “Verbose” recording option.
Next, we will change how selection are recorded from “Smart Variable” to “Ray”.
Our recorded script after adding our base circle now looks different.
Operating this new script within a new instance of SpaceClaim now successfully generates our base circle!
What about the other actions, adding the nose circle and two tangent lines?
Success! Copying this new script into a new instance of SpaceClaim replicates our geometry. So far, so good. We will, however, experience problems if we try to parameterize our geometry. I will change the nose circle diameter from 26 mm to 20 mm to demonstrate.
We experienced these problems related to “Selecting” objects in our model. It turns out that selecting will be our biggest challenge. Therefore, I propose that we reduce "selections" as much as possible for this geometry. Selecting items like lines and circles should be avoided. To do this, we will create the geometry by different means. Instead of adding circles and making tangent lines to connect them, we will create arcs, then connect the arc ends from the base to the nose. This method requires that we need to be much more thoughtful in the construction of our script.
Review of Scripting Blocks
We saw that when we recorded our original script (adding a circle) there were certain elements in the scripting block.
# Sketch Circle
origin = Point2D.Create(MM(0), MM(0))
result = SketchCircle.Create(origin, MM(19))
baseSel = SelectionPoint.Create(GetRootPart().DatumPlanes[0].Curves[0].GetChildren[ICurvePoint]()[0])
targetSel = SelectionPoint.Create(GetRootPart().DatumPlanes[0].GetChildren[IDatumLine]()[0])
result = Constraint.CreateCoincident(baseSel, targetSel)
# EndBlock
We see that two points are defined: “origin” and “MM(19)”. Therefore, the “SketchCircle.Create” function requires an origin and radius to be defined. Everything else in this block relates to selecting the item we created and constraining it to the plane. I will propose that this last section is not required to successfully generate our geometry. Therefore, I recommend to delete these superfluous commands and simply run the following script.
# Sketch Circle
origin = Point2D.Create(MM(0), MM(0))
result = SketchCircle.Create(origin, MM(19))
# EndBlock
And… it works!
Now, I suggest to examine for yourself by recording scripting blocks for arcs and lines to identify those essential elements required to generate the camshaft profile. I have already done this and have attached my script here for your review.
I have also parameterized my script to terms typically used while identifying automotive camshaft characteristic, such as:
Using these parameters, the following geometry will be generated.
Download this script and begin exploring camshaft profile design… and learn about making practical Python scripts for SpaceClaim while you’re at it!! 😊