Function Generator

From PeformIQ Wiki
Jump to navigation Jump to search

Function Generator

See - https://web.archive.org/web/20161126051349/http://www.albedo-cg.de/ImpactPrograms/impactGauss.rar

Hi, everybody!

Some of you might remember my old Python script that allowed you to generate detailed motion behaviors that otherwise would be almost impossible to program.

Good news! I'm working on a Java command line version of this program. I've added many new possibilities to create complex movements. A new addition will be the possibility to define space curves that the program translates into Impact compatible velocity functions.

Just for your information, here's a snippet of the in-program documentation:

/* List of arguments used:
 
    waveform: waveform/motion Shape, like tri, sin etc.
    motionProperty: which property is modulated? a, v, f, p etc.
    cycleLength: the length of one motion cycle in milliseconds. This is the time scale I'm using.
    Free timescale definition may be implemented later.
    amplitude: nuff said
    offset: this is the amplitude offset
    startTime: you know what I mean.
    stopTime: no comment.
    fileName: maybe this means the filename? Who knows?
    (shift): this doesn't exist yet. This will enable you to define a phase shifting of the wave.
    You need this for cosine (sin(alpha-90°)) for example.
 
    At the moment you have to enter the command line arguments in the exact order.
    I'll add a proper parsing routine so you can define the values in any order you want.
    Like this:
    w tri p ax l 0.5 s 0.0 e 2.5 a 1.0 o -0.33 f example.txt
    Which actually means:
    waveform tri motionProperty ax cycleLength 0.5ms startTime 0.0ms stopTime 4.5ms amplitude 1.0 offset 0.0 filename example.in
 
    */

To cope with the stopTime problem in case of different from zero/min/max crossing simply add another quarter cycle.

                The rest will be automatically interpolated.
 
                motionProperties have to be checked against standard properties as:
                a* (acceleration, ax,ay,az)
                ar*(rotational acceleration)
                f* (force)
                v* (velocity)
                p  (pressure)
 
                These Properties come with the following time behaviours (those marked with * are implemented):
 
                * tri: triangular time vs. property behavior
                * sin: sinusodial behavior
                  squ: square waveform behavior. pulse width modulation possible
                  gauss: a gauss-bell shaped waveform for single pulse events.
                  ram: ramp waveform - a clipped triangle waveform with variable asymmetry and width modulation, like this:
 
                     -----                 +
                    +     ++              +
                   +        ++           +
                  +           ++        +
                 +              ++     +
                +                 -----
 
                or
 
                   ---------               +
                   +        +              +
                  +          +            +
                  +           +           +
                 +             +         +
                 +              ----------
 
                The ramp waveform makes the square and tri waveform obsolete:
                - A ramp without caps is a tri waveform.
                - A ramp with maximum cap width is a square/rectangular waveform.
 
                A new property is defined, called "l" (location). The new property will make the definition of movements along paths a lot easier
                This type will then be translated into velocity that is readable by the program.
                For this a 2D or 3D treatment is essential, as the 2D/3D space vectors are needed to calculate velocity from space curves.
                The treatment is easy because the program uses linear interpolation to determine intermediate values.
 
                "l" defines the following trajectory shapes (The * marks implemented properties):
 
                lcirc: circle (good for eccentric simulations)
                lpoly: polygonal shape with n equal sides
                lelip: ellipse
                lwave: this is the ultimate goal. A wav-file used as displacement source. could be a bit hard for me at the beginning...

Entering the command line:

impactMotion.jar w tri p ax l 1.0 s 0.0 e 4.5 a 1.0 o 0.0 f example.in

which actually means:

waveform tri motionProperty ax cycleLength 1.0ms startTime 0.0ms stopTime 4.5ms amplitude 1.0 offset 0.0 filname example.in

gives the following result:

