Tutorial 4: Reading Status and Error Handling

This part covers the following.

  1. Updating the status of the WMX3 Robot module

  2. Processing status information received from the WMX3 Robot module

1. Sample Code

The following is sample code for acquiring system status information and handling errors using the WMX3 Robot class. After initializing the control target, it repeats the acquisition of status information and error handling 10 times.

The sample code ‘InitWMX, InitRobotSystem’ was explained in the previous chapter, and the sample code ‘PrintRobotStatus and PrintError’ will be explained separately in this chapter.

main

int main(int argc, const char* argv[])
{
    int ret = 0;
    wmx3Api::WMX3Api dev;
    wmx3Api::RobotMotion robot(&dev);
    wmx3Api::RobotMotionParam robotMotionParam;
    wmx3Api::RobotStatus robotStatus;
    int errorBit;   // Bit flag about error
    int errorCode[wmx3Api::RobotStatus::ErrorBit::ERROR_BIT_SIZE];  // Array of error codes.

    // Initialization
    ret = InitWMX(dev);
    ret = InitRobotSystem(robot, robotMotionParam);

    // Update the Robot Status
    for (int idx = 0; idx < 10; idx++) {
        // Update RobotStatus. 
        errorBit = robot.UpdateRobotStatus(robotMotionParam.robotParam.robotId, robotStatus, errorCode);

        // Print robot status. 
        PrintRobotStatus(robotStatus);

        // Print Error information.
        if (errorBit != 0) {
            PrintError(errorBit, errorCode, robotStatus);
        }

        Sleep(100);
    }

    return ret;
}

  • To update the robot’s status, you must call the UpdateRobotStatus function of the wmx3Api::RobotMotion class.

  • The error determination of the return value of UpdateRobotStatus (in the errorBit of the code above) is determined by bit. The type of error indicated by each errorBit can be found in RobotStatus::ErrorBit(enum) in RobotMotionApi.h.

  • You can use an int array of size ERROR_BIT_SIZE as an argument to UpdateRobotStatus, and the error code corresponding to each bit of errorBit is stored in the array.

    • ex) If errorBit == 0b00000101, you can see that an error occurred in bits 0 and 2. Therefore, you can check the error code in elements 0 and 2 of errorCode.

  • If an error occurs (erorrBit != 0), call the PrintRobotError function to output the error information.

PrintRobotStatus

This is a function that outputs the robot’s status information (robotStatus). In the example, the coordinates of the robot’s end effector (tool) are output.

int PrintRobotStatus(const wmx3Api::RobotStatus& robotStatus)
{
    // TODO: 
    // Enter code to print status(by User)
    // User can find out 'enum type information' by converting robotStatus.motionState, robotStatus.motionErrorCode.
    robotStatus.motionState;
    robotStatus.motionErrorInfo;
    robotStatus.stateCommand;
    robotStatus.stateFeedback;

    printf("Id[%d]\tPose[%f\t%f\t%f]\n",
        robotStatus.stateCommand.robotId,
        robotStatus.stateCommand.toolPose.point.x,
        robotStatus.stateCommand.toolPose.point.y,
        robotStatus.stateCommand.toolPose.point.z);

    return 0;
}

PrintRobotError

Outputs error information corresponding to errorBit (error type) and errorCode (error code).

int PrintError(const int errorBit, int(&errorCode)[wmx3Api::RobotStatus::ErrorBit::ERROR_BIT_SIZE], const wmx3Api::RobotStatus& robotStatus)
{
    // Check if there are something error while update status.
    for (int idx = 0; idx < (wmx3Api::RobotStatus::ErrorBit::ERROR_BIT_SIZE); idx++) {
        if ((errorBit >> idx) & 0x01) {
            printf("WMX3 function error %d\n", errorCode[idx]);
        }
    }

    // If there is 'Motion Error', print error code with joint number.
    if ((errorBit >> wmx3Api::RobotStatus::ErrorBit::ERROR_BIT_MOTION_ERROR) & 0x01) {
        printf("[%d]Joint, Error : %d\n", robotStatus.motionErrorInfo.errorJoint, robotStatus.motionErrorInfo.errorCode);
    }

    return 0;
}

  • Outputs error information corresponding to errorBit (error type) and errorCode (error code).

  • It iterates through the errorCode corresponding to each errorBit and calls the PrintErrorStr function to output the error information.

  • If the bit of ERROR_BIT_MOTION_ERROR is raised, it indicates that an error has occurred in the Motion.

    • Additional information about the error in Motion can be found in robotStatus.motionErrorInfo.

    • motionErrorInfo.errorJoint indicates the number of the Joint where the problem occurred.

    • motionErrorInfo.errorCode indicates the error code for the Motion. You can check it in wmx3Api::kinematics::constants::MotionErrorCode.

2. Program Execution Result

../_images/ROBOT_OPTION_DOC_TUTORIAL_UDATE_ROBOT_STATUS_01_CONSOL_RESULT.png

  • The test is performed 10 times.