TOnMonitoringStateCB
This callback function is used to check changes in the operation state of the robot controller.
See Rules for callback functions.
Defined in: DRFLEx.h
typedef void (*TOnMonitoringStateCB)(const ROBOT_STATE);
void set_on_monitoring_state(TOnMonitoringStateCB pCallbackFunc)
{
_set_on_monitoring_state(_rbtCtrl, pCallbackFunc);
};
Parameter
Parameter Name |
Data Type |
Default Value |
Description |
|---|---|---|---|
eState |
Refer to the Definition of Enumeration Type. |
Return
None
Example
#include "DRFLEx.h"
#include <atomic>
#include <chrono>
#include <cstdio>
#include <thread>
using namespace DRAFramework;
std::atomic<bool> g_bNeedServoOn(false);
// Callback function: triggered whenever the robot’s operational state changes
void OnMonitoringStateCB(const ROBOT_STATE eState)
{
switch ((unsigned char)eState)
{
case STATE_SAFE_OFF:
printf("[STATE] SAFE OFF detected. Servo on is requested from the main loop.\n");
g_bNeedServoOn = true;
break;
case STATE_STANDBY:
printf("[STATE] Robot is now standby and ready.\n");
break;
case STATE_MOVING:
printf("[STATE] Robot is executing motion.\n");
break;
case STATE_SAFE_STOP:
printf("[STATE] Robot is in safe stop.\n");
break;
default:
printf("[STATE] Unknown or transitional state: %d\n", eState);
break;
}
}
int main()
{
CDRFLEx drfl;
// Connect to the robot controller
drfl.open_connection("192.168.137.100");
// Register callback for robot state monitoring
drfl.set_on_monitoring_state(OnMonitoringStateCB);
// Keep program alive to observe state transitions
while (true)
{
// Call set_robot_control outside the callback
if (g_bNeedServoOn)
{
g_bNeedServoOn = false;
drfl.set_robot_control(CONTROL_SERVO_ON);
}
std::this_thread::sleep_for(std::chrono::seconds(1));
}
drfl.close_connection();
return 0;
}
Note
This callback is automatically invoked by the controller whenever a robot state transition occurs.
Typical usage includes servo enabling after STATE_SAFE_OFF, logging state changes, or updating GUI indicators.
Call set_robot_control outside the callback.