.. _set_on_mastering_need: set_on_mastering_need ------------------------------------------ This function registers a callback function that automatically checks whether the robot’s axes have been twisted by an external force. Use it to run your own code automatically when this event occurs. **Definition** |br| ``DRFLEx.h`` within class `CDRFLEx`, public section .. code-block:: cpp void set_on_mastering_need(TOnMasteringNeedCB pCallbackFunc) { _set_on_mastering_need(_rbtCtrl, pCallbackFunc); }; **Parameter** .. list-table:: :widths: 20 20 20 40 :header-rows: 1 * - **Parameter Name** - **Data Type** - **Default Value** - **Description** * - pCallbackFunc - :ref:`TOnMasteringNeedCB ` - - - Refer to definition of callback function **Return** |br| None **Example** .. code-block:: cpp std::atomic g_bNeedHoming(false); void OnMasteringNeedCB() { // Request homing from the main loop g_bNeedHoming = true; } drfl.set_on_mastering_need(OnMasteringNeedCB); // Main loop: call move_home outside the callback while (true) { if (g_bNeedHoming) { g_bNeedHoming = false; // Starts the homing mode for the alignment of the robot’s axes drfl.move_home(MOVE_HOME_MECHANIC, 1); } std::this_thread::sleep_for(std::chrono::milliseconds(100)); } When registered, this callback is executed automatically if the controller detects **axis misalignment caused by external force**. The callback sets a flag, and the main loop then starts the **homing procedure** to realign all robot joints, ensuring proper position calibration before resuming normal operation. Call move_home outside the callback; see :ref:`Rules for callback functions `.