DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Loading...
Searching...
No Matches
Trajectory1D.h
Go to the documentation of this file.
1// This file is part of DynExp.
2
9#pragma once
10
11#include "stdafx.h"
12#include "DynExpCore.h"
13#include "../MetaInstruments/Stage.h"
14#include "../MetaInstruments/DataStreamInstrument.h"
15#include "../Instruments/InterModuleCommunicator.h"
16
17#include "CommonModuleEvents.h"
18
19#include <QWidget>
20
21namespace Ui
22{
23 class Trajectory1D;
24}
25
26namespace DynExpModule
27{
28 class Trajectory1D;
29
31 {
32 Q_OBJECT
33
34 public:
37
38 bool AllowResize() const noexcept override final { return false; }
39
40 const auto GetUI() const noexcept { return ui.get(); }
41
42 private:
43 std::unique_ptr<Ui::Trajectory1D> ui;
44 };
45
47 {
48 public:
51
53 virtual ~Trajectory1DData() = default;
54
57 auto& GetCommunicator() { return Communicator; }
58
59 auto GetTriggerMode() const noexcept { return TriggerMode; }
61 auto GetPositioningMode() const noexcept { return PositioningMode; }
63 auto GetPosMultiplier() const noexcept { return PosMultiplier; }
64 void SetPosMultiplier(double PosMultiplier) noexcept { this->PosMultiplier = PosMultiplier; }
65 auto GetRepeatCount() const noexcept { return RepeatCount; }
66 void SetRepeatCount(size_t RepeatCount) noexcept { this->RepeatCount = RepeatCount; }
67 auto GetDwellTime() const noexcept { return DwellTime; }
68 void SetDwellTime(std::chrono::milliseconds DwellTime) noexcept { this->DwellTime = DwellTime; }
69
70 auto GetLastWrittenSampleID() const noexcept { return LastWrittenSampleID; }
72 const auto& GetSamples() const noexcept { return Samples; }
73 auto& GetSamples() noexcept { return Samples; }
75
76 auto GetCurrentPlaybackPos() const noexcept { return CurrentPlaybackPos; }
77 bool IsTriggered() const noexcept { return CurrentPlaybackPos > 0; }
79 auto GetCurrentRepeatCount() const noexcept { return CurrentRepeatCount; }
81 auto IsReady() const noexcept { return Ready; }
82 void SetReady(bool Ready) noexcept { this->Ready = Ready; }
83 auto GetTrajectoryStartedTime() const noexcept { return TrajectoryStartedTime; }
84 void SetTrajectoryStartedTime(std::chrono::time_point<std::chrono::system_clock> TrajectoryStartedTime) noexcept { this->TrajectoryStartedTime = TrajectoryStartedTime; }
85
86 private:
87 void ResetImpl(dispatch_tag<QModuleDataBase>) override final;
89
90 void Init();
91
95
98 double PosMultiplier = 1.0;
99 size_t RepeatCount = 1;
100 std::chrono::milliseconds DwellTime = std::chrono::milliseconds(100);
101
104
107 bool Ready = false;
108 std::chrono::time_point<std::chrono::system_clock> TrajectoryStartedTime;
109 };
110
112 {
113 public:
116
118 virtual ~Trajectory1DParams() = default;
119
120 virtual const char* GetParamClassTag() const noexcept override { return "Trajectory1DParams"; }
121
123 "TrajectoryDataInstr", "Trajectory data stream", "Data stream instrument to stream position data from", DynExpUI::Icons::Instrument };
125 "PositionerStage", "Positioner", "Underlying positioner to be controlled by this module", DynExpUI::Icons::Instrument };
127 "InterModuleCommunicator", "Inter-module communicator", "Inter-module communicator to control this module with", DynExpUI::Icons::Instrument, true };
128
130 "Trigger action which starts streaming the position data", true, Trajectory1DData::TriggerModeType::Manual };
132 "Indicates how position samples are treated", true, Trajectory1DData::PositioningModeType::Absolute };
133 Param<ParamsConfigDialog::NumberType> PosMultiplier = { *this, "PosMultiplier", "Position multiplier",
134 "Factor to multiply each position sample with before moving", true, 1, -1e9, 1e9, 1, 2 };
135 Param<ParamsConfigDialog::NumberType> RepeatCount = { *this, "RepeatCount", "Number of repetitions",
136 "Determines how many times the trajectory data stream should be played back after a trigger event has occurred", true, 1, 1 };
137 Param<ParamsConfigDialog::NumberType> DwellTime = { *this, "DwellTime", "Dwell time in ms",
138 "Dwell time used for data streams containing samples without time data", true, 100, 1 };
139
140 private:
142 };
143
145 {
146 public:
149
151 virtual ~Trajectory1DConfigurator() = default;
152
153 private:
154 virtual DynExp::ParamsBasePtrType MakeParams(DynExp::ItemIDType ID, const DynExp::DynExpCore& Core) const override final { return DynExp::MakeParams<Trajectory1DConfigurator>(ID, Core); }
155 };
156
158 {
159 public:
163
164 constexpr static auto Name() noexcept { return "1D Trajectory Positioning"; }
165 constexpr static auto Category() noexcept { return "Motion Control"; }
166
169 virtual ~Trajectory1D() = default;
170
171 virtual std::string GetName() const override { return Name(); }
172 virtual std::string GetCategory() const override { return Category(); }
173
174 std::chrono::milliseconds GetMainLoopDelay() const override final { return std::chrono::milliseconds(1); }
175
176 private:
178
179 void ResetImpl(dispatch_tag<QModuleBase>) override final;
180
181 std::unique_ptr<DynExp::QModuleWidget> MakeUIWidget() override final;
182 void UpdateUIChild(const ModuleBase::ModuleDataGetterType& ModuleDataGetter) override final;
183
184 // Helper functions
185 void UpdateStream(Util::SynchronizedPointer<ModuleDataType>& ModuleData);
186 void Move(Util::SynchronizedPointer<ModuleDataType>& ModuleData);
187 void Start(Util::SynchronizedPointer<ModuleDataType>& ModuleData) const;
188 void Stop(Util::SynchronizedPointer<ModuleDataType>& ModuleData) const;
189 void Trigger(Util::SynchronizedPointer<ModuleDataType>& ModuleData) const;
190
191 // Events, run in module thread
192 void OnInit(DynExp::ModuleInstance* Instance) const override final;
193 void OnExit(DynExp::ModuleInstance* Instance) const override final;
194
195 void OnStartClicked(DynExp::ModuleInstance* Instance, bool) const { OnStart(Instance); }
196 void OnStopClicked(DynExp::ModuleInstance* Instance, bool) const { OnStop(Instance); }
197 void OnTriggerClicked(DynExp::ModuleInstance* Instance, bool) const { OnTrigger(Instance); }
198 void OnStart(DynExp::ModuleInstance* Instance) const;
199 void OnStop(DynExp::ModuleInstance* Instance) const;
200 void OnTrigger(DynExp::ModuleInstance* Instance) const;
201
203 };
204}
Provides common events for inter-module communication. Also refer to DynExp::InterModuleEventBase.
Defines DynExp's core module as an interface between the UI and DynExp objects.
std::vector< BasicSample > BasicSampleListType
Type of a list containing data stream samples of type BasicSample.
virtual DynExp::ParamsBasePtrType MakeParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core) const override final
Override to make derived classes call DynExp::MakeParams with the correct configurator type derived f...
void SetTriggerMode(TriggerModeType TriggerMode) noexcept
void SetCurrentPlaybackPos(size_t CurrentPlaybackPos) noexcept
auto GetCurrentPlaybackPos() const noexcept
auto GetPositioningMode() const noexcept
void SetSamples(DynExpInstr::DataStreamBase::BasicSampleListType &&Samples) noexcept
void SetTrajectoryStartedTime(std::chrono::time_point< std::chrono::system_clock > TrajectoryStartedTime) noexcept
virtual void ResetImpl(dispatch_tag< Trajectory1DData >)
auto GetTrajectoryStartedTime() const noexcept
auto GetPosMultiplier() const noexcept
const auto & GetSamples() const noexcept
size_t CurrentPlaybackPos
0 means waiting for trigger. Values > 0 mean running. They indicate the sample to be written next.
auto IsReady() const noexcept
void SetPositioningMode(PositioningModeType PositioningMode) noexcept
DynExp::LinkedObjectWrapperContainer< DynExpInstr::PositionerStage > PositionerStage
void SetDwellTime(std::chrono::milliseconds DwellTime) noexcept
void SetReady(bool Ready) noexcept
auto GetLastWrittenSampleID() const noexcept
auto GetDwellTime() const noexcept
void SetCurrentRepeatCount(size_t CurrentRepeatCount) noexcept
DynExp::LinkedObjectWrapperContainer< DynExpInstr::InterModuleCommunicator > Communicator
DynExpInstr::DataStreamBase::BasicSampleListType Samples
std::chrono::time_point< std::chrono::system_clock > TrajectoryStartedTime
PositioningModeType PositioningMode
bool IsTriggered() const noexcept
void SetPosMultiplier(double PosMultiplier) noexcept
void SetRepeatCount(size_t RepeatCount) noexcept
DynExp::LinkedObjectWrapperContainer< DynExpInstr::DataStreamInstrument > TrajectoryDataInstr
void ResetImpl(dispatch_tag< QModuleDataBase >) override final
auto GetCurrentRepeatCount() const noexcept
virtual ~Trajectory1DData()=default
auto GetTriggerMode() const noexcept
bool Ready
Running (not necessarily triggered yet) if true.
void SetLastWrittenSampleID(size_t LastWrittenSampleID) noexcept
std::chrono::milliseconds DwellTime
auto GetRepeatCount() const noexcept
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< Trajectory1DData::PositioningModeType > PositioningMode
virtual ~Trajectory1DParams()=default
Trajectory1DParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core)
static Util::TextValueListType< Trajectory1DData::PositioningModeType > PositioningModeTypeStrList()
Param< DynExp::ObjectLink< DynExpInstr::PositionerStage > > PositionerStage
static Util::TextValueListType< Trajectory1DData::TriggerModeType > TriggerModeTypeStrList()
Param< ParamsConfigDialog::NumberType > RepeatCount
Param< ParamsConfigDialog::NumberType > DwellTime
Param< DynExp::ObjectLink< DynExpInstr::InterModuleCommunicator > > Communicator
Param< Trajectory1DData::TriggerModeType > TriggerMode
void ConfigureParamsImpl(dispatch_tag< QModuleParamsBase >) override final
Param< DynExp::ObjectLink< DynExpInstr::DataStreamInstrument > > TrajectoryDataInstr
Param< ParamsConfigDialog::NumberType > PosMultiplier
std::unique_ptr< Ui::Trajectory1D > ui
bool AllowResize() const noexcept override final
Indicates the resizing behavior of the user interface window. Override to adjust.
const auto GetUI() const noexcept
void ResetImpl(dispatch_tag< QModuleBase >) override final
void UpdateStream(Util::SynchronizedPointer< ModuleDataType > &ModuleData)
std::unique_ptr< DynExp::QModuleWidget > MakeUIWidget() override final
Used by InitUI() as a factory function for the module's user interface widget. Create the widget here...
virtual ~Trajectory1D()=default
void Start(Util::SynchronizedPointer< ModuleDataType > &ModuleData) const
void OnTriggerClicked(DynExp::ModuleInstance *Instance, bool) const
void OnTrigger(DynExp::ModuleInstance *Instance) const
std::chrono::milliseconds GetMainLoopDelay() const override final
Specifies in which time intervals the module's event queue runs to handle pending events.
static constexpr auto Category() noexcept
void Trigger(Util::SynchronizedPointer< ModuleDataType > &ModuleData) const
void OnInit(DynExp::ModuleInstance *Instance) const override final
This event is triggered right before the module thread starts. Override it to lock instruments this m...
virtual std::string GetName() const override
Returns the name of this Object type.
void OnStartClicked(DynExp::ModuleInstance *Instance, bool) const
void Stop(Util::SynchronizedPointer< ModuleDataType > &ModuleData) const
Trajectory1DData ModuleDataType
void OnExit(DynExp::ModuleInstance *Instance) const override final
This event is triggered right before the module thread terminates (not due to an exception,...
void OnStopClicked(DynExp::ModuleInstance *Instance, bool) const
void OnStop(DynExp::ModuleInstance *Instance) const
Util::DynExpErrorCodes::DynExpErrorCodes ModuleMainLoop(DynExp::ModuleInstance &Instance) override final
Module main loop. The function is executed periodically by the module thread. Also refer to GetMainLo...
Trajectory1D(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
void OnStart(DynExp::ModuleInstance *Instance) const
void Move(Util::SynchronizedPointer< ModuleDataType > &ModuleData)
static constexpr auto Name() noexcept
virtual std::string GetCategory() const override
Returns the category of this Object type.
void UpdateUIChild(const ModuleBase::ModuleDataGetterType &ModuleDataGetter) override final
DynExp's core class acts as the interface between the user interface and DynExp's internal data like ...
Definition DynExpCore.h:127
This class holds a pointer (LinkedObjectWrapperPointer) to a LinkedObjectWrapper. Intances of this cl...
Definition Object.h:3168
Util::CallableMemberWrapper< ModuleBase, ModuleDataTypeSyncPtrType(ModuleBase::*)(const std::chrono::milliseconds)> ModuleDataGetterType
Invoking an instance of this alias is supposed to call ModuleBase::GetModuleData() of the instance th...
Definition Module.h:624
const std::unique_ptr< ModuleDataType > ModuleData
Module data belonging to this ModuleBase instance.
Definition Module.h:788
ModuleBase(const std::thread::id OwnerThreadID, ParamsBasePtrType &&Params)
Constructs a ModuleBase instance.
Definition Module.cpp:206
Refer to ParamsBase::dispatch_tag.
Definition Module.h:191
Defines data for a thread belonging to a ModuleBase instance. Refer to RunnableInstance.
Definition Module.h:840
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
const auto & GetCore() const noexcept
Returns a reference to DynExp's core.
Definition Object.h:1677
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
Base class for modules with a Qt-based user interface. Derive from this class to implement modules wi...
Definition Module.h:1660
QModuleBase(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
Constructs a QModuleBase instance.
Definition Module.cpp:591
Configurator class for QModuleBase.
Definition Module.h:1646
Data class for QModuleBase.
Definition Module.h:1536
Parameter class for QModuleBase.
Definition Module.h:1622
QModuleParamsBase(ItemIDType ID, const DynExpCore &Core)
Constructs the parameters for a QModuleBase instance.
Definition Module.h:1628
Window class for Qt-based user interfaces belonging to DynExp modules. User interface Qt window class...
Definition Module.h:1395
QModuleBase & Owner
Module owning this user interface window (reference, because it should never change nor be nullptr).
Definition Module.h:1478
QModuleWidget(QModuleBase &Owner, QWidget *Parent=nullptr)
Constructs a QModuleWidget instance.
Definition Module.cpp:451
DynExp's module namespace contains the implementation of DynExp modules which extend DynExp's core fu...
constexpr auto Instrument
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.
DynExpErrorCodes
DynExp's error codes
Definition Exception.h:22
DynExp's Util namespace contains commonly used functions and templates as well as extensions to Qt an...
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.