.. _cb_tonmonitoringstatecb: TOnMonitoringStateCB ------------------------------------------ This callback function is used to check changes in the operation state of the robot controller. See :ref:`Rules for callback functions `. **Defined in:** ``DRFLEx.h`` .. code-block:: cpp typedef void (*TOnMonitoringStateCB)(const ROBOT_STATE); void set_on_monitoring_state(TOnMonitoringStateCB pCallbackFunc) { _set_on_monitoring_state(_rbtCtrl, pCallbackFunc); }; **Parameter** .. list-table:: :header-rows: 1 :widths: 20 25 15 40 * - Parameter Name - Data Type - Default Value - Description * - eState - :ref:`ROBOT_STATE ` - - - Refer to the Definition of Enumeration Type. **Return** |br| None **Example** .. code-block:: cpp #include "DRFLEx.h" #include #include #include #include using namespace DRAFramework; std::atomic 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.