Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
Controller.h
Go to the documentation of this file.
1#pragma once
5
6namespace sf::gmi
7{
8
13{
14 public:
19 {
20 Parameters() = default;
21
22 explicit Parameters(int mode)
23 : _mode(mode)
24 {}
25
26 int _mode{0};
27 };
28
33
37 virtual ~Controller();
38
42 void destroy();
43
47 bool initialize();
48
53
57 void hookEventHandler(ControllerEvent handler);
58
62 void unhookEventHandler(ControllerEvent handler);
63
69 bool storeSettings(bool rd);
70
75 {
76 public:
80 EAxisLocation getLocation() const;
81
85 AxisMovements getMovements() const;
86
90 const char* getName() const;
91
95 const char* getDescription() const;
96
100 double getCurrent(EAxisValueType avt) const;
101
105 bool setCurrent(EAxisValueType avt, double val);
106
110 double getAccuracy() const;
111
115 double getResolution() const;
116
120 double getMinMax(EAxisMinMax amm) const;
121
125 bool setOffset(double ofs);
126
130 double setOffset() const;
131
135 double getTarget(EAxisValueType avt) const;
136
140 bool setTarget(EAxisValueType avt, double val);
141
145 bool setPosition(double value);
146
152 double normalized(double pos) const;
153
157 bool setMode(EAxisMode mode);
158
163
167 bool canModeChange(EAxisMode cur_mode, EAxisMode new_mode, bool pos_cmplt, bool vel_cmplt, bool con_cmplt);
168
173
174 protected:
179
183 virtual ~Axis();
184
189
190 private:
194 Controller& _controller;
198 EAxisLocation _location;
199
200 friend Controller;
201 };
202
207 bool homeAxes(bool skip);
208
214
219
225
230
235
240
244 bool setTriggerEnable(bool enable);
245
249 bool getTriggerEnable() const;
250
255 double setTriggerFreq(double freq);
256
261 double getTriggerFreq() const;
262
263 //
264 // Movement execution related functions and properties.
265 //
266
272
277
282
287
292
298
302 Axis& getAxis(int axis_loc);
303
307 const Axis& getAxis(int axis_loc) const;
308
312 Axis& getPhysicalAxis(int axis_num);
313
318
325 bool getCurrent(EAxisValueType avt, AxesCoord& ac) const;
326
333 bool setCurrent(EAxisValueType avt, const AxesCoord& coord);
334
341 bool getTarget(EAxisValueType avt, AxesCoord& coord) const;
342
349 bool setTarget(EAxisValueType avt, const AxesCoord& coord);
350
359 bool setTarget(const AxesCoord& pos, const AxesCoord& vel, const AxesCoord& acc, bool linear);
360
368 bool setMode(EAxisMode am, const AxesCoord& ac, EAxisMode amdef = amDISABLED);
369
375
381
385 double getTriggerDensity() const;
386
390 bool setTriggerDensity(double td);
391
395 bool setTriggerMode(bool intern);
396
400 bool getTriggerMode() const;
401
406
411
415 bool isMovePosCompleted() const;
416
420 bool isMoveVelCompleted() const;
421
425 bool isMoveConCompleted() const;
426
431 bool isMoving() const;
432
436 bool setPosition(EAxisLocation al, double value);
437
441 bool setPosition(const AxesCoord& ac);
442
451
459 AxesCoord normalized(const AxesCoord& dist) const;
460
465
469 virtual void openDebugger() {}
470
471 // Information retrieval functions.
475 enum EStatus : int
476 {
478 csERROR = -1,
480 csUNINIT = 0,
489 };
490
494 inline bool isReady() const;
495
499 static const char* getAxisName(int axis_loc);
500
504 static const char* getAxisDescription(int axis_loc);
505
509 static const char* getStatusName(EStatus status);
510
514 const char* getStatusName() const;
515
519 unsigned getAxisCount() const;
520
524 std::string getLastErrorText() const;
525
526 //
527 // Parameter manipulation and retrieval functions.
528 //
529
533 bool getParamInfo(IdType id, ParamInfo& info) const;
534
539 bool getParam(IdType id, Value& value) const;
540
544 bool setParam(IdType id, const Value& value, bool skip_event);
545
549 bool setGetParam(IdType id, Value& value, bool skip_event);
550
556 virtual bool handleParam(IdType id, ParamInfo* info, const Value* setval, Value* getval) = 0;
557
562 virtual IdType getParamId(EParam param, int axis = std::numeric_limits<int>::max()) const = 0;
563
567 virtual bool enumParamIds(IdList& ids) const = 0;
568
572 void setParamHook(NotifyProc proc, void* data);
573
577 void setResultHook(NotifyProc proc, void* data);
578
583 virtual IdType getResultId(EResult result, int axis = std::numeric_limits<int>::max()) const = 0;
584
588 virtual bool enumResultIds(IdList& ids) const = 0;
589
593 bool getResultInfo(IdType id, ResultInfo& info) const;
594
598 virtual bool handleResult(IdType id, ResultInfo* info, BufferInfo* buf_info) = 0;
599
604 bool getResultBuffer(IdType id, BufferInfo& buf_info);
605
609 bool getAccuracy(AxesCoord& accuracy) const;
610
614 bool getResolution(AxesCoord& resolution) const;
615
619 bool getMinMax(EAxisMinMax amm, AxesCoord& coord) const;
620
624 bool setOffset(const AxesCoord& coord);
625
629 bool getOffset(AxesCoord& coord) const;
630
634 std::string getProfilePath() const;
635
636 protected:
641 virtual bool doInitialize(bool) = 0;
642
647 virtual bool doSetPosition(EAxisLocation al, double);
648
653 virtual bool doHomeAxes(bool skip);
654
658 void setLastErrorText(const char* text);
659
663 void setStatus(EStatus status);
664
668 EStatus getStatus() const;
669
675
681
686 void sendPopEvent();
687
688 private:
692 void sendEvent(EControllerEvent ce);
693
698 bool setParam(EParam param, int axis, const Value& value, bool skip_event);
699
704 bool getParam(EParam param, int axis, Value& value) const;
705
710 void attach(Axis* axis);
711
715 Axis* getAxisPtr(int axis_loc);
716
720 bool _flagDestroying;
724 Axis::PtrVector _axes;
728 Axis* _axesMap[alLastEntry];
732 Axis _nullAxis;
736 std::string _lastErrorText;
740 EStatus _status;
744 NotifyProc _paramNotifyProc;
748 NotifyProc _resultNotifyProc;
752 void* _paramNotifyData;
756 void* _resultNotifyData;
760 bool _noEventGeneration;
768 EventList _motionEventList;
769
770 friend Axis;
771
772 // Declarations of static functions and data members to be able to create registered RSA implementations.
774};
775
776inline bool Controller::isReady() const
777{
778 return _status == csREADY;
779}
780
781inline bool Controller::getResultInfo(IdType id, ResultInfo& info) const
782{
783 return const_cast<Controller*>(this)->handleResult(id, &info, nullptr);
784}
785
787{
788 return handleResult(id, nullptr, &buf_info);
789}
790
791inline bool Controller::getParamInfo(IdType id, ParamInfo& info) const
792{
793 return const_cast<Controller*>(this)->handleParam(id, &info, NULL, NULL);
794}
795
796inline bool Controller::getParam(IdType id, Value& value) const
797{
798 return const_cast<Controller*>(this)->handleParam(id, NULL, NULL, &value);
799}
800
802{
803 sendEvent(cePOPEVENT);
804}
805
806inline void Controller::setParamHook(NotifyProc proc, void* data)
807{
808 _paramNotifyProc = proc;
809 _paramNotifyData = data;
810}
811
812inline void Controller::setResultHook(NotifyProc proc, void* data)
813{
814 _resultNotifyProc = proc;
815 _resultNotifyData = data;
816}
817
819{
820 return getMovePos() == mpcCOMPLETE;
821}
822
824{
825 return getMoveVel() == mvcCOMPLETE;
826}
827
829{
830 return getMoveCon() == mccCOMPLETE;
831}
832
833inline unsigned Controller::getAxisCount() const
834{
835 return _axes.count();
836}
837
838inline Controller::Axis* Controller::getAxisPtr(int axis_loc)
839{
840 return &getAxis(axis_loc);
841}
842
844{
845 return _status;
846}
847
848inline std::string Controller::getLastErrorText() const
849{
850 return _lastErrorText;
851}
852
853inline void Controller::setLastErrorText(const char* text)
854{
855 _lastErrorText = text;
856}
857
858inline const char* Controller::getStatusName() const
859{
860 return getStatusName(_status);
861}
862
864{
865 AxesCoord ac(dist);
866 return normalize(ac);
867}
868
870{
871 return _location;
872}
873
875{
876 return _movements;
877}
878
879}// namespace sf::gmi
#define SF_DECL_IFACE(InterfaceType, ParamType, FuncName)
Declares a public static function in the class where it is used. Where: InterfaceType: Global typenam...
Definition TClassRegistration.h:71
Dialog containing multiple property pages.
Definition qt/PropertySheetDialog.h:14
Counted vector having additional methods and operators for ease of usage.
Definition TVector.h:25
size_type count() const
Returns the amount of entries in the vector.
Definition TVector.h:625
Value container class able to performing arithmetic functions.
Definition Value.h:19
All axis values in one structure accompanied by some handy manipulation methods.
Definition AxesCoord.h:13
Interface class to access Axis properties and functions.
Definition Controller.h:75
bool canModeChange(EAxisMode cur_mode, EAxisMode new_mode, bool pos_cmplt, bool vel_cmplt, bool con_cmplt)
Returns true if the mode can be changed.
bool setCurrent(EAxisValueType avt, double val)
Sets the current position/velocity/acceleration. Only when not moving.
double getTarget(EAxisValueType avt) const
Returns the current velocity.
double getResolution() const
Returns the resolution of the axis.
bool setTarget(EAxisValueType avt, double val)
Sets the current velocity.
EAxisMode getMode() const
Returns the mode of operation.
TVector< Axis * > PtrVector
Easy to use vector for an array of Axis pointers.
Definition Controller.h:172
double normalized(double pos) const
normalize the passed position for all unlimited rotation axes. Uses accuracy to find the actual posit...
double getAccuracy() const
Returns the accuracy for velocity and position.
virtual ~Axis()
Virtual destructor for possible derived destructors.
const char * getName() const
Returns the name of this instance.
EAxisLocation getLocation() const
Returns the location of the axis in the constellation of axes.
Definition Controller.h:869
AxisMovements getMovements() const
Returns the possible movements the is instance can make.
Definition Controller.h:874
double setOffset() const
Get the position offset.
bool setOffset(double ofs)
Set the position offset.
bool setMode(EAxisMode mode)
Sets the axis mode for operation. Returns false on failure.
Axis(Controller *mc, EAxisLocation)
Constructor that registers itself at the passed controller.
double getMinMax(EAxisMinMax amm) const
Gets the current extremes from this axis.
double getCurrent(EAxisValueType avt) const
Returns the current position/velocity/acceleration.
AxisMovements _movements
Holds the possible movements.
Definition Controller.h:188
const char * getDescription() const
Returns the description of this instance.
bool setPosition(double value)
Sets the current position.
Pure virtual class for implementation of motion controllers.
Definition Controller.h:13
const char * getStatusName() const
Gets the current status as a name.
Definition Controller.h:858
bool getMinMax(EAxisMinMax amm, AxesCoord &coord) const
Gets the current axes extremes.
static const char * getAxisDescription(int axis_loc)
Gets the description of the axis.
std::string getLastErrorText() const
Gets the last error if there is one.
Definition Controller.h:848
double getTriggerDensity() const
Gets the density of measurements in radians or meters depending on selected axis.
bool setChuckJaw(EChuckJaw cj)
Sets chuck-jaw state.
bool getResultInfo(IdType id, ResultInfo &info) const
Retrieve information about the passed result id.
Definition Controller.h:781
void sendPopEvent()
Sends a POP event to the hooked event handlers. Is to be called by the implementation to signal that ...
Definition Controller.h:801
bool setTriggerEnable(bool enable)
Sets the trigger enable.
AxesCoord normalized(const AxesCoord &dist) const
normalize the passed position for all unlimited rotation axes. Uses accuracy to find the actual posit...
Definition Controller.h:863
virtual IdType getResultId(EResult result, int axis=std::numeric_limits< int >::max()) const =0
Gets the ID of the result for the specified gate. Value std::numeric_limits<int>::max() tells the imp...
void destroy()
Must be called from a derived class in the destructor before anything.
virtual bool doSetPosition(EAxisLocation al, double)
Can be overloaded by a derived class. Sets the current position.
EAxisLocation getTriggerAxis() const
Gets the current selected trigger axis.
AxesCoord & normalize(AxesCoord &pos) const
normalize the passed position for all unlimited rotation axes. Uses accuracy to find the actual posit...
bool setPosition(const AxesCoord &ac)
Sets the current position of all axis.
void hookEventHandler(ControllerEvent handler)
Attaches the event handler for events.
virtual bool handleParam(IdType id, ParamInfo *info, const Value *setval, Value *getval)=0
This function must be overloaded to handle the interface parameters. When info in non-null the parame...
bool getParam(IdType id, Value &value) const
Returns the value of the specified parameter id. When the ID does not exist it returns false.
Definition Controller.h:796
static const char * getAxisName(int axis_loc)
Gets the name of the axis.
bool setTarget(EAxisValueType avt, const AxesCoord &coord)
Set the target value type.
void setLastErrorText(const char *text)
Derived classes can set the error text for the function.
Definition Controller.h:853
EChuckJaw getChuckJaw() const
Gets chuck-jaw state.
EAxisLocation getJoystickAxis() const
Returns the current selected axis on the joystick control. This does not mean it is enabled.
double getTriggerFreq() const
Returns the trigger internal frequency generator.
unsigned getAxisCount() const
Gets the amount real implemented axes.
Definition Controller.h:833
static const char * getStatusName(EStatus status)
Gets the status name of the current status.
Axis & getPhysicalAxis(int axis_num)
Returns the physical axis location of the passed axis number.
bool setOffset(const AxesCoord &coord)
Sets the position offset for all position related parameters of all axes.
bool setMovePos(EMovePosCmd mpc)
Executes a passed move position command.
bool getAccuracy(AxesCoord &accuracy) const
Gets the accuracy of positions of the implementation for a coords compare.
bool setPopAxis(EAxisLocation al)
Sets the selected axis for the pop event source.
EMovePosCmd getMovePos() const
Returns the current active position command. When moving position the command returned will eventuall...
EAxisLocation getPopAxis() const
Returns the current selected axis on the pop event source.
bool isReady() const
Returns true if the current status is READY.
Definition Controller.h:776
void callParamHook(IdType id)
Calls the hooked function if it exists. Passing the set data pointer and the ID of the effected param...
Controller(const Parameters &)
Constructor for passing general structure for derived classes.
bool getTarget(EAxisValueType avt, AxesCoord &coord) const
Gets the target set for this axis.
EMoveConCmd getMoveCon() const
Returns the current active velocity command.
bool setTriggerDensity(double td)
Sets the density of measurements in rads or m depending on selected axis.
bool isMoveVelCompleted() const
Returns true if the velocity move is completed.
Definition Controller.h:823
void setParamHook(NotifyProc proc, void *data)
Sets a procedure hook for the interface implementation to be called when the value changes as a resul...
Definition Controller.h:806
virtual void openDebugger()
Opens a debugger dialog for the motion controller if any.
Definition Controller.h:469
bool setJoystick(EJoystickCmd jsc)
Enables or disables the joystick mode of the controller.
EStatus
States the controller can have.
Definition Controller.h:476
@ csHOMING
Is currently homing.
Definition Controller.h:486
@ csINIT
Initialized.
Definition Controller.h:482
@ csUNHOMED
Axes are not homed yet.
Definition Controller.h:484
@ csREADY
Is ready for action.
Definition Controller.h:488
virtual bool doHomeAxes(bool skip)
Does the real execution of the home function and must be overloaded. When skip has been passed the im...
bool setGetParam(IdType id, Value &value, bool skip_event)
Sets and immediately gets the same value again clipped or not. When skip event is true the callParamH...
bool setTriggerMode(bool intern)
Sets Trigger mode.
void unhookEventHandler(ControllerEvent handler)
Detaches the event handler for events.
const Axis & getAxis(int axis_loc) const
Gets a const reference to the axis at the specified location.
bool homeAxes(bool skip)
Start homing procedure and returns true when successfully started. When skip has been passed the impl...
virtual ~Controller()
Virtual destructor for derived classes.
EJoystickCmd getJoystick() const
Returns the joystick state. Off=0, Stop=1 and On=2.
bool initialize()
Initializes the hardware for operation and starts the thread when doInitialize returns true.
EStatus getStatus() const
Gets the status value.
Definition Controller.h:843
double setTriggerFreq(double freq)
Sets the trigger internal frequency generator and returns the clipped or rounded value.
virtual void addPropertyPages(PropertySheetDialog *sheet)
Adds controller specific property pages to the passed sheet.
bool isMovePosCompleted() const
Returns true if the last position move is completed.
Definition Controller.h:818
bool setPosition(EAxisLocation al, double value)
Sets the current position of single axis.
virtual bool handleResult(IdType id, ResultInfo *info, BufferInfo *buf_info)=0
This function must be overloaded to handle the interface results.
bool getCurrent(EAxisValueType avt, AxesCoord &ac) const
Gets the current axes values.
void callResultHook(IdType id)
Calls the hooked function if it exists. Passing the set data pointer and the ID of the effected resul...
bool setMode(EAxisMode am, const AxesCoord &ac, EAxisMode amdef=amDISABLED)
Sets the mode according the in the coord specified axes.
bool setJoystickAxis(EAxisLocation axis_loc)
Sets the selected axis for the joystick enabled or not.
bool setTriggerAxis(EAxisLocation al)
Sets the axis which pulses are used to derive the trigger pulses.
bool getTriggerMode() const
Gets the trigger mode.
Axis & getAxis(int axis_loc)
Gets a reference to the axis at the specified location.
bool setCurrent(EAxisValueType avt, const AxesCoord &coord)
Sets the current axes values.
bool setMoveCon(EMoveConCmd mcc)
Executes a passed move continuous command.
virtual bool doInitialize(bool)=0
Initialization function which must be overloaded by a derived class. Should check the hardware config...
bool getResolution(AxesCoord &resolution) const
Gets the resolution on all axis for the implementation.
bool isMoveConCompleted() const
Returns true if the contineous move is completed.
Definition Controller.h:828
void setResultHook(NotifyProc proc, void *data)
Sets a procedure hook for the interface implementation to be called when there ias data result has da...
Definition Controller.h:812
bool getParamInfo(IdType id, ParamInfo &info) const
Retrieve information about the passed param id.
Definition Controller.h:791
bool setParam(IdType id, const Value &value, bool skip_event)
Sets an interface parameter and notifies hooked user when skip_event is false.
virtual bool enumResultIds(IdList &ids) const =0
Enumerate interface results ids.
bool setTarget(const AxesCoord &pos, const AxesCoord &vel, const AxesCoord &acc, bool linear)
Set the target.
bool storeSettings(bool rd)
Reads or writes the non exported parameters/settings to profile.
bool uninitialize()
Un-initializes the hardware.
virtual IdType getParamId(EParam param, int axis=std::numeric_limits< int >::max()) const =0
Gets the ID of the parameter for the specified gate. Value std::numeric_limits<int>::max() tells the ...
bool isMoving() const
Function testing for movement of position and velocity mode. When there is an abort state of-any-of t...
bool setMoveVel(EMoveVelCmd mvc)
Executes a passed move velocity command.
EMoveVelCmd getMoveVel() const
Returns the current active velocity command.
std::string getProfilePath() const
Returns the configuration profile path of this implementation.
AxisLocations getRadialUnlimited() const
Gets a bitmap set of radial unlimited axis locations.
void setStatus(EStatus status)
Used by derived classes to set the controllers status.
virtual bool enumParamIds(IdList &ids) const =0
Enumerate interface parameters ids.
bool getOffset(AxesCoord &coord) const
Returns the current offset for all axes.
bool getTriggerEnable() const
Gets the trigger enable status.
bool getResultBuffer(IdType id, BufferInfo &buf_info)
Gets the result buffer associated with the result ID passed in the result hook at the time of the cal...
Definition Controller.h:786
#define _GMI_CLASS
Definition gmi/iface/global.h:35
Definition AxesCoord.h:7
void(* NotifyProc)(void *data, IdType id)
Function type for the function type which is called when a parameter changes as a result of changes i...
Definition GmiInterface.h:277
EChuckJaw
Definition GmiInterface.h:629
unsigned long long IdType
Type for gathering parameter ID's.
Definition GmiTypes.h:19
EAxisValueType
List of axis coordinate types. Use a full namespace type path when specifying a Q_PROPERTY(....
Definition GmiTypes.h:31
EMovePosCmd
Enumerate for controller position movement command.
Definition GmiInterface.h:481
@ mpcCOMPLETE
Stop current movement smooth.
Definition GmiInterface.h:485
EAxisMode
Enumerate for controller mode of operation.
Definition GmiInterface.h:578
EAxisMinMax
Enumerate for retrieving axis extremes.
Definition GmiInterface.h:606
TSet< EAxisLocation > AxisLocations
Bitmap set of axis locations.
Definition GmiTypes.h:141
EResult
Motion default results.
Definition GmiInterface.h:458
EMoveVelCmd
Enumerate for controller velocity movement command.
Definition GmiInterface.h:508
@ mvcCOMPLETE
No movement.
Definition GmiInterface.h:512
EMoveConCmd
Enumerate for controller continuous movement command.
Definition GmiInterface.h:531
@ mccCOMPLETE
No movement.
Definition GmiInterface.h:535
EJoystickCmd
Enumerate for controller Joy movement command.
Definition GmiInterface.h:554
EParam
Motion default parameters. List of ids which must always be implemented for each motion implementatio...
Definition GmiInterface.h:284
EAxisLocation
Enumeration of axis locations.
Definition GmiTypes.h:81
@ alLastEntry
Last entry used in iterations.
Definition GmiTypes.h:131
EControllerEvent
Enumerate for controller events.
Definition GmiInterface.h:647
@ cePOPEVENT
POP axis has made a rotation.
Definition GmiInterface.h:667
TSet< EAxisMovement > AxisMovements
Bitmap set of axis movements.
Definition GmiTypes.h:75
Structure to hold data update information.
Definition GmiInterface.h:231
Arguments for when creating a controller implementation.
Definition Controller.h:19
Parameters(int mode)
Definition Controller.h:22
Structure to hold parameter information.
Definition GmiInterface.h:107
Structure to hold parameter information.
Definition GmiInterface.h:171