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#include "ui_Trajectory1D.h"
21
22namespace DynExpModule
23{
24 class Trajectory1D;
25
27 {
28 Q_OBJECT
29
30 public:
33
34 bool AllowResize() const noexcept override final { return false; }
35
36 const auto& GetUI() const noexcept { return ui; }
37
38 private:
39 Ui::Trajectory1D ui;
40 };
41
43 {
44 public:
46
48 virtual ~Trajectory1DData() = default;
49
52 auto& GetCommunicator() { return Communicator; }
53
54 auto GetTriggerMode() const noexcept { return TriggerMode; }
56 auto GetRepeatCount() const noexcept { return RepeatCount; }
57 void SetRepeatCount(size_t RepeatCount) noexcept { this->RepeatCount = RepeatCount; }
58 auto GetDwellTime() const noexcept { return DwellTime; }
59 void SetDwellTime(std::chrono::milliseconds DwellTime) noexcept { this->DwellTime = DwellTime; }
60
61 auto GetLastWrittenSampleID() const noexcept { return LastWrittenSampleID; }
63 const auto& GetSamples() const noexcept { return Samples; }
64 auto& GetSamples() noexcept { return Samples; }
66
67 auto GetCurrentPlaybackPos() const noexcept { return CurrentPlaybackPos; }
68 bool IsTriggered() const noexcept { return CurrentPlaybackPos > 0; }
70 auto GetCurrentRepeatCount() const noexcept { return CurrentRepeatCount; }
72 auto IsReady() const noexcept { return Ready; }
73 void SetReady(bool Ready) noexcept { this->Ready = Ready; }
74 auto GetTrajectoryStartedTime() const noexcept { return TrajectoryStartedTime; }
75 void SetTrajectoryStartedTime(std::chrono::time_point<std::chrono::system_clock> TrajectoryStartedTime) noexcept { this->TrajectoryStartedTime = TrajectoryStartedTime; }
76
77 private:
78 void ResetImpl(dispatch_tag<QModuleDataBase>) override final;
80
81 void Init();
82
86
88 size_t RepeatCount = 1;
89 std::chrono::milliseconds DwellTime = std::chrono::milliseconds(100);
90
93
94 size_t CurrentPlaybackPos = 0;
96 bool Ready = false;
97 std::chrono::time_point<std::chrono::system_clock> TrajectoryStartedTime;
98 };
99
101 {
102 public:
104
106 virtual ~Trajectory1DParams() = default;
107
108 virtual const char* GetParamClassTag() const noexcept override { return "Trajectory1DParams"; }
109
111 "TrajectoryDataInstr", "Trajectory data stream", "Data stream instrument to stream position data from", DynExpUI::Icons::Instrument };
113 "PositionerStage", "Positioner", "Underlying positioner to be controlled by this module", DynExpUI::Icons::Instrument };
115 "InterModuleCommunicator", "Inter-module communicator", "Inter-module communicator to control this module with", DynExpUI::Icons::Instrument, true };
116
118 "Trigger action which starts streaming the position data", true, Trajectory1DData::TriggerModeType::Manual };
119 Param<ParamsConfigDialog::NumberType> RepeatCount = { *this, "RepeatCount", "Number of repetitions",
120 "Determines how many times the trajectory data stream should be played back after a trigger event has occurred", true, 1, 1 };
121 Param<ParamsConfigDialog::NumberType> DwellTime = { *this, "DwellTime", "Dwell time in ms",
122 "Dwell time used for data streams containing samples without time data", true, 100, 1 };
123
124 private:
126 };
127
129 {
130 public:
133
135 virtual ~Trajectory1DConfigurator() = default;
136
137 private:
138 virtual DynExp::ParamsBasePtrType MakeParams(DynExp::ItemIDType ID, const DynExp::DynExpCore& Core) const override final { return DynExp::MakeParams<Trajectory1DConfigurator>(ID, Core); }
139 };
140
142 {
143 public:
147
148 constexpr static auto Name() noexcept { return "1D Trajectory Positioning"; }
149 constexpr static auto Category() noexcept { return "Motion Control"; }
150
153 virtual ~Trajectory1D() = default;
154
155 virtual std::string GetName() const override { return Name(); }
156 virtual std::string GetCategory() const override { return Category(); }
157
158 std::chrono::milliseconds GetMainLoopDelay() const override final { return std::chrono::milliseconds(1); }
159
160 private:
162
163 void ResetImpl(dispatch_tag<QModuleBase>) override final;
164
165 std::unique_ptr<DynExp::QModuleWidget> MakeUIWidget() override final;
166 void UpdateUIChild(const ModuleBase::ModuleDataGetterType& ModuleDataGetter) override final;
167
168 // Helper functions
169 void UpdateStream(Util::SynchronizedPointer<ModuleDataType>& ModuleData);
170 void Move(Util::SynchronizedPointer<ModuleDataType>& ModuleData);
171 void Start(Util::SynchronizedPointer<ModuleDataType>& ModuleData) const;
172 void Stop(Util::SynchronizedPointer<ModuleDataType>& ModuleData) const;
173 void Trigger(Util::SynchronizedPointer<ModuleDataType>& ModuleData) const;
174
175 // Events, run in module thread
176 void OnInit(DynExp::ModuleInstance* Instance) const override final;
177 void OnExit(DynExp::ModuleInstance* Instance) const override final;
178
179 void OnStartClicked(DynExp::ModuleInstance* Instance, bool) const { OnStart(Instance); }
180 void OnStopClicked(DynExp::ModuleInstance* Instance, bool) const { OnStop(Instance); }
181 void OnTriggerClicked(DynExp::ModuleInstance* Instance, bool) const { OnTrigger(Instance); }
182 void OnStart(DynExp::ModuleInstance* Instance) const;
183 void OnStop(DynExp::ModuleInstance* Instance) const;
184 void OnTrigger(DynExp::ModuleInstance* Instance) const;
185
187 };
188}
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
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
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
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
bool IsTriggered() const 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...
virtual ~Trajectory1DParams()=default
Trajectory1DParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core)
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
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:3160
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:587
const std::unique_ptr< ModuleDataType > ModuleData
Module data belonging to this ModuleBase instance.
Definition Module.h:743
ModuleBase(const std::thread::id OwnerThreadID, ParamsBasePtrType &&Params)
Constructs a ModuleBase instance.
Definition Module.cpp:189
Refer to ParamsBase::dispatch_tag.
Definition Module.h:189
Defines data for a thread belonging to a ModuleBase instance. Refer to RunnableInstance.
Definition Module.h:793
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:1344
QModuleBase(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType &&Params)
Constructs a QModuleBase instance.
Definition Module.cpp:557
Configurator class for QModuleBase.
Definition Module.h:1330
Data class for QModuleBase.
Definition Module.h:1220
Parameter class for QModuleBase.
Definition Module.h:1306
QModuleParamsBase(ItemIDType ID, const DynExpCore &Core)
Constructs the parameters for a QModuleBase instance.
Definition Module.h:1312
Window class for Qt-based user interfaces belonging to DynExp modules. User interface Qt window class...
Definition Module.h:1079
QModuleBase & Owner
Module owning this user interface window (reference, because it should never change nor be nullptr).
Definition Module.h:1162
QModuleWidget(QModuleBase &Owner, QWidget *Parent=nullptr)
Constructs a QModuleWidget instance.
Definition Module.cpp:417
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.