Example 4: Damped Sine Wave Generator
We created a damped sine wave generator to demonstrate a little bit more elaborated programming in a class function. An example is shown in the following figure:
Double click on the SineGen part in the Canvas View or the TOP\SineGen name listed in the Tree View to obtain the following Part Properties dialog:
The write-protected Value column with a light yellow background color contains the values from the mySineGen object, from which this SineGen part is derived. The Override column contains the values local to the part, overriding the values from the object. When an Override field is blank, such as Current Angle in this example, the value from the object will be used. The Angle Increment is set to 5 degrees locally. You can click on the Unit cell to select a different unit of measure for this attribute. As a matter of fact, we set the internal unit to be radian so that all the internal calculations can be done without any unit conversion. We entered 5 degrees here as a part override value to "correct" the default value set in radian. However, the output in the first figure still shows angles with rounding errors. It is because all the calculations are done in radian unit internally. The complement of the Damping Factor (1.0 - Damping Factor) is used to scale-down the sine curve after each circular cycle (per 360 degrees). For example, when the damping factor is 0.2, the amplitudes of the sine wave in a cycle will be 80% of those of the previous cycle.
In Visual Calculator version 1.1, we interpolate the damping factor linearly within one cycle, rather than keeping in a constant as in version 1.0. The effect is that the discontinuity at the joint between two adjacent cycles is removed.
The cycle defined in the simulation control object indicates how many times the parts in the system are gone through, not the circular cycle in mathematics. Double click on the SimControl.Cycle.Calc_Default object in the Tree View of the Object tab (the first tab) to obtain an Object Properties dialog as following:
With the Ending Cycle Number set to 720 and 5 degrees Angle Increment set in the SineGen part, the simulation will be executed through a total of 3600 degrees, or 10 circular cycles. A damped sine curve, generated with a Damping Factor of 0.5, is plotted as below.
Again, if SansGUI cannot find the simulator DLL, please consult the instructions on Setting Simulator DLL Location at the bottom of Example 1.
You can follow the same Dynamic Charting procedures in Example 3 to take advantage of the new feature in SansGUI version 1.1 or later.
Go back to Introduction.
Visual Calculator for SansGUI Version 1.1
Copyright © 2001-2003 ProtoDesign, Inc. All rights reserved.