DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Loading...
Searching...
No Matches
LockinAmplifier.cpp
Go to the documentation of this file.
1// This file is part of DynExp.
2
3#include "stdafx.h"
4#include "LockinAmplifier.h"
5
6namespace DynExpInstr
7{
8 LockinAmplifierDefs::LockinSample::LockinSample(uint8_t Channel, DataType Time, LockinResultCartesian CartesianResult) noexcept
9 : Channel(Channel), CartesianResult(CartesianResult), Time(Time)
10 {
11 UpdatePolar();
12 }
13
15 : Channel(Channel), PolarResult(PolarResult), Time(Time)
16 {
17 UpdateCartesian();
18 }
19
20 constexpr LockinAmplifierDefs::LockinSample::LockinSample(uint8_t Channel, DataType Time, LockinResultCartesian CartesianResult, LockinResultPolar PolarResult) noexcept
21 : Channel(Channel), CartesianResult(CartesianResult), PolarResult(PolarResult), Time(Time)
22 {
23 }
24
30
32 {
33 CartesianResult.X = PolarResult.R * std::cos(PolarResult.Theta);
34 CartesianResult.Y = PolarResult.R * std::sin(PolarResult.Theta);
35 }
36
38 {
39 switch (Signal)
40 {
41 case SignalType::R: return PolarResult.R;
42 case SignalType::Theta: return PolarResult.Theta;
43 case SignalType::X: return CartesianResult.X;
44 case SignalType::Y: return CartesianResult.Y;
45 default: return 0;
46 }
47 }
48
50 {
51 auto Owner = DynExp::dynamic_Object_cast<LockinAmplifier>(&Instance.GetOwner());
52
53 Owner->ApplyFromParams();
54
55 InitFuncImpl(dispatch_tag<InitTask>(), Instance);
56 }
57
59 {
60 auto SamplingRate = GetSamplingRate();
61
62 // Avoid division by zero.
63 if (SamplingRate > 0)
64 return GetSampleStream()->GetStreamSizeWrite() / SamplingRate;
65 else
66 return 0;
67 }
68
73
75 {
77 { "Do not apply automatically", AutoApplyParamsType::DoNotApply },
78 { "Automatically apply parameters", AutoApplyParamsType::AutoApply },
79 };
80
81 return List;
82 }
83
87
91
95
97 {
98 auto InstrParams = DynExp::dynamic_Params_cast<LockinAmplifier>(GetNonConstParams());
99 auto InstrData = DynExp::dynamic_InstrumentData_cast<LockinAmplifier>(GetInstrumentData());
100
101 InstrParams->Sensitivity = InstrData->GetSensitivity();
102 InstrParams->Phase = InstrData->GetPhase();
103 InstrParams->TimeConstant = InstrData->GetTimeConstant();
104 InstrParams->FilterOrder = InstrData->GetFilterOrder();
105 InstrParams->TriggerMode = InstrData->GetTriggerMode();
106 InstrParams->TriggerEdge = InstrData->GetTriggerEdge();
107 InstrParams->Signal = InstrData->GetSignalType();
108 InstrParams->SamplingRate = InstrData->GetSamplingRate();
109 InstrParams->Enable = InstrData->IsEnabled();
110
111 PersistDataToParamsImpl(dispatch_tag<LockinAmplifier>());
112 }
113
115 {
116 ApplyFromParamsImpl(dispatch_tag<LockinAmplifier>());
117 }
118
123
128
129 void LockinAmplifier::SetFilterOrder(uint8_t FilterOrder, DynExp::TaskBase::CallbackType CallbackFunc) const
130 {
132 }
133
138
143
144 void LockinAmplifier::SetSamplingRate(double SamplingRate, DynExp::TaskBase::CallbackType CallbackFunc) const
145 {
147 }
148
149 void LockinAmplifier::SetEnable(bool Enable, DynExp::TaskBase::CallbackType CallbackFunc) const
150 {
152 }
153
158
163}
Defines a meta instrument for a lock-in amplifier.
double GetAcquisitionTime() const
Determines the duration of a single acquisition in seconds using GetSamplingRate() and DataStreamBase...
void ResetImpl(dispatch_tag< DataStreamInstrumentData >) override final
static Util::TextValueListType< AutoApplyParamsType > AutoApplyParamsTypeStrList()
Maps description strings to the AutoApplyParamsType enum's items.
void InitFuncImpl(dispatch_tag< DataStreamInstrumentTasks::InitTask >, DynExp::InstrumentInstance &Instance) override final
Initializes the respective instrument within the instrument inheritance hierarchy....
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.
virtual void ForceTrigger(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Forces (starts) the data acquisition ignoring the trigger.
virtual void SetTriggerMode(LockinAmplifierDefs::TriggerModeType TriggerMode, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Sets the lock-in amplifier's trigger mode.
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 void SetSamplingRate(double SamplingRate, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Sets the lock-in amplifier's sampling rate.
virtual void AutoAdjustSensitivity(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Makes the lock-in amplifier automatically set its sensitivity/amplification.
virtual void SetEnable(bool Enable, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const
Enables or disables the lock-in amplifier's demodulator.
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...
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
Refer to ParamsBase::dispatch_tag.
Definition Object.h:2018
const auto & GetOwner() const noexcept
Returns Owner.
Definition Object.h:3524
std::function< void(const TaskBase &, ExceptionContainer &)> CallbackType
Type of a callback function which is invoked when a task has finished, failed or has been aborted....
Definition Instrument.h:939
Thrown when a requested feature is either under development and thus not implemented yet or when a sp...
Definition Exception.h:299
TriggerEdgeType
Type to determine at which edge of a trigger signal to trigger. Not a strongly-typed enum to allow us...
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...
DynExp's instrument namespace contains the implementation of DynExp instruments which extend DynExp's...
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.
DataType Y
Y component of the signal in cartesian coordinates.
DataType X
X component of the signal in cartesian coordinates.
Type describing a recorded lock-in sample in polar coordinates. Must be trivially copyable.
DataType R
Radial component of the signal in polar coordinates.
DataType Theta
Phase component of the signal in polar coordinates.
LockinResultCartesian CartesianResult
Representation of the recorded sample in cartesian coordinates.
constexpr LockinSample() noexcept=default
Default-constructs a LockinSample instance.
void UpdatePolar() noexcept
Updates PolarResult based on CartesianResult.
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)