Stepdance Software Library
Loading...
Searching...
No Matches
WaveGenerator1D Class Reference

Used for generating a sinusoidal waveform signal. More...

#include <generators.hpp>

Inheritance diagram for WaveGenerator1D:

Public Member Functions

 WaveGenerator1D ()
 Default constructor for WaveGenerator1D. Does not initialize board hardware. Call begin() to set up the generator.
void begin ()
 Initialize the WaveGenerator1D. Must be called to set up the generator.
void setNoInput ()
 Set the generator to use internal frame count for waveform generation instead of an input signal. This means the generator will produce a continuous waveform based on the frame rate and does not need to be mapped to an input.
void debugPrint ()
 Print debug information about the WaveGenerator1D to the Serial console.
void enable ()
 Enable the WaveGenerator1D.
void disable ()
 Disable the WaveGenerator1D.

Public Attributes

volatile ControlParameter amplitude = 0
 ControlParameter for the amplitude of the waveform- the distance from the center line of the wave form to the top or bottom of the wave crest or trough. You can set it directly or map an input to it (e.g. from an analog input).
volatile ControlParameter phase = 0.0
 ControlParameter for the phase of the waveform in radians. Phase is the offset of the waveform from its starting point. You can set it directly or map an input to it.
volatile ControlParameter frequency = 8
 ControlParameter for the frequency of the waveform in revolutions per second (e.g. number of waves within a period). You can set it directly or map an input to it.
BlockPort input
 Input BlockPort for the WaveGenerator1D. This is what you map to with an upstream component. If setNoInput() is called, this input is ignored.
BlockPort output
 Output BlockPort for the WaveGenerator1D. This is what you map from to a downstream component.

Protected Member Functions

void run ()

Protected Attributes

volatile float64_t current_angle_rad = 0
volatile float64_t delta = 0

Detailed Description

Used for generating a sinusoidal waveform signal.

A WaveGenerator1D produces a sinusoidal waveform output based on an input position or internal frame count. It allows control over amplitude, phase, and frequency, making it useful for generating or modifying motion signals with an oscillation. Here's an example of how to instantiate and configure a WaveGenerator1D:

// Will create an oscillation in the motion of a channel based on analog inputs for amplitude, frequency, and phase
#define module_driver
#include "stepdance.hpp"
WaveGenerator1D wave_gen;
InputPort input_a;
Channel channel_a;
OutputPort output_a;
AnalogInput analog_a1; //amplitude pot
AnalogInput analog_a2; //frequency pot
AnalogInput analog_a3; //rotary pot
void setup() {
// Initialize OutputPort A
output_a.begin(OUTPUT_A);
// Enable the output drivers
enable_drivers();
// Initialize InputPort A
input_a.begin(INPUT_A);
input_a.output_x.map(wave_gen.input, INCREMENTAL); // Map SIGNAL_X to WaveGenerator1D input
// Map WaveGenerator1D output to Channel A's target position
wave_gen.output.map(channel_a.input_target_position);
wave_gen.begin();
// Initialize Channel A
channel_a.begin(&output_a, SIGNAL_E); // Connect Channel A to OutputPort A's SIGNAL_E
// Initialize Analog Inputs for controlling amplitude and frequency
analog_a1.set_floor(0, 25);
analog_a1.set_ceiling(10, 1020);
analog_a1.map(&wave_gen.amplitude);
analog_a1.begin(IO_A1);
analog_a2.set_floor(0.1, 25); //avoid zero frequency
analog_a2.set_ceiling(5.0, 1020);
analog_a2.map(&wave_gen.frequency);
analog_a2.begin(IO_A2);
analog_a3.set_floor(0, 25);
analog_a3.set_ceiling(6.28, 1020); //0 to 2pi
analog_a3.map(&wave_gen.phase);
analog_a3.begin(IO_A3);
dance_start();
}
void loop(){
dance_loop();
}

Member Data Documentation

◆ input

BlockPort WaveGenerator1D::input

Input BlockPort for the WaveGenerator1D. This is what you map to with an upstream component. If setNoInput() is called, this input is ignored.

input_a.output_x.map(wave_gen.input); // Map SIGNAL_X to WaveGenerator1D input

◆ output

BlockPort WaveGenerator1D::output

Output BlockPort for the WaveGenerator1D. This is what you map from to a downstream component.

wave_gen.output.map(channelX.input_target_position); // Map WaveGenerator1D output to ChannelX target position

The documentation for this class was generated from the following file: