[EthercatDevice_DmpStepper_Generic]
Description
Register the event callback function for the EtherCAT slave device. Since this callback function is called within update()
, it is prohibited to call blocking functions and system call-related functions within this callback function if update()
is called in an interrupt callback function (such as Cyclic Callback, Error Callback, or Event Callback).
Derived Class:
Class Name | Vendor ID | Product Code |
EthercatDevice_QECR11MP3S | 0x00000bc3 | 0x0086d0d6 |
EthercatDevice_QECR00MP3S | 0x00000bc3 | 0x0086d0d9 |
Syntax
int attachInterrupt(void (*callback)(int));
Parameters
[in] void (*callback)(int)
The event callback function to be registered has an integer-type parameter that indicates the event type. The supported event types are as follows:
Definition | Code | Description |
ECAT_EMERGENCY_STOPPED | 1 | Emergency stop occurred. |
ECAT_MACHINE_X_AXIS_LIMIT_TOUCHED | 2 | The X-axis limit switch has been touched. |
ECAT_MACHINE_Y_AXIS_LIMIT_TOUCHED | 3 | The Y-axis limit switch has been touched. |
ECAT_MACHINE_Z_AXIS_LIMIT_TOUCHED | 4 | The Z-axis limit switch has been touched. |
The remaining event types are determined using the following macros. Since the status of the following events are stored in the process data and this data is not latched, it is recommended to call update()
in the cyclic callback to handle these events and prevent event loss.
Definition | Description |
IS_ECAT_ENCODER_1_INDEX_RESET(event) | The Index Reset event of Encoder 1 has been triggered. |
IS_ECAT_ENCODER_2_INDEX_RESET(event) | The Index Reset event of Encoder 2 has been triggered. |
IS_ECAT_ENCODER_3_INDEX_RESET(event) | The Index Reset event of Encoder 3 has been triggered. |
IS_ECAT_ENCODER_X_INDEX_RESET(event) | The Index Reset event of Encoder X has been triggered. |
IS_ECAT_ENCODER_Y_INDEX_RESET(event) | The Index Reset event of Encoder Y has been triggered. |
IS_ECAT_ENCODER_Z_INDEX_RESET(event) | The Index Reset event of Encoder Z has been triggered. |
IS_ECAT_ENCODER_1_OVERFLOW(event) | The Overflow event of Encoder 1 has been triggered. |
IS_ECAT_ENCODER_2_OVERFLOW(event) | The Overflow event of Encoder 2 has been triggered. |
IS_ECAT_ENCODER_3_OVERFLOW(event) | The Overflow event of Encoder 3 has been triggered. |
IS_ECAT_ENCODER_X_OVERFLOW(event) | The Overflow event of Encoder X has been triggered. |
IS_ECAT_ENCODER_Y_OVERFLOW(event) | The Overflow event of Encoder Y has been triggered. |
IS_ECAT_ENCODER_Z_OVERFLOW(event) | The Overflow event of Encoder Z has been triggered. |
IS_ECAT_ENCODER_1_UNDERFLOW(event) | The Underflow event of Encoder 1 has been triggered. |
IS_ECAT_ENCODER_2_UNDERFLOW(event) | The Underflow event of Encoder 2 has been triggered. |
IS_ECAT_ENCODER_3_UNDERFLOW(event) | The Underflow event of Encoder 3 has been triggered. |
IS_ECAT_ENCODER_X_UNDERFLOW(event) | The Underflow event of Encoder X has been triggered. |
IS_ECAT_ENCODER_Y_UNDERFLOW(event) | The Underflow event of Encoder Y has been triggered. |
IS_ECAT_ENCODER_Z_UNDERFLOW(event) | The Underflow event of Encoder Z has been triggered. |
Return Value
Return an error code. If the returned value is zero, it indicates a successful execution of this function.
Comment
This function must be called after a successful execution of EthercatMaster::begin()
. This function is blocking and cannot be called within the Cyclic Callback.
Example
#include "Ethercat.h" EthercatMaster master; EthercatDevice_QECR11MP3S slave; int emergency_stopped; int x_limit_touched; int y_limit_touched; int z_limit_touched; int encoder_index_reset[3]; int encoder_overflow[3]; int encoder_underflow[3]; int encoder_xyz_index_reset[3]; int encoder_xyz_overflow[3]; int encoder_xyz_underflow[3]; void Callback(int event) { switch (event) { case ECAT_EMERGENCY_STOPPED: emergency_stopped = 1; return; case ECAT_MACHINE_X_AXIS_LIMIT_TOUCHED: x_limit_touched = 1; return; case ECAT_MACHINE_Y_AXIS_LIMIT_TOUCHED: y_limit_touched = 1; return; case ECAT_MACHINE_Z_AXIS_LIMIT_TOUCHED: z_limit_touched = 1; return; default: break; } if (IS_ECAT_ENCODER_1_INDEX_RESET(event)) encoder_index_reset[0] = 1; else if (IS_ECAT_ENCODER_2_INDEX_RESET(event)) encoder_index_reset[1] = 1; else if (IS_ECAT_ENCODER_3_INDEX_RESET(event)) encoder_index_reset[2] = 1; else if (IS_ECAT_ENCODER_1_OVERFLOW(event)) encoder_overflow[0] = 1; else if (IS_ECAT_ENCODER_2_OVERFLOW(event)) encoder_overflow[1] = 1; else if (IS_ECAT_ENCODER_3_OVERFLOW(event)) encoder_overflow[2] = 1; else if (IS_ECAT_ENCODER_1_UNDERFLOW(event)) encoder_underflow[0] = 1; else if (IS_ECAT_ENCODER_2_UNDERFLOW(event)) encoder_underflow[1] = 1; else if (IS_ECAT_ENCODER_3_UNDERFLOW(event)) encoder_underflow[2] = 1; if (IS_ECAT_ENCODER_X_INDEX_RESET(event)) encoder_xyz_index_reset[0] = 1; else if (IS_ECAT_ENCODER_Y_INDEX_RESET(event)) encoder_xyz_index_reset[1] = 1; else if (IS_ECAT_ENCODER_Z_INDEX_RESET(event)) encoder_xyz_index_reset[2] = 1; else if (IS_ECAT_ENCODER_X_OVERFLOW(event)) encoder_xyz_overflow[0] = 1; else if (IS_ECAT_ENCODER_Y_OVERFLOW(event)) encoder_xyz_overflow[1] = 1; else if (IS_ECAT_ENCODER_Z_OVERFLOW(event)) encoder_xyz_overflow[2] = 1; else if (IS_ECAT_ENCODER_X_UNDERFLOW(event)) encoder_xyz_underflow[0] = 1; else if (IS_ECAT_ENCODER_Y_UNDERFLOW(event)) encoder_xyz_underflow[1] = 1; else if (IS_ECAT_ENCODER_Z_UNDERFLOW(event)) encoder_xyz_underflow[2] = 1; } void CyclicCallback() { slave.update(); } void setup() { Serial.begin(115200); master.begin(); slave.attach(0, master); slave.attachInterrupt(Callback); master.attachCyclicCallback(CyclicCallback); master.start(); } void loop() { if (emergency_stopped) { emergency_stopped = 0; Serial.println("ECAT_EMERGENCY_STOPPED"); } if (x_limit_touched) { x_limit_touched = 0; Serial.println("ECAT_MACHINE_X_AXIS_LIMIT_TOUCHED"); } if (y_limit_touched) { y_limit_touched = 0; Serial.println("ECAT_MACHINE_Y_AXIS_LIMIT_TOUCHED"); } if (z_limit_touched) { z_limit_touched = 0; Serial.println("ECAT_MACHINE_Z_AXIS_LIMIT_TOUCHED"); } if (encoder_index_reset[0]) { encoder_index_reset[0] = 0; Serial.println("IS_ECAT_ENCODER_1_INDEX_RESET"); } if (encoder_index_reset[1]) { encoder_index_reset[1] = 0; Serial.println("IS_ECAT_ENCODER_2_INDEX_RESET"); } if (encoder_index_reset[2]) { encoder_index_reset[2] = 0; Serial.println("IS_ECAT_ENCODER_3_INDEX_RESET"); } if (encoder_overflow[0]) { encoder_overflow[0] = 0; Serial.println("IS_ECAT_ENCODER_1_OVERFLOW"); } if (encoder_overflow[1]) { encoder_overflow[1] = 0; Serial.println("IS_ECAT_ENCODER_2_OVERFLOW"); } if (encoder_overflow[2]) { encoder_overflow[2] = 0; Serial.println("IS_ECAT_ENCODER_3_OVERFLOW"); } if (encoder_underflow[0]) { encoder_underflow[0] = 0; Serial.println("IS_ECAT_ENCODER_1_UNDERFLOW"); } if (encoder_underflow[1]) { encoder_underflow[1] = 0; Serial.println("IS_ECAT_ENCODER_2_UNDERFLOW"); } if (encoder_underflow[2]) { encoder_underflow[2] = 0; Serial.println("IS_ECAT_ENCODER_3_UNDERFLOW"); } if (encoder_xyz_index_reset[0]) { encoder_xyz_index_reset[0] = 0; Serial.println("IS_ECAT_ENCODER_X_INDEX_RESET"); } if (encoder_xyz_index_reset[1]) { encoder_xyz_index_reset[1] = 0; Serial.println("IS_ECAT_ENCODER_Y_INDEX_RESET"); } if (encoder_xyz_index_reset[2]) { encoder_xyz_index_reset[2] = 0; Serial.println("IS_ECAT_ENCODER_Z_INDEX_RESET"); } if (encoder_xyz_overflow[0]) { encoder_xyz_overflow[0] = 0; Serial.println("IS_ECAT_ENCODER_X_OVERFLOW"); } if (encoder_xyz_overflow[1]) { encoder_xyz_overflow[1] = 0; Serial.println("IS_ECAT_ENCODER_Y_OVERFLOW"); } if (encoder_xyz_overflow[2]) { encoder_xyz_overflow[2] = 0; Serial.println("IS_ECAT_ENCODER_Z_OVERFLOW"); } if (encoder_xyz_underflow[0]) { encoder_xyz_underflow[0] = 0; Serial.println("IS_ECAT_ENCODER_X_UNDERFLOW"); } if (encoder_xyz_underflow[1]) { encoder_xyz_underflow[1] = 0; Serial.println("IS_ECAT_ENCODER_Y_UNDERFLOW"); } if (encoder_xyz_underflow[2]) { encoder_xyz_underflow[2] = 0; Serial.println("IS_ECAT_ENCODER_Z_UNDERFLOW"); } // ... }
Please see EthercatDevice_DmpStepper_Generic Class for more QEC Stepper Drivers instructions and API usage.