UNPKG

@strato-automation/node-red-contrib-strato-automation

Version:
157 lines (140 loc) 6.41 kB
<!-- Inspired by: https://github.com/natcl/node-red-contrib-lfo/tree/master --> <script type="text/javascript"> RED.nodes.registerType('signal-generator',{ category: 'Strato Automation', color: '#f3b567', defaults: { name: {value:""}, waveform: {value: "sine"}, period: {value: 60, validate:RED.validators.number()}, samplingrate: {value: 2, validate:RED.validators.number()} }, inputs:1, outputs:1, icon: "serial.png", label: function() { return this.name||"Signal Generator"; }, paletteLabel: "Signal Generator", oneditprepare: function () { $( "#node-input-period" ).spinner({min:0}); $( "#node-input-samplingrate" ).spinner({min:1}); } }); </script> <script type="text/html" data-template-name="signal-generator"> <!-- Basic Settings --> <div class="form-tips" style="margin-bottom: 20px;"> <b>Basic Settings</b> </div> <div class="form-row"> <label for="node-input-name"><i class="fa fa-bookmark"></i> Name</label> <input type="text" id="node-input-name" placeholder="Optional name for this generator"> </div> <div class="form-row"> <label for="node-input-waveform"><i class="fa fa-wave-square"></i> Waveform</label> <select id="node-input-waveform" style="width: 70%;"> <option value="sine">Sine</option> <option value="saw">Saw</option> <option value="saw_i">Inverted Saw</option> <option value="triangle">Triangle</option> <option value="square">Square</option> <option value="sig">Sigmoid</option> </select> </div> <!-- Timing Settings --> <div class="form-tips" style="margin: 20px 0;"> <b>Timing Settings</b> </div> <div style="padding-left: 10px; border-left: 3px solid #ddd;"> <div class="form-row"> <label for="node-input-period"><i class="fa fa-clock-o"></i> Period</label> <input type="text" id="node-input-period" placeholder="60" style="text-align:end; width:70px !important"> <span class="form-tips" style="margin-left: 10px;">Seconds per cycle</span> </div> <div class="form-row"> <label for="node-input-samplingrate"><i class="fa fa-tachometer"></i> Sampling Rate</label> <input type="text" id="node-input-samplingrate" placeholder="2" style="text-align:end; width:70px !important"> <span class="form-tips" style="margin-left: 10px;">Seconds between samples</span> </div> </div> <div class="form-tips" style="margin-top: 20px;"> <p><i class="fa fa-info-circle"></i> Tip: Higher sampling rates provide smoother output but consume more CPU resources.</p> </div> </script> <script type="text/html" data-help-name="signal-generator"> <p>A versatile signal generator that produces various waveforms with configurable timing parameters.</p> <h3>Inputs</h3> <dl class="message-properties"> <dt>payload <span class="property-type">number | "stop"</span></dt> <dd> <ul> <li>Number: Updates the period (in seconds)</li> <li><code>"stop"</code>: Stops the signal generation</li> </ul> </dd> <dt class="optional">waveform <span class="property-type">string</span></dt> <dd> Dynamically change the waveform type: <ul> <li><code>sine</code> - Sinusoidal wave</li> <li><code>saw</code> - Sawtooth wave (rising)</li> <li><code>saw_i</code> - Inverted sawtooth (falling)</li> <li><code>triangle</code> - Triangular wave</li> <li><code>square</code> - Square wave</li> <li><code>sig</code> - Sigmoid wave</li> </ul> </dd> </dl> <h3>Outputs</h3> <dl class="message-properties"> <dt>payload <span class="property-type">number</span></dt> <dd>Generated signal value between -1 and 1</dd> <dt>topic <span class="property-type">string</span></dt> <dd>Set to "default"</dd> </dl> <h3>Configuration</h3> <dl class="message-properties"> <dt>Name <span class="property-type">string</span></dt> <dd>Optional name to identify the node in the flow</dd> <dt>Waveform <span class="property-type">string</span></dt> <dd> The type of wave to generate: <ul> <li><b>Sine</b> - Smooth periodic oscillation</li> <li><b>Saw</b> - Linear rise, instant fall</li> <li><b>Inverted Saw</b> - Instant rise, linear fall</li> <li><b>Triangle</b> - Linear rise and fall</li> <li><b>Square</b> - Instant transitions between high/low</li> <li><b>Sigmoid</b> - S-shaped curve</li> </ul> </dd> <dt>Period <span class="property-type">number</span></dt> <dd>Time in seconds for one complete cycle of the waveform</dd> <dt>Sampling Rate <span class="property-type">number</span></dt> <dd>Time in seconds between samples (minimum 1 second)</dd> </dl> <h3>Details</h3> <p>The node generates continuous waveforms with values between -1 and 1. Key features include:</p> <ul> <li>Dynamic period adjustment through input messages</li> <li>Runtime waveform type switching</li> <li>Configurable sampling rate for performance control</li> <li>Automatic startup after node deployment</li> <li>Clean shutdown on flow stop</li> </ul> <h3>Performance Considerations</h3> <ul> <li>Lower sampling rates (higher values) reduce CPU usage but produce coarser output</li> <li>Higher sampling rates (lower values) produce smoother output but increase CPU usage</li> <li>Consider your application's requirements when setting the sampling rate</li> </ul> <h3>Example Uses</h3> <ul> <li>Generating test signals</li> <li>Creating periodic behaviors</li> <li>Simulating sensor data</li> <li>Producing modulation signals</li> <li>Testing control systems</li> </ul> </script>