itom
|
Helper class to give plugin developers an easy access to actuators in other threads. More...
#include <pluginThreadCtrl.h>
Public Member Functions | |
ActuatorThreadCtrl () | |
default constructor. No actuator instance is currently under control. | |
ActuatorThreadCtrl (const ito::ParamBase &pluginParameter, ito::RetVal *retval=NULL) | |
Creates the control object for an actuator plugin instance. | |
ActuatorThreadCtrl (ito::AddInActuator *plugin, ito::RetVal *retval=NULL) | |
Creates the control object for a actuator plugin instance. | |
ActuatorThreadCtrl (const ActuatorThreadCtrl &other) | |
copy constructor. The reference counter of the covered plugin by other will be incremented another time. | |
virtual | ~ActuatorThreadCtrl () |
destructor. Decrements the reference counter of the covered plugin and deletes it, if it drops to zero. | |
ito::RetVal | setPosRel (const QVector< int > &axes, const QVector< double > &relPositions, int timeOutMS=PLUGINWAIT) |
ito::RetVal | setPosAbs (const QVector< int > &axes, const QVector< double > &absPositions, int timeOutMS=PLUGINWAIT) |
ito::RetVal | setPosRel (int axis, double relPosition, int timeOutMS=PLUGINWAIT) |
ito::RetVal | setPosAbs (int axis, double absPosition, int timeOutMS=PLUGINWAIT) |
ito::RetVal | getPos (QVector< int > axes, QVector< double > &positions, int timeOutMS=PLUGINWAIT) |
ito::RetVal | getPos (int axis, double &position, int timeOutMS=PLUGINWAIT) |
ito::RetVal | checkAxis (int axisNum) |
Public Member Functions inherited from ito::PluginThreadCtrl | |
PluginThreadCtrl () | |
default constructor. No plugin instance is currently under control. | |
PluginThreadCtrl (const ito::ParamBase &pluginParameter, ito::RetVal *retval=NULL) | |
Creates the control object for a plugin instance. | |
PluginThreadCtrl (ito::AddInBase *plugin, ito::RetVal *retval=NULL) | |
Creates the control object for a plugin instance. | |
PluginThreadCtrl (const PluginThreadCtrl &other) | |
copy constructor. The reference counter of the covered plugin by other will be incremented another time. | |
virtual | ~PluginThreadCtrl () |
destructor. Decrements the reference counter of the covered plugin and deletes it, if it drops to zero. | |
PluginThreadCtrl & | operator= (const PluginThreadCtrl &other) |
assignment operator. Gets control over the plugin currently covered by other. Decrements the reference counter of the former plugin and increments it of the plugin controlled by other. | |
ito::RetVal | getParam (ito::Param &val, int timeOutMS=PLUGINWAIT) |
ito::RetVal | setParam (ito::ParamBase val, int timeOutMS=PLUGINWAIT) |
ito::RetVal | waitForSemaphore (int timeOutMS=PLUGINWAIT) |
Protected Attributes | |
int | m_numAxes |
Protected Attributes inherited from ito::PluginThreadCtrl | |
ito::AddInBase * | m_pPlugin |
ItomSharedSemaphoreLocker | m_semaphoreLocker |
Helper class to give plugin developers an easy access to actuators in other threads.
The ActuatorThreadCtrl-Class can be used in filters and algorithms when an actuator plugin should be controlled by another thread. To create this controlling instance, at first, create an instance of the actuator plugin itself, then, pass it to the constructor of ActuatorThreadCtrl. In the following example, an instance of DummyMotor is passed as first mandatory argument to the init method of your plugin. You would like to create an easy thread control wrapper around this actuator plugin:
Using this class, all main methods of the actuator plugin can be directly called with an optional timeout value (in ms). The thread control, timeout checks... is then done by this helper class.
Use getPos to obtain the current position (in mm or degree) for one multiple axes. Inversely, setPosRel or setPosAbs will set the absolute or relative position(s) of one or multiple axes. Usually, setPosXXX will only return after the position has been reached. If you want to continue within your code while the actuator is still moving, check if your specific actuator has the 'async' parameter defined. If so, set it to 1 (see example below):
ito::ActuatorThreadCtrl::ActuatorThreadCtrl | ( | const ito::ParamBase & | pluginParameter, |
ito::RetVal * | retval = NULL ) |
Creates the control object for an actuator plugin instance.
This implementation gets the controlled instance from a ito::ParamBase object of param type ito::ParamBase::HWRef. Use this version, if the controlled plugin is passed to an algorithm or other plugin via a vector of mandatory or optional parameters in terms of ito::ParamBase objects.
This constructor increments the reference of the controlled plugin such that the plugin is not deleted until the reference has been decremented in the destructor of this class.
pluginParameter | is a plugin parameter of type ito::ParamBase::HWRef. |
retval | is an optional pointer to ito::RetVal. An error is set to this retval if the given plugin is no valid actuator plugin instance. |
ito::ActuatorThreadCtrl::ActuatorThreadCtrl | ( | ito::AddInActuator * | plugin, |
ito::RetVal * | retval = NULL ) |
Creates the control object for a actuator plugin instance.
This implementation gets the controlled instance from the real pointer to a ito::Actuator instance.
This constructor increments the reference of the controlled plugin such that the plugin is not deleted until the reference has been decremented in the destructor of this class.
plugin | is the pointer to the controlled plugin. |
retval | is an optional pointer to ito::RetVal. An error is set to this retval if the given plugin is no valid actuator plugin instance. |
ito::RetVal ito::ActuatorThreadCtrl::checkAxis | ( | int | axisNum | ) |
Check if an axis is within the axis-range
\detail Check if a specific axis is within the axisSpace of this actuator
[in] | axisNum | axis index to be checked |
ito::RetVal ito::ActuatorThreadCtrl::getPos | ( | int | axis, |
double & | position, | ||
int | timeOutMS = PLUGINWAIT ) |
Get the position of a single axis
\detail Get the position of a single axis specified by axis.
[in] | axis | Number of the axis |
[out] | pos | position of the axis |
[in] | timeOutMS | TimeOut for the semaphore-wait |
ito::RetVal ito::ActuatorThreadCtrl::getPos | ( | QVector< int > | axes, |
QVector< double > & | positions, | ||
int | timeOutMS = PLUGINWAIT ) |
Get the position of more than one axis
\detail Get the position of a number of axis specified by axisVec.
[in] | axisVec | Number of the axis |
[out] | posVec | Vector with position of the axis |
[in] | timeOutMS | TimeOut for the semaphore-wait |
ito::RetVal ito::ActuatorThreadCtrl::setPosAbs | ( | const QVector< int > & | axes, |
const QVector< double > & | absPositions, | ||
int | timeOutMS = PLUGINWAIT ) |
Move more than on axis absolute
\detail Move the axis in axisVec to the positions given in posVec. The axisVec and posVec must be same size. After the invoke-command this thread must wait / synchronize with the actuator-thread. Therefore the semaphore->wait is called via the function threadActuator::waitForSemaphore(timeOutMS) To enable the algorithm to process data during movement, the waitForSemaphore(timeOutMS) can be skipped by callWait = false. The threadActuator::waitForSemaphore(timeOutMS)-function must than be called by the algorithms afterwards / before the next command is send to the actuator.
[in] | axisVec | Vector with the axis to move |
[in] | posVec | Vector with the new absolute positions |
[in] | timeOutMS | TimeOut for the semaphore-wait, if (0) the waitForSemaphore is not called and must be called separate by the algorithm |
ito::RetVal ito::ActuatorThreadCtrl::setPosAbs | ( | int | axis, |
double | absPosition, | ||
int | timeOutMS = PLUGINWAIT ) |
Move a single axi absolute
\detail Move a single axis specified by axis to the position pos. After the invoke-command this thread must wait / synchronize with the actuator-thread. Therefore the semaphore->wait is called via the function threadActuator::waitForSemaphore(timeOutMS) To enable the algorithm to process data during movement, the waitForSemaphore(timeOutMS) can be skipped by callWait = false. The threadActuator::waitForSemaphore(timeOutMS)-function must than be called by the algorithms afterwards / before the next command is send to the actuator.
[in] | axis | Number of the axis |
[in] | pos | New position of the axis |
[in] | timeOutMS | TimeOut for the semaphore-wait, if (0) the waitForSemaphore is not called and must be called separate by the algorithm |
ito::RetVal ito::ActuatorThreadCtrl::setPosRel | ( | const QVector< int > & | axes, |
const QVector< double > & | relPositions, | ||
int | timeOutMS = PLUGINWAIT ) |
Move more than on axis relative to current position
\detail Move the axis in axisVec with a distance defined in stepSizeVec relative to current position. The axisVec and stepSizeVec must be same size. After the invoke-command this thread must wait / synchronize with the actuator-thread. Therefore the semaphore->wait is called via the function threadActuator::waitForSemaphore(timeOutMS) To enable the algorithm to process data during movement, the waitForSemaphore(timeOutMS) can be skipped by callWait = false. The threadActuator::waitForSemaphore(timeOutMS)-function must than be called by the algorithms afterwards / before the next command is send to the actuator.
[in] | axisVec | Vector with the axis to move |
[in] | stepSizeVec | Vector with the distances for every axis |
[in] | timeOutMS | TimeOut for the semaphore-wait, if (0) the waitForSemaphore is not called and must be called separate by the algorithm |
ito::RetVal ito::ActuatorThreadCtrl::setPosRel | ( | int | axis, |
double | relPosition, | ||
int | timeOutMS = PLUGINWAIT ) |
Move a single axis relative to current position
\detail Move a single axis specified by axis with a distance defined in stepSize relative to current position. After the invoke-command this thread must wait / synchronize with the actuator-thread. Therefore the semaphore->wait is called via the function threadActuator::waitForSemaphore(timeOutMS) To enable the algorithm to process data during movement, the waitForSemaphore(timeOutMS) can be skipped by callWait = false. The threadActuator::waitForSemaphore(timeOutMS)-function must than be called by the algorithms afterwards / before the next command is send to the actuator.
[in] | axis | Number of the axis |
[in] | stepSize | Distances from current position |
[in] | timeOutMS | TimeOut for the semaphore-wait, if (0) the waitForSemaphore is not called and must be called separate by the algorithm |