Skip to content

Commit

Permalink
Merge pull request #106 from aigallegos/fix-cryptic-err-codes
Browse files Browse the repository at this point in the history
Fixed Cryptic Error Codes in mpStartJob
  • Loading branch information
ted-miller authored Aug 3, 2023
2 parents 258372a + ff2e138 commit 5a2c6ee
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
32 changes: 17 additions & 15 deletions src/ErrorHandling.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,26 @@
//-------------------------------------------------------------------
// Convert error code to string
//-------------------------------------------------------------------
void Ros_ErrorHandling_ErrNo_ToString(int errNo, char* const errMsg, int errMsgSize)
const char* const Ros_ErrorHandling_ErrNo_ToString(int errNo)
{
switch (errNo)
{
case 0x2010: strncpy(errMsg, "Robot is in operation", errMsgSize); break;
case 0x2030: strncpy(errMsg, "In HOLD status (PP)", errMsgSize); break;
case 0x2040: strncpy(errMsg, "In HOLD status (External)", errMsgSize); break;
case 0x2050: strncpy(errMsg, "In HOLD status (Command)", errMsgSize); break;
case 0x2060: strncpy(errMsg, "In ERROR/ALARM status", errMsgSize); break;
case 0x2070: strncpy(errMsg, "In SERVO OFF status", errMsgSize); break;
case 0x2080: strncpy(errMsg, "Wrong operation mode", errMsgSize); break;
case 0x3040: strncpy(errMsg, "The home position is not registered", errMsgSize); break;
case 0x3050: strncpy(errMsg, "Out of range (ABSO data)", errMsgSize); break;
case 0x3400: strncpy(errMsg, "Cannot operate MASTER JOB", errMsgSize); break;
case 0x3410: strncpy(errMsg, "The JOB name is already registered in another task", errMsgSize); break;
case 0x4040: strncpy(errMsg, "Specified JOB not found", errMsgSize); break;
case 0x5200: strncpy(errMsg, "Over data range", errMsgSize); break;
default: strncpy(errMsg, "Unspecified reason", errMsgSize); break;
//Note: returning literals here as 'const char*' is OK, as they are stored
//in an anonymous array with static storage.
case 0x2010: return "Robot is in operation";
case 0x2030: return "In HOLD status (PP)";
case 0x2040: return "In HOLD status (External)";
case 0x2050: return "In HOLD status (Command)";
case 0x2060: return "In ERROR/ALARM status";
case 0x2070: return "In SERVO OFF status";
case 0x2080: return "Wrong operation mode";
case 0x3040: return "The home position is not registered";
case 0x3050: return "Out of range (ABSO data)";
case 0x3400: return "Cannot operate MASTER JOB";
case 0x3410: return "The JOB name is already registered in another task";
case 0x4040: return "Specified JOB not found";
case 0x5200: return "Over data range";
default: return "Unspecified reason";
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ErrorHandling.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ typedef enum
extern void motoRosAssert(BOOL mustBeTrue, ASSERTION_SUBCODE subCodeIfFalse);
extern void motoRosAssert_withMsg(BOOL mustBeTrue, ASSERTION_SUBCODE subCodeIfFalse, char* msgFmtIfFalse, ...);

extern void Ros_ErrorHandling_ErrNo_ToString(int errNo, char* const errMsg, int errMsgSize);
extern const char* const Ros_ErrorHandling_ErrNo_ToString(int errNo);
extern const char* const Ros_ErrorHandling_MotionNotReadyCode_ToString(MotionNotReadyCode code);

#endif // MOTOROS2_ERROR_HANDLING_H
7 changes: 5 additions & 2 deletions src/MotionControl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,9 @@ BOOL Ros_MotionControl_StartMotionMode(MOTION_MODE mode)
{
//TODO(gavanderhoorn): should this be reported to user, or are causes
//covered by errors in MotionNotReadyCode?
Ros_Debug_BroadcastMsg("Can't turn on servo because: 0x%04X", rData.err_no);
Ros_Debug_BroadcastMsg(
"Can't turn on servo because: '%s' (0x%04X)",
Ros_ErrorHandling_ErrNo_ToString(rData.err_no), rData.err_no);
goto updateStatus;
}
}
Expand Down Expand Up @@ -1287,7 +1289,8 @@ BOOL Ros_MotionControl_StartMotionMode(MOTION_MODE mode)
{
//TODO(gavanderhoorn): special check for "job is not loaded"
Ros_Debug_BroadcastMsg(
"Can't start '%s' because: 0x%04X", g_nodeConfigSettings.inform_job_name, rData.err_no);
"Can't start '%s' because: '%s' (0x%04X)", g_nodeConfigSettings.inform_job_name,
Ros_ErrorHandling_ErrNo_ToString(rData.err_no), rData.err_no);
goto updateStatus;
}

Expand Down

0 comments on commit 5a2c6ee

Please sign in to comment.