DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Loading...
Searching...
No Matches
SmarAct.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"
15
16namespace DynExpInstr
17{
18 class SmarAct;
19
20 namespace SmarActTasks
21 {
28
35
42
43 class SetHomeTask final : public DynExp::TaskBase
44 {
46 };
47
48 class ReferenceTask final : public DynExp::TaskBase
49 {
50 public:
52
53 private:
55 };
56
57 class CalibrateTask final : public DynExp::TaskBase
58 {
59 public:
61
62 private:
64 };
65
76
77 class MoveToHomeTask final : public DynExp::TaskBase
78 {
79 public:
81
82 private:
84 };
85
97
109
110 class StopMotionTask final : public DynExp::TaskBase
111 {
113 };
114 }
115
117 {
120
121 public:
123 {
124 constexpr void Set(int32_t ByteCode) noexcept { this->ByteCode = ByteCode; }
125
126 constexpr bool IsSensorPresent() const noexcept { return ByteCode & SA_CTL_CH_STATE_BIT_SENSOR_PRESENT; }
127 constexpr bool IsMoving() const noexcept { return ByteCode & (SA_CTL_CH_STATE_BIT_ACTIVELY_MOVING); }
128 constexpr bool IsClosedLoopActive() const noexcept { return ByteCode & (SA_CTL_CH_STATE_BIT_CLOSED_LOOP_ACTIVE); }
129 constexpr bool IsEndStopReached() const noexcept { return ByteCode & SA_CTL_CH_STATE_BIT_END_STOP_REACHED; }
130 constexpr bool IsRangeLimitReached() const noexcept { return ByteCode & SA_CTL_CH_STATE_BIT_RANGE_LIMIT_REACHED; }
131 constexpr bool IsReferencing() const noexcept { return ByteCode & SA_CTL_CH_STATE_BIT_REFERENCING; }
132 constexpr bool IsCalibrating() const noexcept { return ByteCode & SA_CTL_CH_STATE_BIT_CALIBRATING; }
133 constexpr bool IsReferenced() const noexcept { return ByteCode & SA_CTL_CH_STATE_BIT_IS_REFERENCED; }
134 constexpr bool IsCalibrated() const noexcept { return ByteCode & SA_CTL_CH_STATE_BIT_IS_CALIBRATED; }
135
136 constexpr bool IsErrorState() const noexcept
137 {
138 return ByteCode & (SA_CTL_CH_STATE_BIT_FOLLOWING_LIMIT_REACHED | SA_CTL_CH_STATE_BIT_MOVEMENT_FAILED
139 | SA_CTL_CH_STATE_BIT_POSITIONER_OVERLOAD | SA_CTL_CH_STATE_BIT_OVER_TEMPERATURE
140 | SA_CTL_CH_STATE_BIT_POSITIONER_FAULT);
141 }
142
143 private:
144 int32_t ByteCode = 0;
145 };
146
147 SmarActData() = default;
148 virtual ~SmarActData() = default;
149
150 auto GetChannel() const noexcept { return Channel; }
151
152 // Reference getter overload to allow other tasks than update task to update the channel state (especially if they started the stage to move).
154 auto GetSmarActChannelStatus() const noexcept { return SmarActChannelStatus; }
155
156 auto GetHomePosition() const noexcept { return HomePosition; }
158
160
161 private:
162 void ResetImpl(dispatch_tag<PositionerStageData>) override final;
164
165 virtual bool IsMovingChild() const noexcept override { return SmarActChannelStatus.IsMoving(); }
166 virtual bool HasArrivedChild() const noexcept override { return SmarActChannelStatus.IsClosedLoopActive() && !SmarActChannelStatus.IsMoving(); } // SmarAct is holding target position.
167 virtual bool HasFailedChild() const noexcept override { return SmarActChannelStatus.IsErrorState(); }
168 virtual bool IsReferencedChild() const noexcept override { return SmarActChannelStatus.IsReferenced(); }
169
171
175 };
176
178 {
179 public:
181 virtual ~SmarActParams() = default;
182
183 virtual const char* GetParamClassTag() const noexcept override { return "SmarActParams"; }
184
186 "HardwareAdapter", "SmarAct controller", "Underlying hardware adapter of this instrument", DynExpUI::Icons::HardwareAdapter };
187 Param<ParamsConfigDialog::NumberType> Channel = { *this, "Channel", "Channel",
188 "Channel of the SmarAct controller this instrument refers to", true, 0, 0, std::numeric_limits<uint8_t>::max(), 1, 0 };
189 Param<ParamsConfigDialog::NumberType> HoldTime = { *this, "HoldTime", "Closed-loop hold time in ms",
190 "Specifies duration in ms of actively holding target position in closed-loop mode (-2 means do not set, -1 means infinite)",
191 true, -1, -2, std::numeric_limits<int32_t>::max(), 1, 0 };
192
193 private:
196 };
197
199 {
200 public:
203
205 virtual ~SmarActConfigurator() = default;
206
207 private:
208 virtual DynExp::ParamsBasePtrType MakeParams(DynExp::ItemIDType ID, const DynExp::DynExpCore& Core) const override { return DynExp::MakeParams<SmarActConfigurator>(ID, Core); }
209 };
210
212 {
213 public:
217
218 constexpr static auto Name() noexcept { return "SmarAct"; }
219
220 SmarAct(const std::thread::id OwnerThreadID, DynExp::ParamsBasePtrType&& Params);
221 virtual ~SmarAct() {}
222
223 virtual std::string GetName() const override { return Name(); }
224
225 virtual PositionerStageData::PositionType GetMinPosition() const noexcept override { return -100e9; }
226 virtual PositionerStageData::PositionType GetMaxPosition() const noexcept override { return 100e9; }
227 virtual PositionerStageData::PositionType GetResolution() const noexcept override { return 10; }
228 virtual PositionerStageData::PositionType GetMinVelocity() const noexcept override { return 1; }
229 virtual PositionerStageData::PositionType GetMaxVelocity() const noexcept override { return 100e6; }
230 virtual PositionerStageData::PositionType GetDefaultVelocity() const noexcept override { return 1e6; }
231 virtual double GetStepNanoMeterRatio() const noexcept override { return 1e-3; } // pm to nm
232 virtual bool IsUsingSIUnits() const noexcept override { return true; } // Assuming SmarAct positioners with sensor
233
234 virtual void SetHome() const override { MakeAndEnqueueTask<SmarActTasks::SetHomeTask>(); }
235 virtual void Reference([[maybe_unused]] DirectionType Direction = DirectionType::Forward, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const override { MakeAndEnqueueTask<SmarActTasks::ReferenceTask>(std::move(CallbackFunc)); }
236 virtual void Calibrate(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const override { MakeAndEnqueueTask<SmarActTasks::CalibrateTask>(std::move(CallbackFunc)); }
237 virtual void SetVelocity(PositionerStageData::PositionType Velocity) const override { MakeAndEnqueueTask<SmarActTasks::SetVelocityTask>(Velocity); }
238
239 virtual void MoveToHome(DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const override { MakeAndEnqueueTask<SmarActTasks::MoveToHomeTask>(std::move(CallbackFunc)); }
240 virtual void MoveAbsolute(PositionerStageData::PositionType Position, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const override { MakeAndEnqueueTask<SmarActTasks::MoveAbsoluteTask>(Position, std::move(CallbackFunc)); }
241 virtual void MoveRelative(PositionerStageData::PositionType Position, DynExp::TaskBase::CallbackType CallbackFunc = nullptr) const override { MakeAndEnqueueTask<SmarActTasks::MoveRelativeTask>(Position, std::move(CallbackFunc)); }
242 virtual void StopMotion() const override { MakeAndEnqueueTask<SmarActTasks::StopMotionTask>(); }
243
244 private:
245 virtual void OnErrorChild() const override;
246
247 void ResetImpl(dispatch_tag<PositionerStage>) override final;
249
250 virtual std::unique_ptr<DynExp::InitTaskBase> MakeInitTask() const override { return DynExp::MakeTask<SmarActTasks::InitTask>(); }
251 virtual std::unique_ptr<DynExp::ExitTaskBase> MakeExitTask() const override { return DynExp::MakeTask<SmarActTasks::ExitTask>(); }
252 virtual std::unique_ptr<DynExp::UpdateTaskBase> MakeUpdateTask() const override { return DynExp::MakeTask<SmarActTasks::UpdateTask>(); }
253 };
254}
Defines DynExp's core module as an interface between the UI and DynExp objects.
Implementation of a hardware adapter to control SmarAct MCS2 hardware.
Implementation of a meta instrument to control single-axis positioner stages.
Configurator class for PositionerStage.
Definition Stage.h:142
Data class for PositionerStage.
Definition Stage.h:66
signed long long PositionType
Numeric type to store the stage positions.
Definition Stage.h:71
Parameter class for PositionerStage.
Definition Stage.h:119
Defines a task for deinitializing an instrument within an instrument inheritance hierarchy....
Definition Stage.h:39
Defines a task for initializing an instrument within an instrument inheritance hierarchy....
Definition Stage.h:26
Defines a task for updating an instrument within an instrument inheritance hierarchy....
Definition Stage.h:52
Implementation of a meta instrument to control single-axis positioner stages.
Definition Stage.h:155
DirectionType
Type to determine the direction of the positioner stage's movements.
Definition Stage.h:160
virtual ~SmarActConfigurator()=default
virtual DynExp::ParamsBasePtrType MakeParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core) const override
Override to make derived classes call DynExp::MakeParams with the correct configurator type derived f...
Definition SmarAct.h:208
PositionType HomePosition
Definition SmarAct.h:174
virtual bool IsMovingChild() const noexcept override
Returns whether the stage is currently moving (result of IsMovingChild())
Definition SmarAct.h:165
virtual bool HasArrivedChild() const noexcept override
Returns whether the stage has arrived at its destiny position (result of HasArrivedChild())
Definition SmarAct.h:166
auto GetSmarActChannelStatus() const noexcept
Definition SmarAct.h:154
DynExpHardware::SmarActHardwareAdapter::ChannelType Channel
Definition SmarAct.h:170
auto GetChannel() const noexcept
Definition SmarAct.h:150
virtual ~SmarActData()=default
virtual void ResetImpl(dispatch_tag< SmarActData >)
Definition SmarAct.h:163
void SetHomePosition(PositionType HomePosition) noexcept
Definition SmarAct.h:157
auto & GetSmarActChannelStatus() noexcept
Definition SmarAct.h:153
virtual bool HasFailedChild() const noexcept override
Returns whether the stage is in an error state, i.e. moving has failed (result of HasFailedChild())
Definition SmarAct.h:167
void ResetImpl(dispatch_tag< PositionerStageData >) override final
Refer to DynExp::InstrumentDataBase::Reset(). Using tag dispatch mechanism to ensure that ResetImpl()...
Definition SmarAct.cpp:157
size_t NumFailedStatusUpdateAttempts
Definition SmarAct.h:173
auto GetHomePosition() const noexcept
Definition SmarAct.h:156
virtual bool IsReferencedChild() const noexcept override
Returns whether a closed-loop positioner knows its position in respect to its zero point (result of I...
Definition SmarAct.h:168
DynExp::LinkedObjectWrapperContainer< DynExpHardware::SmarActHardwareAdapter > HardwareAdapter
Definition SmarAct.h:159
SmarActChannelStatusType SmarActChannelStatus
Definition SmarAct.h:172
virtual void ConfigureParamsImpl(dispatch_tag< SmarActParams >)
Definition SmarAct.h:195
Param< DynExp::ObjectLink< DynExpHardware::SmarActHardwareAdapter > > HardwareAdapter
Definition SmarAct.h:185
SmarActParams(DynExp::ItemIDType ID, const DynExp::DynExpCore &Core)
Definition SmarAct.h:180
void ConfigureParamsImpl(dispatch_tag< PositionerStageParams >) override final
Called by DynExp::ParamsBase::ConfigureParams() as a starting point for the tag dispatch mechanism to...
Definition SmarAct.h:194
virtual ~SmarActParams()=default
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 SmarAct.h:183
Param< ParamsConfigDialog::NumberType > HoldTime
Definition SmarAct.h:189
Param< ParamsConfigDialog::NumberType > Channel
Definition SmarAct.h:187
CalibrateTask(CallbackType CallbackFunc) noexcept
Definition SmarAct.h:60
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
Definition SmarAct.cpp:99
virtual void ExitFuncImpl(dispatch_tag< ExitTask >, DynExp::InstrumentInstance &Instance)
Definition SmarAct.h:33
void ExitFuncImpl(dispatch_tag< PositionerStageTasks::ExitTask >, DynExp::InstrumentInstance &Instance) override final
Deinitializes the respective instrument within the instrument inheritance hierarchy....
Definition SmarAct.cpp:24
void InitFuncImpl(dispatch_tag< PositionerStageTasks::InitTask >, DynExp::InstrumentInstance &Instance) override final
Initializes the respective instrument within the instrument inheritance hierarchy....
Definition SmarAct.cpp:8
virtual void InitFuncImpl(dispatch_tag< InitTask >, DynExp::InstrumentInstance &Instance)
Definition SmarAct.h:26
MoveAbsoluteTask(PositionerStageData::PositionType Position, CallbackType CallbackFunc) noexcept
Definition SmarAct.h:89
const PositionerStageData::PositionType Position
Definition SmarAct.h:95
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
Definition SmarAct.cpp:128
MoveRelativeTask(PositionerStageData::PositionType Position, CallbackType CallbackFunc) noexcept
Definition SmarAct.h:101
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
Definition SmarAct.cpp:138
const PositionerStageData::PositionType Position
Definition SmarAct.h:107
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
Definition SmarAct.cpp:118
MoveToHomeTask(CallbackType CallbackFunc) noexcept
Definition SmarAct.h:80
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
Definition SmarAct.cpp:89
ReferenceTask(CallbackType CallbackFunc) noexcept
Definition SmarAct.h:51
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
Definition SmarAct.cpp:80
const PositionerStageData::PositionType Velocity
Definition SmarAct.h:74
SetVelocityTask(PositionerStageData::PositionType Velocity) noexcept
Definition SmarAct.h:69
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
Definition SmarAct.cpp:109
virtual DynExp::TaskResultType RunChild(DynExp::InstrumentInstance &Instance) override
Runs the task. Override RunChild() to define a derived task's action(s). Any exception leaving RunChi...
Definition SmarAct.cpp:148
virtual void UpdateFuncImpl(dispatch_tag< UpdateTask >, DynExp::InstrumentInstance &Instance)
Definition SmarAct.h:40
void UpdateFuncImpl(dispatch_tag< PositionerStageTasks::UpdateTask >, DynExp::InstrumentInstance &Instance) override final
Updates the respective instrument within the instrument inheritance hierarchy. Call UpdateFuncImpl() ...
Definition SmarAct.cpp:44
virtual void MoveRelative(PositionerStageData::PositionType Position, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const override
Moves the positioner to a position relative to its current position. The position offset Steps has to...
Definition SmarAct.h:241
virtual void SetVelocity(PositionerStageData::PositionType Velocity) const override
Sets the positioner's velocity in its native units. Do divide units of PositionerStageData::Velocity ...
Definition SmarAct.h:237
virtual PositionerStageData::PositionType GetMaxPosition() const noexcept override
Returns the maximal position the stage can move to in nm if the stage supports SI units,...
Definition SmarAct.h:226
virtual void OnErrorChild() const override
Derived classes can perform critical shutdown actions after an error has occurred....
Definition SmarAct.cpp:172
virtual std::string GetName() const override
Returns the name of this Object type.
Definition SmarAct.h:223
virtual void Calibrate(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const override
Calibrates the positioner. The meaning of such a calibration is solely specified by the hardware manu...
Definition SmarAct.h:236
virtual std::unique_ptr< DynExp::InitTaskBase > MakeInitTask() const override
Factory function for an init task (InitTaskBase). Override to define the desired initialization task ...
Definition SmarAct.h:250
virtual PositionerStageData::PositionType GetResolution() const noexcept override
Returns the stage's position resolution (precision) in nm if the stage supports SI units,...
Definition SmarAct.h:227
virtual void Reference(DirectionType Direction=DirectionType::Forward, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const override
References the positioner such that it finds its zero position or end stop.
Definition SmarAct.h:235
virtual PositionerStageData::PositionType GetDefaultVelocity() const noexcept override
Returns the stage's default velocity in nm/s if the stage supports SI units, in steps/s otherwise.
Definition SmarAct.h:230
virtual ~SmarAct()
Definition SmarAct.h:221
virtual void MoveToHome(DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const override
Moves the positioner to its stored home position. Also refer to SetHome().
Definition SmarAct.h:239
virtual void StopMotion() const override
Stops any motion or position stabilization of the positioner immediately.
Definition SmarAct.h:242
virtual double GetStepNanoMeterRatio() const noexcept override
Determines the conversion factor in between internal PositionerStageData::PositionType position and v...
Definition SmarAct.h:231
virtual void SetHome() const override
Stores the positioner's home position. Also refer to MoveToHome().
Definition SmarAct.h:234
virtual std::unique_ptr< DynExp::ExitTaskBase > MakeExitTask() const override
Factory function for an exit task (ExitTaskBase). Override to define the desired deinitialization tas...
Definition SmarAct.h:251
virtual void ResetImpl(dispatch_tag< SmarAct >)
Definition SmarAct.h:248
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...
Definition SmarAct.h:252
virtual PositionerStageData::PositionType GetMinPosition() const noexcept override
Returns the minimal position the stage can move to in nm if the stage supports SI units,...
Definition SmarAct.h:225
virtual void MoveAbsolute(PositionerStageData::PositionType Position, DynExp::TaskBase::CallbackType CallbackFunc=nullptr) const override
Moves the positioner to an absolute position in its native units. Do divide units of PositionerStageD...
Definition SmarAct.h:240
virtual bool IsUsingSIUnits() const noexcept override
Determines whether the underlying hardware expects SI units for positions and velocities or arbitrary...
Definition SmarAct.h:232
static constexpr auto Name() noexcept
Definition SmarAct.h:218
void ResetImpl(dispatch_tag< PositionerStage >) override final
Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every de...
Definition SmarAct.cpp:180
virtual PositionerStageData::PositionType GetMaxVelocity() const noexcept override
Returns the maximal velocity the stage can move with in nm/s if the stage supports SI units,...
Definition SmarAct.h:229
virtual PositionerStageData::PositionType GetMinVelocity() const noexcept override
Returns the minimal velocity the stage can move with in nm/s if the stage supports SI units,...
Definition SmarAct.h:228
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:813
This class holds a pointer (LinkedObjectWrapperPointer) to a LinkedObjectWrapper. Intances of this cl...
Definition Object.h:3168
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 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
Type owning a callback function which is invoked when a task has finished, failed,...
Definition Instrument.h:978
Base class for all tasks being processed by instruments. The class must not contain public virtual fu...
Definition Instrument.h:929
CallbackType CallbackFunc
This callback function is called after the task has finished (either successfully or not) with a poin...
TaskBase(CallbackType CallbackFunc=nullptr, std::chrono::system_clock::time_point DeferUntil={}) noexcept
Constructs an instrument task.
Defines the return type of task functions.
Definition Instrument.h:865
Refer to DynExp::ParamsBase::dispatch_tag.
DynExp's instrument namespace contains the implementation of DynExp instruments which extend DynExp's...
constexpr auto HardwareAdapter
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.
Accumulates include statements to provide a precompiled header.
constexpr bool IsReferencing() const noexcept
Definition SmarAct.h:131
constexpr void Set(int32_t ByteCode) noexcept
Definition SmarAct.h:124
constexpr bool IsSensorPresent() const noexcept
Definition SmarAct.h:126
constexpr bool IsEndStopReached() const noexcept
Definition SmarAct.h:129
constexpr bool IsCalibrated() const noexcept
Definition SmarAct.h:134
constexpr bool IsErrorState() const noexcept
Definition SmarAct.h:136
constexpr bool IsRangeLimitReached() const noexcept
Definition SmarAct.h:130
constexpr bool IsClosedLoopActive() const noexcept
Definition SmarAct.h:128
constexpr bool IsMoving() const noexcept
Definition SmarAct.h:127
constexpr bool IsReferenced() const noexcept
Definition SmarAct.h:133
constexpr bool IsCalibrating() const noexcept
Definition SmarAct.h:132