ax=[0.0,0.0,0.25,10.0,0.5,0.0,0.75,-10.0,1.0,0.0,1.25,10.0,1.5,0.0,1.75,
-10.0,2.0,0.0,2.25,10.0,2.5,0.0,2.75,-10.0,3.0,0.0,3.25,10.0,3.5,0.0,3.75,
-10.0,4.0,0.0,4.25,10.0,4.5,0.0,4.75,-10.0]

in the file example.in

This is a triangle waveform, as you can see.

I hope to finish the rest of the waveforms soon.

- Manuel_L Manuel_L Jul 13, 2006


New Function Generator for Gauss curves

Hi, everybody!

I've written a first version of the function generator for Impact but I'm rather unexperienced in JAVA, so I'm restructuring the code now.

The first generator that's ready is made for the definition of a Gauss curve.

The data precision you enter is double, so don't wonder about strange rounding errors like 9.89999999999998 instead of 9.9 :)

Simply use the program like this (in brackets stands the type of data you have to enter):

impactGauss.jar filename.txt(string) property(string) startTime(double) endTime(double) amplitude(double) sigma(double) peak(double) timeStep(double)

so entering

impactGauss.jar test.txt ax 0.0 1.0 1.0 0.1 0.3 0.025

means acceleration in x-direction, start at 0.0, end at 1.0, amplitude 1.0, sigma of Gauss curve 0.1, peak at 0.3, time steps at which values are calculated 0.025 This yields:

ax=[0.0,0.011108996538242316,0.025,0.022794180883612375,0.05,0.04393693362340742,
0.07500000000000001,0.07955950871822776,0.1,0.13533528323661276,0.125,0.2162651668298874,
0.15,0.3246524673583498,0.175,0.45783336177161427,0.19999999999999998,0.6065306597126334,
0.22499999999999998,0.7548396019890072,0.24999999999999997,0.8824969025845953,0.27499999999999997,
0.969233234476344,0.3,1.0,0.325,0.969233234476344,0.35000000000000003,0.8824969025845952,
0.37500000000000006,0.7548396019890069,0.4000000000000001,0.6065306597126329,0.4250000000000001,
0.4578333617716136,0.4500000000000001,0.3246524673583491,0.47500000000000014,0.21626516682988672,
0.5000000000000001,0.13533528323661245,0.5250000000000001,0.07955950871822744,0.5500000000000002,
0.04393693362340726,0.5750000000000002,0.022794180883612236,0.6000000000000002,
0.011108996538242247,0.6250000000000002,0.005086069231012664,0.6500000000000002,
0.0021874911181828677,0.6750000000000003,8.838263069350413E-,0.7000000000000003,
3.354626279025083E-4,0.7250000000000003,1.1961288358102309E-4,0.7500000000000003,
4.0065297392950425E-5,0.7750000000000004,1.2607105177048299E-4,0.8000000000000004,
3.726653172078585E-6,0.8250000000000004,1.0348542111093552E-6,0.8500000000000004,
2.6995785033629474E-7,0.8750000000000004,6.615601637697559E-8,0.9000000000000005,
1.5229979744712143E-8,0.9250000000000005,3.2937141103059874E-9,
0.9500000000000005,6.691586091292545E-10,0.9750000000000005,1.277111554512797E-10,1.0000000000000004,2.289734845645496E-11]

Don't forget that Gauss curves at the start need to have the peak at least 3*sigma (3 times the standard deviation) away from start time if you want the curve to start smoothly at near zero values. It's better to have the peak 3.5 or 4 times sigma away from the start time to be on the safe side.

Now you only need to copy and paste this text bit into your in-file and you're done.

The program doesn't have any type testing or any other exeption handling, only file writing is handled, so if you don't enter the values exactly in the correct order nothing will happen, you might get messed up data, your computer might explode or whatever ;)

I hope this small jar-file is useful to you. If you want to change something you can use the source code. I'll add lots of other mathematical curves later.

Get the jar-file and the java source from here:

http://www.albedo-cg.de/ImpactPrograms/impactGauss.rar

- Manuel_L Oct 16, 2006