You're reading the documentation for an older, but still supported version (1.33.4).
For information on the latest version, please have a look at 1.33.5.
For information on the latest version, please have a look at 1.33.5.
set_on_monitoring_state
This function registers a callback that automatically detects changes in the operation state of the robot controller. It is useful for executing specific actions automatically when the robot’s state changes.
Definition
DRFLEx.h within class CDRFLEx, public section
void set_on_monitoring_state(TOnMonitoringStateCB pCallbackFunc) {
_set_on_monitoring_state(_rbtCtrl, pCallbackFunc);
};
Parameter
Parameter Name |
Data Type |
Default Value |
Description |
|---|---|---|---|
pCallbackFunc |
Callback function pointer to be registered for robot state monitoring |
Return
None
Example
std::atomic<bool> g_bNeedServoOn(false);
void OnMonitoringStateCB(const ROBOT_STATE eState)
{
switch ((unsigned char)eState)
{
case STATE_SAFE_OFF:
// Request servo on from the main loop
g_bNeedServoOn = true;
break;
default:
break;
}
}
drfl.set_on_monitoring_state(OnMonitoringStateCB);
// Main loop: call set_robot_control outside the callback
while (true) {
if (g_bNeedServoOn) {
g_bNeedServoOn = false;
drfl.set_robot_control(CONTROL_SERVO_ON);
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
This example registers a state monitoring callback that sets a flag when the controller enters the SAFE OFF state; the main loop then turns on the robot servo. Call set_robot_control outside the callback; see Rules for callback functions.