diff --git a/doc/troubleshooting.md b/doc/troubleshooting.md index cec68130..eb9e1c4d 100644 --- a/doc/troubleshooting.md +++ b/doc/troubleshooting.md @@ -613,7 +613,7 @@ ALARM 8011 [xx] ``` -Where `[xx]` is a subcode in the ranges `[23 - 54]` or `[56 - 58]`. +Where `[xx]` is a subcode in the ranges `[23 - 54]`, `[56 - 58]`, or `[64]`. *Solution:* These alarms are often caused by version incompatibilities between ROS 2 (on the client PC), micro-ROS (as part of MotoROS2) and/or the micro-ROS Agent. diff --git a/src/CommunicationExecutor.c b/src/CommunicationExecutor.c index 60f21285..0d9b56d8 100644 --- a/src/CommunicationExecutor.c +++ b/src/CommunicationExecutor.c @@ -143,7 +143,6 @@ void Ros_Communication_Initialize() motoRosAssert(ret == RCL_RET_OK, SUBCODE_FAIL_SUPPORT_INIT); rcl_node_options_t node_options = rcl_node_get_default_options(); -#ifndef MOTOPLUS_LIBMICROROS_ROS2_IS_IRON //construct a faux command line to pass to rcl_parse_arguments(..) char* faux_argv[MAX_REMAP_RULE_NUM]; size_t faux_argc = 0; @@ -172,7 +171,6 @@ void Ros_Communication_Initialize() node_options = rcl_node_get_default_options(); } } -#endif //init node with the remap rules and other options from the config file ret = rclc_node_init_with_options( @@ -182,11 +180,13 @@ void Ros_Communication_Initialize() Ros_Debug_BroadcastMsg("rclc_node_init_with_options = %d", (int)ret); motoRosAssert(ret == RCL_RET_OK, SUBCODE_FAIL_NODE_INIT); +#ifdef MOTOPLUS_LIBMICROROS_ROS2_IS_IRON + ret = rcl_node_type_cache_init(&g_microRosNodeInfo.node); + motoRosAssert(ret == RCL_RET_OK, SUBCODE_FAIL_NODE_TYPE_CACHE_INIT); +#endif // MOTOPLUS_LIBMICROROS_ROS2_IS_IRON //we're done with it ret = rcl_node_options_fini(&node_options); RCL_UNUSED(ret); -#ifndef MOTOPLUS_LIBMICROROS_ROS2_IS_IRON Ros_CleanupFauxArgv(faux_argv, faux_argc); -#endif MOTOROS2_MEM_TRACE_REPORT(comm_exec_init); } @@ -196,6 +196,12 @@ void Ros_Communication_Cleanup() MOTOROS2_MEM_TRACE_START(comm_exec_fini); rcl_ret_t ret; +#ifdef MOTOPLUS_LIBMICROROS_ROS2_IS_IRON + ret = rcl_node_type_cache_fini(&g_microRosNodeInfo.node); + if (ret != RCL_RET_OK) + Ros_Debug_BroadcastMsg("Failed cleaning up node type cache: %d", ret); +#endif + Ros_Debug_BroadcastMsg("Cleanup node"); ret = rcl_node_fini(&g_microRosNodeInfo.node); if (ret != RCL_RET_OK) diff --git a/src/ErrorHandling.h b/src/ErrorHandling.h index b1ae1325..98362d26 100644 --- a/src/ErrorHandling.h +++ b/src/ErrorHandling.h @@ -169,7 +169,7 @@ typedef enum SUBCODE_CONFIGURATION_FAIL_MP_NICDATA1, SUBCODE_FAIL_MP_NICDATA_INIT1, SUBCODE_FAIL_INVALID_BASE_TRACK_MOTION_TYPE, - + SUBCODE_FAIL_NODE_TYPE_CACHE_INIT, } ALARM_ASSERTION_FAIL_SUBCODE; //8011 typedef enum diff --git a/src/FauxCommandLineArgs.c b/src/FauxCommandLineArgs.c index 12bc470b..95b7f1cf 100644 --- a/src/FauxCommandLineArgs.c +++ b/src/FauxCommandLineArgs.c @@ -9,8 +9,6 @@ #include #include -#ifndef MOTOPLUS_LIBMICROROS_ROS2_IS_IRON - //TODO: Once https://github.com/ros2/rcl/issues/998 is addressed, this would no longer // be necessary. We could construct rcl_remap_t instances directly without having // to construct a fake argv and go through rcl_parse_arguments(..). @@ -109,4 +107,3 @@ void Ros_CleanupFauxArgv(char** arr, size_t arr_len) } } -#endif // MOTOPLUS_LIBMICROROS_ROS2_IS_IRON diff --git a/src/MotoROS.h b/src/MotoROS.h index 3f2f5a88..d3052e6b 100644 --- a/src/MotoROS.h +++ b/src/MotoROS.h @@ -23,7 +23,10 @@ #include #include #include - +#ifdef MOTOPLUS_LIBMICROROS_ROS2_IS_IRON +#include +#include +#endif //MOTOPLUS_LIBMICROROS_ROS2_IS_IRON #include #include #include diff --git a/src/MotoROS2_AllControllers.vcxproj b/src/MotoROS2_AllControllers.vcxproj index 63b9e60c..2dfd5a49 100644 --- a/src/MotoROS2_AllControllers.vcxproj +++ b/src/MotoROS2_AllControllers.vcxproj @@ -168,7 +168,7 @@ $(SolutionDir)bin\$(Configuration)\ - $(ProjectDir)..\libmicroros_dx200_iron\include; + $(ProjectDir)..\lib;$(ProjectDir)..\libmicroros_dx200_iron\include; "$(MP_VS_Install)mpBuilder.exe" -c $(Configuration) -p "$(ProjectDir)\" -n "mr2_dx2_h" -b "$(SolutionDir)bin\$(Configuration)" -o build -i "$(MP_VS_Install)DX200\inc" @@ -216,7 +216,7 @@ $(SolutionDir)bin\$(Configuration)\ - $(ProjectDir)..\libmicroros_yrc1000_iron\include; + $(ProjectDir)..\lib;$(ProjectDir)..\libmicroros_yrc1000_iron\include; "$(MP_VS_Install)mpBuilder.exe" -c $(Configuration) -p "$(ProjectDir)\" -n "mr2_yrc1_h" -b "$(SolutionDir)bin\$(Configuration)" -o build -i "$(MP_VS_Install)YRC1000\inc" @@ -264,7 +264,7 @@ $(SolutionDir)bin\$(Configuration)\ - $(ProjectDir)..\libmicroros_yrc1000u_iron\include; + $(ProjectDir)..\lib;$(ProjectDir)..\libmicroros_yrc1000u_iron\include; "$(MP_VS_Install)mpBuilder.exe" -c $(Configuration) -p "$(ProjectDir)\" -n "mr2_yrc1m_h" -b "$(SolutionDir)bin\$(Configuration)" -o build -i "$(MP_VS_Install)YRC1000u\inc" @@ -404,18 +404,24 @@ + + + + + + @@ -433,6 +439,7 @@ + @@ -467,6 +474,7 @@ + diff --git a/src/MotoROS2_AllControllers.vcxproj.filters b/src/MotoROS2_AllControllers.vcxproj.filters index 6b585860..5251a5c8 100644 --- a/src/MotoROS2_AllControllers.vcxproj.filters +++ b/src/MotoROS2_AllControllers.vcxproj.filters @@ -247,6 +247,27 @@ Compile Settings + + + + + Compile Settings + + + Compile Settings + + + Compile Settings + + + Compile Settings + + + Compile Settings + + + Compile Settings + @@ -333,6 +354,12 @@ Source Files\Utilities + + Source Files + + + Source Files + @@ -425,9 +452,6 @@ Header Files\Utilities - - Header Files\Robot Controller - Header Files\Robot Controller @@ -443,5 +467,14 @@ Header Files\Robot Controller + + Header Files + + + Header Files + + + Header Files\Utilities + - + \ No newline at end of file diff --git a/src/StringConversionUtilities.c b/src/StringConversionUtilities.c new file mode 100644 index 00000000..37fbcf96 --- /dev/null +++ b/src/StringConversionUtilities.c @@ -0,0 +1,79 @@ +#include "MotoROS.h" + +//Implementation taken from https://github.com/gcc-mirror/gcc/blob/master/libiberty/strtoll.c +INT64 strtoll(const char* nptr, char** endptr, int base) +{ + const char* s = nptr; + UINT64 acc; + int c; + UINT64 cutoff; + int neg = 0, any, cutlim; + /* + * Skip white space and pick up leading +/- sign if any. + * If base is 0, allow 0x for hex and 0 for octal, else + * assume decimal; if base is already 16, allow 0x. + */ + do { + c = *s++; + } while (isspace(c)); + if (c == '-') { + neg = 1; + c = *s++; + } + else if (c == '+') + c = *s++; + if ((base == 0 || base == 16) && + c == '0' && (*s == 'x' || *s == 'X')) { + c = s[1]; + s += 2; + base = 16; + } + if (base == 0) + base = c == '0' ? 8 : 10; + /* + * Compute the cutoff value between legal numbers and illegal + * numbers. That is the largest legal value, divided by the + * base. An input number that is greater than this value, if + * followed by a legal input character, is too big. One that + * is equal to this value may be valid or not; the limit + * between valid and invalid numbers is then based on the last + * digit. For instance, if the range for longs is + * [-2147483648..2147483647] and the input base is 10, + * cutoff will be set to 214748364 and cutlim to either + * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated + * a value > 214748364, or equal but the next digit is > 7 (or 8), + * the number is too big, and we will return a range error. + * + * Set any if any `digits' consumed; make it negative to indicate + * overflow. + */ + cutoff = neg ? -(UINT64) 0: ULONG_LONG_MAX; + cutlim = cutoff % (UINT64)base; + cutoff /= (UINT64)base; + for (acc = 0, any = 0;; c = *s++) { + if (isdigit(c)) + c -= '0'; + else if (isalpha(c)) + c -= isupper(c) ? 'A' - 10 : 'a' - 10; + else + break; + if (c >= base) + break; + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + any = -1; + else { + any = 1; + acc *= base; + acc += c; + } + } + if (any < 0) { + acc = neg ? LONG_LONG_MIN : LONG_LONG_MAX; + errno = ERANGE; + } + else if (neg) + acc = -acc; + if (endptr != 0) + *endptr = (char*)(any ? s - 1 : nptr); + return (acc); +} diff --git a/src/StringConversionUtils.h b/src/StringConversionUtils.h new file mode 100644 index 00000000..f9694a3a --- /dev/null +++ b/src/StringConversionUtils.h @@ -0,0 +1,7 @@ +#ifndef MOTOROS2_STRING_CONVERSION_UTILS_H +#define MOTOROS2_STRING_CONVERSION_UTILS_H + +#include "MotoROS.h" + +INT64 strtoll(const char* s, char** endptr, int base); +#endif // MOTOROS2_STRING_CONVERSION_UTILS_H