DynExp
Highly flexible laboratory automation for dynamically changing experiments.
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 
22 namespace DynExpModule
23 {
24  class Trajectory1D;
25 
27  {
28  Q_OBJECT
29 
30  public:
32  ~Trajectory1DWidget() = default;
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 
51  auto& GetPositionerStage() { return PositionerStage; }
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 
87  TriggerModeType TriggerMode = TriggerModeType::Manual;
88  size_t RepeatCount = 1;
89  std::chrono::milliseconds DwellTime = std::chrono::milliseconds(100);
90 
91  size_t LastWrittenSampleID = 0;
93 
94  size_t CurrentPlaybackPos = 0;
95  size_t CurrentRepeatCount = 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 
152  : QModuleBase(OwnerThreadID, std::move(Params)) {}
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...
Definition: Trajectory1D.h:138
void SetTriggerMode(TriggerModeType TriggerMode) noexcept
Definition: Trajectory1D.h:55
void SetCurrentPlaybackPos(size_t CurrentPlaybackPos) noexcept
Definition: Trajectory1D.h:69
auto GetCurrentPlaybackPos() const noexcept
Definition: Trajectory1D.h:67
void SetSamples(DynExpInstr::DataStreamBase::BasicSampleListType &&Samples) noexcept
Definition: Trajectory1D.h:65
void SetTrajectoryStartedTime(std::chrono::time_point< std::chrono::system_clock > TrajectoryStartedTime) noexcept
Definition: Trajectory1D.h:75
virtual void ResetImpl(dispatch_tag< Trajectory1DData >)
Definition: Trajectory1D.h:79
auto GetTrajectoryStartedTime() const noexcept
Definition: Trajectory1D.h:74
size_t CurrentPlaybackPos
0 means waiting for trigger. Values > 0 mean running. They indicate the sample to be written next.
Definition: Trajectory1D.h:94
auto IsReady() const noexcept
Definition: Trajectory1D.h:72
DynExp::LinkedObjectWrapperContainer< DynExpInstr::PositionerStage > PositionerStage
Definition: Trajectory1D.h:84
void SetDwellTime(std::chrono::milliseconds DwellTime) noexcept
Definition: Trajectory1D.h:59
void SetReady(bool Ready) noexcept
Definition: Trajectory1D.h:73
auto GetLastWrittenSampleID() const noexcept
Definition: Trajectory1D.h:61
auto GetDwellTime() const noexcept
Definition: Trajectory1D.h:58
void SetCurrentRepeatCount(size_t CurrentRepeatCount) noexcept
Definition: Trajectory1D.h:71
const auto & GetSamples() const noexcept
Definition: Trajectory1D.h:63
DynExp::LinkedObjectWrapperContainer< DynExpInstr::InterModuleCommunicator > Communicator
Definition: Trajectory1D.h:85
DynExpInstr::DataStreamBase::BasicSampleListType Samples
Definition: Trajectory1D.h:92
auto & GetSamples() noexcept
Definition: Trajectory1D.h:64
std::chrono::time_point< std::chrono::system_clock > TrajectoryStartedTime
Definition: Trajectory1D.h:97
bool IsTriggered() const noexcept
Definition: Trajectory1D.h:68
void SetRepeatCount(size_t RepeatCount) noexcept
Definition: Trajectory1D.h:57
DynExp::LinkedObjectWrapperContainer< DynExpInstr::DataStreamInstrument > TrajectoryDataInstr
Definition: Trajectory1D.h:83
void ResetImpl(dispatch_tag< QModuleDataBase >) override final
auto GetCurrentRepeatCount() const noexcept
Definition: Trajectory1D.h:70
virtual ~Trajectory1DData()=default
auto GetTriggerMode() const noexcept
Definition: Trajectory1D.h:54
bool Ready
Running (not necessarily triggered yet) if true.
Definition: Trajectory1D.h:96
void SetLastWrittenSampleID(size_t LastWrittenSampleID) noexcept
Definition: Trajectory1D.h:62
std::chrono::milliseconds DwellTime
Definition: Trajectory1D.h:89
auto GetRepeatCount() const noexcept
Definition: Trajectory1D.h:56
virtual ~Trajectory1DParams()=default
Trajectory1DParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core)
Definition: Trajectory1D.h:105
Param< DynExp::ObjectLink< DynExpInstr::PositionerStage > > PositionerStage
Definition: Trajectory1D.h:112
static Util::TextValueListType< Trajectory1DData::TriggerModeType > TriggerModeTypeStrList()
Param< ParamsConfigDialog::NumberType > RepeatCount
Definition: Trajectory1D.h:119
Param< ParamsConfigDialog::NumberType > DwellTime
Definition: Trajectory1D.h:121
Param< DynExp::ObjectLink< DynExpInstr::InterModuleCommunicator > > Communicator
Definition: Trajectory1D.h:114
Param< Trajectory1DData::TriggerModeType > TriggerMode
Definition: Trajectory1D.h:117
void ConfigureParamsImpl(dispatch_tag< QModuleParamsBase >) override final
Definition: Trajectory1D.h:125
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...
Definition: Trajectory1D.h:108
Param< DynExp::ObjectLink< DynExpInstr::DataStreamInstrument > > TrajectoryDataInstr
Definition: Trajectory1D.h:110
const auto & GetUI() const noexcept
Definition: Trajectory1D.h:36
bool AllowResize() const noexcept override final
Indicates the resizing behavior of the user interface window. Override to adjust.
Definition: Trajectory1D.h:34
Trajectory1DWidget(Trajectory1D &Owner, QModuleWidget *parent=nullptr)
Definition: Trajectory1D.cpp:9
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
Definition: Trajectory1D.h:181
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.
Definition: Trajectory1D.h:158
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.
Definition: Trajectory1D.h:155
void OnStartClicked(DynExp::ModuleInstance *Instance, bool) const
Definition: Trajectory1D.h:179
void Stop(Util::SynchronizedPointer< ModuleDataType > &ModuleData) const
Trajectory1DData ModuleDataType
Definition: Trajectory1D.h:146
void OnExit(DynExp::ModuleInstance *Instance) const override final
This event is triggered right before the module thread terminates (not due to an exception,...
constexpr static auto Name() noexcept
Definition: Trajectory1D.h:148
void OnStopClicked(DynExp::ModuleInstance *Instance, bool) const
Definition: Trajectory1D.h:180
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)
Definition: Trajectory1D.h:151
void OnStart(DynExp::ModuleInstance *Instance) const
constexpr static auto Category() noexcept
Definition: Trajectory1D.h:149
void Move(Util::SynchronizedPointer< ModuleDataType > &ModuleData)
virtual std::string GetCategory() const override
Returns the category of this Object type.
Definition: Trajectory1D.h:156
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
Base class for modules. Modules implement programs on their own (e.g. measurement protocols or server...
Definition: Module.h:392
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
Configurator class for ModuleBase.
Definition: Module.h:374
Data structure to contain data which is synchronized in between different threads....
Definition: Module.h:171
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
Parameter class for ModuleBase.
Definition: Module.h:337
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 ItemIDType ID
ID of the Object this parameter class instance belongs to.
Definition: Object.h:1779
const auto & GetCore() const noexcept
Returns a reference to DynExp's core.
Definition: Object.h:1677
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...
Definition: circularbuf.cpp:7
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.