DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Loading...
Searching...
No Matches
LockinAmplifier.h
Go to the documentation of this file.
1// This file is part of DynExp.
2
8#pragma once
9
10#include "stdafx.h"
12
13namespace DynExpInstr
14{
15 class LockinAmplifier;
16
20 namespace LockinAmplifierDefs
21 {
32
43
50 X,
51 Y,
52 R,
53 Theta
54 };
55
61 {
62 using DataType = double;
63
67 constexpr LockinResultCartesian() noexcept = default;
68
74 constexpr LockinResultCartesian(DataType X, DataType Y) noexcept : X(X), Y(Y) {}
75
78 };
79
85 {
86 using DataType = double;
87
91 constexpr LockinResultPolar() noexcept = default;
92
98 constexpr LockinResultPolar(DataType R, DataType Theta) noexcept : R(R), Theta(Theta) {}
99
102 };
103
109 {
110 using DataType = double;
111
115 constexpr LockinSample() noexcept = default;
116
125
134
145
149 void UpdatePolar() noexcept;
150
154 void UpdateCartesian() noexcept;
155
161 DataType GetDisambiguatedValue(SignalType Signal) const noexcept;
162
163 uint8_t Channel{};
164
167
169 };
170 }
171
216
221 {
222 public:
224
231 LockinAmplifierData(size_t BufferSizeInSamples) : DataStreamInstrumentData(std::make_unique<SampleStreamType>(BufferSizeInSamples)) {}
232
233 virtual ~LockinAmplifierData() = default;
234
240 virtual double GetSensitivity() const noexcept = 0;
241 virtual void SetSensitivity(double Sensitivity) noexcept = 0;
242 virtual double GetPhase() const noexcept = 0;
243 virtual void SetPhase(double Phase) noexcept = 0;
244 virtual double GetTimeConstant() const noexcept = 0;
245 virtual void SetTimeConstant(double TimeConstant) noexcept = 0;
246 virtual uint8_t GetFilterOrder() const noexcept { return 0; }
247 virtual void SetFilterOrder(uint8_t FilterOrder) noexcept {}
248
253
257 virtual void SetTriggerMode(LockinAmplifierDefs::TriggerModeType TriggerMode) noexcept {}
258
263
267 virtual void SetTriggerEdge(LockinAmplifierDefs::TriggerEdgeType TriggerEdge) noexcept {}
268
272 virtual LockinAmplifierDefs::SignalType GetSignalType() const noexcept = 0;
273
277 virtual void SetSignalType(LockinAmplifierDefs::SignalType SignalType) noexcept = 0;
278
279 virtual double GetSamplingRate() const noexcept { return 0; }
280 virtual void SetSamplingRate(double SamplingRate) noexcept {}
281 virtual bool IsEnabled() const noexcept { return true; }
282 virtual void SetEnable(uint8_t Enable) noexcept {}
283
289 virtual bool IsOverloaded() const noexcept { return false; }
290
300 virtual std::pair<double, double> GetInputLoad() const noexcept { return std::make_pair(-1, -1); }
301
307 virtual double GetOscillatorFrequency() const noexcept { return 0; }
308
314 virtual double GetAcquisitionProgress() const noexcept { return -1; }
316
323 double GetAcquisitionTime() const;
324
325 private:
326 void ResetImpl(dispatch_tag<DataStreamInstrumentData>) override final;
328 };
329
334 {
335 public:
344
350
356
357 virtual ~LockinAmplifierParams() = 0;
358
359 virtual const char* GetParamClassTag() const noexcept override { return "LockinAmplifierParams"; }
360
365 Param<AutoApplyParamsType> AutoApplyParams = { *this, AutoApplyParamsTypeStrList(), "AutoApplyParams", "Auto apply parameters",
366 "Determines whether the parameters saved to the instrument are applied automatically on instrument initialization", false, AutoApplyParamsType::DoNotApply };
367
371 Param<double> Sensitivity{ *this, "Sensitivity", 1, 0 };
372
376 Param<double> Phase{ *this, "Phase", 0, 0, 2.0 * std::numbers::pi };
377
382 Param<double> TimeConstant{ *this, "TimeConstant", 1e-3, 0 };
383
388 Param<unsigned int> FilterOrder{ *this, "FilterOrder", 1, 1, 10 };
389
394
399
405
409 Param<double> SamplingRate{ *this, "SamplingRate", 1000, 1 };
410
414 Param<bool> Enable{ *this, "Enable", false };
415
416 private:
419 };
420
433
439 {
440 public:
444
453
454 constexpr static auto Name() noexcept { return "Lock-in Amplifier"; }
455 constexpr static auto Category() noexcept { return "I/O"; }
456
462
463 virtual ~LockinAmplifier() = 0;
464
465 virtual std::string GetName() const override { return Name(); }
466 virtual std::string GetCategory() const override { return Category(); }
467
468 virtual std::chrono::milliseconds GetTaskQueueDelay() const override { return std::chrono::milliseconds(100); }
469
474
479 virtual const char* GetSensitivityUnitString() const noexcept = 0;
481
491 void PersistDataToParams() const;
492
500 void ApplyFromParams() const;
501
508
514 virtual void SetSensitivity(double Sensitivity, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const = 0;
515
522 virtual void AutoAdjustSensitivity(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
523
529 virtual void SetPhase(double Phase, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const = 0;
530
537 virtual void AutoAdjustPhase(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
538
544 virtual void SetTimeConstant(double TimeConstant, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const = 0;
545
553 virtual void SetFilterOrder(uint8_t FilterOrder, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
554
562 virtual void SetTriggerMode(LockinAmplifierDefs::TriggerModeType TriggerMode, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
563
571 virtual void SetTriggerEdge(LockinAmplifierDefs::TriggerEdgeType TriggerEdge, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
572
578 virtual void SetSignalType(LockinAmplifierDefs::SignalType SignalType, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const = 0;
579
587 virtual void SetSamplingRate(double SamplingRate, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
588
596 virtual void SetEnable(bool Enable, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
597
604 virtual void ForceTrigger(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const;
606
607 private:
608 void ResetImpl(dispatch_tag<DataStreamInstrument>) override final;
610
615
621
629
630 virtual std::unique_ptr<DynExp::InitTaskBase> MakeInitTask() const override { return DynExp::MakeTask<LockinAmplifierTasks::InitTask>(); }
631 virtual std::unique_ptr<DynExp::ExitTaskBase> MakeExitTask() const override { return DynExp::MakeTask<LockinAmplifierTasks::ExitTask>(); }
632 virtual std::unique_ptr<DynExp::UpdateTaskBase> MakeUpdateTask() const override { return DynExp::MakeTask<LockinAmplifierTasks::UpdateTask>(); }
633 };
634}
Implementation of a data stream meta instrument and of data streams input/output devices might work o...
Implements a circular data stream based on Util::circularbuf using samples of type BasicSample.
Configurator class for DataStreamInstrument.
Data class for DataStreamInstrument.
Parameter class for DataStreamInstrument.
Defines a task for deinitializing an instrument within an instrument inheritance hierarchy....
Defines a task for initializing an instrument within an instrument inheritance hierarchy....
Defines a task for updating an instrument within an instrument inheritance hierarchy....
Implementation of the data stream meta instrument, which is a base class for all instruments reading/...
Configurator class for LockinAmplifier.
Data class for LockinAmplifier.
virtual LockinAmplifierDefs::TriggerModeType GetTriggerMode() const noexcept
Getter for the lock-in amplifier's trigger mode.
virtual bool IsEnabled() const noexcept
Returns true if the lock-in amplifier's demodulator is enabled, false otherwise.
virtual void ResetImpl(dispatch_tag< LockinAmplifierData >)
virtual void SetFilterOrder(uint8_t FilterOrder) noexcept
Setter for the filter order/quality of the lock-in amplifier's low-poss filter.
virtual void SetSensitivity(double Sensitivity) noexcept=0
Setter for the lock-in amplifier's sensitivity/amplification setting.
double GetAcquisitionTime() const
Determines the duration of a single acquisition in seconds using GetSamplingRate() and DataStreamBase...
virtual void SetSamplingRate(double SamplingRate) noexcept
Setter for the lock-in amplifier's sampling rate in samples/s.
virtual double GetTimeConstant() const noexcept=0
Getter for the time constant in seconds of the lock-in amplifier's low-poss filter.
virtual double GetAcquisitionProgress() const noexcept
Determines the progress of the current data acquisition.
virtual ~LockinAmplifierData()=default
virtual bool IsOverloaded() const noexcept
Indicates whether the lock-in amplifier's physical signal input is overloaded by e....
virtual void SetTriggerMode(LockinAmplifierDefs::TriggerModeType TriggerMode) noexcept
Setter for the lock-in amplifier's trigger mode.
virtual double GetOscillatorFrequency() const noexcept
Indicates the oscillator frequency the lock-in amplifier demodulates the measured signal at.
virtual std::pair< double, double > GetInputLoad() const noexcept
Indicates the load at the lock-in amplifier's physical signal input in negative and positive directio...
virtual LockinAmplifierDefs::TriggerEdgeType GetTriggerEdge() const noexcept
Getter for the lock-in amplifier's trigger edge.
LockinAmplifierData(size_t BufferSizeInSamples)
Constructs a LockinAmplifierData instance.
virtual void SetSignalType(LockinAmplifierDefs::SignalType SignalType) noexcept=0
Setter for the lock-in amplifier's signal coordinate type to write to the data stream.
virtual void SetPhase(double Phase) noexcept=0
Setter for the phase in rad of the lock-in amplifier's demodulator.
virtual double GetPhase() const noexcept=0
Getter for the phase in rad of the lock-in amplifier's demodulator.
virtual double GetSamplingRate() const noexcept
Getter for the lock-in amplifier's sampling rate in samples/s.
virtual void SetTriggerEdge(LockinAmplifierDefs::TriggerEdgeType TriggerEdge) noexcept
Setter for the lock-in amplifier's trigger edge.
virtual LockinAmplifierDefs::SignalType GetSignalType() const noexcept=0
Getter for the lock-in amplifier's signal coordinate type to write to the data stream.
virtual void SetTimeConstant(double TimeConstant) noexcept=0
Setter for the time constant in seconds of the lock-in amplifier's low-poss filter.
virtual void SetEnable(uint8_t Enable) noexcept
Enables (pass true) or disables (pass false) the lock-in amplifier's demodulator.
virtual uint8_t GetFilterOrder() const noexcept
Getter for the filter order/quality of the lock-in amplifier's low-poss filter.
virtual double GetSensitivity() const noexcept=0
Getter for the lock-in amplifier's sensitivity/amplification setting.
void ResetImpl(dispatch_tag< DataStreamInstrumentData >) override final
Parameter class for LockinAmplifier.
Param< double > Sensitivity
Parameter to store the lock-in amplifier's sensitivity/amplification setting.
Param< double > SamplingRate
Parameter to store the lock-in amplifier's sampling rate in samples/s.
Param< AutoApplyParamsType > AutoApplyParams
Parameter to indicate whether to apply parameters stored here to the instrument when it is started....
Param< LockinAmplifierDefs::TriggerEdgeType > TriggerEdge
Parameter to store the lock-in amplifier's trigger edge.
Param< double > Phase
Parameter to store the phase in rad of the lock-in amplifier's demodulator.
Param< double > TimeConstant
Parameter to store the time constant in seconds of the lock-in amplifier's low-poss filter.
AutoApplyParamsType
Type to determine whether to apply parameters stored here to the lock-in amplifier when the instrumen...
@ AutoApply
Parameters are applied automatically when the instrument is started.
@ DoNotApply
Parameters are not applied automatically when the instrument is started.
void ConfigureParamsImpl(dispatch_tag< DataStreamInstrumentParams >) override final
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
Param< bool > Enable
Parameter to store whether the lock-in amplifier's demodulator is enabled.
virtual void ConfigureParamsImpl(dispatch_tag< LockinAmplifierParams >)
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
Param< unsigned int > FilterOrder
Parameter to store the filter order/quality of the lock-in amplifier's low-poss filter.
Param< LockinAmplifierDefs::TriggerModeType > TriggerMode
Parameter to store the lock-in amplifier's trigger mode.
static Util::TextValueListType< AutoApplyParamsType > AutoApplyParamsTypeStrList()
Maps description strings to the AutoApplyParamsType enum's items.
virtual const char * GetParamClassTag() const noexcept override
This function is intended to be overridden once in each derived class returning the name of the respe...
Param< LockinAmplifierDefs::SignalType > Signal
Parameter to store the lock-in amplifier's signal coordinate type to write to the data stream.
LockinAmplifierParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core)
Constructs the parameters for a LockinAmplifier instance.
Defines a task for deinitializing an instrument within an instrument inheritance hierarchy....
void ExitFuncImpl(dispatch_tag< DataStreamInstrumentTasks::ExitTask >, DynExp::InstrumentInstance &Instance) override final
Deinitializes the respective instrument within the instrument inheritance hierarchy....
virtual void ExitFuncImpl(dispatch_tag< ExitTask >, DynExp::InstrumentInstance &Instance)
Deinitializes the respective instrument within the instrument inheritance hierarchy....
Defines a task for initializing an instrument within an instrument inheritance hierarchy....
virtual void InitFuncImpl(dispatch_tag< InitTask >, DynExp::InstrumentInstance &Instance)
Initializes the respective instrument within the instrument inheritance hierarchy....
void InitFuncImpl(dispatch_tag< DataStreamInstrumentTasks::InitTask >, DynExp::InstrumentInstance &Instance) override final
Initializes the respective instrument within the instrument inheritance hierarchy....
Defines a task for updating an instrument within an instrument inheritance hierarchy....
virtual void UpdateFuncImpl(dispatch_tag< UpdateTask >, DynExp::InstrumentInstance &Instance)
Updates the respective instrument within the instrument inheritance hierarchy. Call UpdateFuncImpl() ...
void UpdateFuncImpl(dispatch_tag< DataStreamInstrumentTasks::UpdateTask >, DynExp::InstrumentInstance &Instance) override final
Updates the respective instrument within the instrument inheritance hierarchy. Call UpdateFuncImpl() ...
Meta instrument for a lock-in amplifier based on the data stream meta instrument.
virtual void AutoAdjustPhase(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Makes the lock-in amplifier automatically set its demodulator's phase.
virtual void SetTriggerEdge(LockinAmplifierDefs::TriggerEdgeType TriggerEdge, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Sets the lock-in amplifier's trigger edge.
static constexpr auto Name() noexcept
Every derived class has to redefine this function.
virtual void SetSignalType(LockinAmplifierDefs::SignalType SignalType, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const =0
Sets the lock-in amplifier's signal coordinate type to read out.
virtual void ForceTrigger(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Forces (starts) the data acquisition ignoring the trigger.
virtual std::chrono::milliseconds GetTaskQueueDelay() const override
Specifies in which time intervals the instrument's task queue runs to handle pending tasks.
virtual void SetTriggerMode(LockinAmplifierDefs::TriggerModeType TriggerMode, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Sets the lock-in amplifier's trigger mode.
virtual std::string GetCategory() const override
Returns the category of this Object type.
virtual void ApplyFromParamsImpl(dispatch_tag< LockinAmplifier >) const =0
Refer to ApplyFromParams(). Using tag dispatch mechanism to ensure that ApplyFromParamsImpl() of ever...
virtual std::unique_ptr< DynExp::InitTaskBase > MakeInitTask() const override
Factory function for an init task (InitTaskBase). Override to define the desired initialization task ...
void ResetImpl(dispatch_tag< DataStreamInstrument >) override final
Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every de...
virtual void SetFilterOrder(uint8_t FilterOrder, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Sets the filter order/quality of the lock-in amplifier's low-poss filter.
virtual std::unique_ptr< DynExp::UpdateTaskBase > MakeUpdateTask() const override
Factory function for an update task (UpdateTaskBase). Override to define the desired update task in d...
virtual void SetSensitivity(double Sensitivity, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const =0
Sets the lock-in amplifier's sensitivity/amplification.
virtual void SetSamplingRate(double SamplingRate, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Sets the lock-in amplifier's sampling rate.
LockinAmplifier(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
Constructs an instrument instance.
virtual void AutoAdjustSensitivity(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Makes the lock-in amplifier automatically set its sensitivity/amplification.
virtual void SetPhase(double Phase, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const =0
Sets the phase of the lock-in amplifier's demodulator.
virtual void PersistDataToParamsImpl(dispatch_tag< LockinAmplifier >) const
Refer to PersistDataToParams(). Using tag dispatch mechanism to ensure that PersistDataToParamsImpl()...
virtual std::unique_ptr< DynExp::ExitTaskBase > MakeExitTask() const override
Factory function for an exit task (ExitTaskBase). Override to define the desired deinitialization tas...
static constexpr auto Category() noexcept
Every derived class has to redefine this function.
virtual void SetEnable(bool Enable, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Enables or disables the lock-in amplifier's demodulator.
virtual const char * GetSensitivityUnitString() const noexcept=0
Determines the unit of the lock-in amplifier's sensitivity/amplification setting and returns a human-...
virtual void SetTimeConstant(double TimeConstant, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const =0
Sets the time constant of the lock-in amplifier's low-poss filter.
virtual std::string GetName() const override
Returns the name of this Object type.
void ApplyFromParams() const
Applies the lock-in amplifier settings stored in the instrument parameters to the physical device....
void PersistDataToParams() const
Retrieves the current lock-in amplifier settings and stores them in the instrument parameters to save...
DynExp's core class acts as the interface between the user interface and DynExp's internal data like ...
Definition DynExpCore.h:127
Refer to DynExp::ParamsBase::dispatch_tag.
Refer to DynExp::ParamsBase::dispatch_tag.
Refer to ParamsBase::dispatch_tag.
Definition Instrument.h:146
Defines data for a thread belonging to a InstrumentBase instance. Refer to RunnableInstance.
Definition Instrument.h:772
const std::thread::id OwnerThreadID
Thread id of the thread which has constructed (and owns) this Object instance.
Definition Object.h:2302
const ParamsBasePtrType Params
Pointer to the parameter class instance belonging to this Object instance.
Definition Object.h:2303
Refer to ParamsBase::dispatch_tag.
Definition Object.h:2018
const ItemIDType ID
ID of the Object this parameter class instance belongs to.
Definition Object.h:1779
const DynExpCore & Core
Reference to DynExp's core.
Definition Object.h:1780
Tag for function dispatching mechanism within this class used when derived classes are not intended t...
Definition Object.h:349
Refer to DynExp::ParamsBase::dispatch_tag.
TriggerEdgeType
Type to determine at which edge of a trigger signal to trigger. Not a strongly-typed enum to allow us...
@ Rise
Trigger on rising edge.
@ UnknownEdge
Trigger edge not specified.
@ Fall
Trigger on falling edge.
SignalType
Type specifying different signal coordinates a lock-in amplifier can record. Not a strongly-typed enu...
@ R
Radial component of the signal in polar coordinates.
@ Y
Y component of the signal in cartesian coordinates.
@ X
X component of the signal in cartesian coordinates.
@ Theta
Phase component of the signal in polar coordinates.
TriggerModeType
Type to determine the trigger mode. Not a strongly-typed enum to allow using the enumeration in a Dyn...
@ ExternSingle
Run once after an external trigger signal has been detected.
@ UnknownMode
Trigger mode not specified.
@ Continuous
Run continuously disabling the trigger.
DynExp's instrument namespace contains the implementation of DynExp instruments which extend DynExp's...
DynExp's main namespace contains the implementation of DynExp including classes to manage resources (...
std::unique_ptr< ParamsBase > ParamsBasePtrType
Alias for a pointer to the parameter system base class ParamsBase.
Definition Object.h:1807
size_t ItemIDType
ID type of objects/items managed by DynExp.
std::vector< std::pair< TextType, ValueType > > TextValueListType
Type of a list containing key-value pairs where key is a text of type Util::TextType.
Definition QtUtil.h:37
Accumulates include statements to provide a precompiled header.
Type describing a recorded lock-in sample in cartesian coordinates. Must be trivially copyable.
constexpr LockinResultCartesian() noexcept=default
Default-constructs a LockinResultCartesian instance.
DataType Y
Y component of the signal in cartesian coordinates.
DataType X
X component of the signal in cartesian coordinates.
double DataType
Data type used to store the sample.
Type describing a recorded lock-in sample in polar coordinates. Must be trivially copyable.
double DataType
Data type used to store the sample.
constexpr LockinResultPolar() noexcept=default
Default-constructs a LockinResultPolar instance.
DataType R
Radial component of the signal in polar coordinates.
DataType Theta
Phase component of the signal in polar coordinates.
Type describing a recorded lock-in sample independent of the coordinate system. Must be trivially cop...
LockinResultCartesian CartesianResult
Representation of the recorded sample in cartesian coordinates.
uint8_t Channel
Channel of the lock-in amplifier this sample has been recorded with.
constexpr LockinSample() noexcept=default
Default-constructs a LockinSample instance.
void UpdatePolar() noexcept
Updates PolarResult based on CartesianResult.
DataType Time
Time in seconds this sample has been recorded at.
DataType GetDisambiguatedValue(SignalType Signal) const noexcept
Retrieves the sample value represented as the coordinate specified by Signal.
LockinResultPolar PolarResult
Representation of the recorded sample in polar coordinates.
void UpdateCartesian() noexcept
Updates CartesianResult based on PolarResult.
double DataType
Data type used to store the sample (value and time)