Controlpp
Loading...
Searching...
No Matches
controlpp::SineGenerator< T > Class Template Reference

A lite weight incremental sine generator. More...

#include <controlpp/Generator.hpp>

Public Member Functions

 SineGenerator (const T &frequency, const T &sample_time)
 Constructs a sine generator.
 
void set_frequency (const T &frequency)
 
void set_sample_time (const T &sample_time)
 
void set_frequency_and_sample_time (const T &frequency, const T &sample_time)
 
sin () const
 Returns the current sine output.
 
cos () const
 Returns the current cosine output.
 
Eigen::Vector< T, 2 > next ()
 calculates the next output
 
void reset ()
 Resets the Sine generator to the initial position.
 

Detailed Description

template<class T>
class controlpp::SineGenerator< T >

A lite weight incremental sine generator.

A lite weight sine generator that calculates incremental results. This allows the use of a fast 2x2 Matrix Vector multiplication, which is much faster than the standard sin and cos computations.

Thus this class is well suited for generating sine waves that are written to an output like an DAC (Digital to Analog Converter).

Template Parameters
TThe value type that the SineGenerator uses. Typically float, double or a custom fixpoint implementation.

Constructor & Destructor Documentation

◆ SineGenerator()

template<class T >
controlpp::SineGenerator< T >::SineGenerator ( const T &  frequency,
const T &  sample_time 
)
inline

Constructs a sine generator.

The initial position (internal state) is at sin() == 0 and cos() == 1

Parameters
frequencyThe frequency of the sine wave
sample_timeThe time that passes in between outputs (calls to next())
See also
controlpp::SineGenerator::next()

Member Function Documentation

◆ cos()

template<class T >
T controlpp::SineGenerator< T >::cos ( ) const
inline

Returns the current cosine output.

Does not advance the state

Returns
The cosine result

◆ next()

template<class T >
Eigen::Vector< T, 2 > controlpp::SineGenerator< T >::next ( )
inline

calculates the next output

Advances the state

Returns
An eigen vector containing the sine (at index 0) and cosine (at index 1)

◆ reset()

template<class T >
void controlpp::SineGenerator< T >::reset ( )
inline

Resets the Sine generator to the initial position.

The initial position (internal state) is at sin() == 0 and cos() == 1

◆ set_frequency()

template<class T >
void controlpp::SineGenerator< T >::set_frequency ( const T &  frequency)
inline

◆ set_frequency_and_sample_time()

template<class T >
void controlpp::SineGenerator< T >::set_frequency_and_sample_time ( const T &  frequency,
const T &  sample_time 
)
inline

◆ set_sample_time()

template<class T >
void controlpp::SineGenerator< T >::set_sample_time ( const T &  sample_time)
inline

◆ sin()

template<class T >
T controlpp::SineGenerator< T >::sin ( ) const
inline

Returns the current sine output.

Does not advance the state

Returns
The sine result

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