From 6ea20f7faedb3f6a5ac3ecf8ab7b8f0f20cb4237 Mon Sep 17 00:00:00 2001 From: Sean Yen Date: Thu, 31 Jan 2019 12:07:31 -0800 Subject: [PATCH 1/2] AMCL windows build bring up. * Add HAVE_UNISTD and HAVE_DRAND48 and portable_utils.hpp for better cross compiling. * Variable length array is not supported in MSVC, conditionally disable it. * Fix install location for shared lib and executables on Windows. * Use isfinite for better cross compiling. --- amcl/CMakeLists.txt | 22 ++++++++++++++++++---- amcl/src/amcl/pf/eig3.c | 5 ++++- amcl/src/amcl/pf/pf.c | 4 ++-- amcl/src/amcl/pf/pf_pdf.c | 1 + amcl/src/amcl/pf/pf_vector.c | 4 ++-- amcl/src/amcl/sensors/amcl_laser.cpp | 2 ++ amcl/src/amcl_node.cpp | 1 + amcl/src/include/portable_utils.hpp | 28 ++++++++++++++++++++++++++++ 8 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 amcl/src/include/portable_utils.hpp diff --git a/amcl/CMakeLists.txt b/amcl/CMakeLists.txt index 75ac9b56e8..cf6e23f95a 100644 --- a/amcl/CMakeLists.txt +++ b/amcl/CMakeLists.txt @@ -48,6 +48,17 @@ catkin_package( include_directories(include) include_directories(${catkin_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}) +include_directories(src/include) + +check_include_file(unistd.h HAVE_UNISTD_H) +if (HAVE_UNISTD_H) + add_definitions(-DHAVE_UNISTD_H) +endif (HAVE_UNISTD_H) + +check_symbol_exists(drand48 stdlib.h HAVE_DRAND48) +if (HAVE_DRAND48) + add_definitions(-DHAVE_DRAND48) +endif (HAVE_DRAND48) add_library(amcl_pf src/amcl/pf/pf.c @@ -82,10 +93,13 @@ target_link_libraries(amcl ) install( TARGETS - amcl amcl_sensors amcl_map amcl_pf - ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} - LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} - RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} + amcl + DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} +) + +install( TARGETS + amcl_sensors amcl_map amcl_pf + DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} ) install(DIRECTORY include/amcl/ diff --git a/amcl/src/amcl/pf/eig3.c b/amcl/src/amcl/pf/eig3.c index ac74e52d3a..3e8aee68db 100644 --- a/amcl/src/amcl/pf/eig3.c +++ b/amcl/src/amcl/pf/eig3.c @@ -8,8 +8,11 @@ #define MAX(a, b) ((a)>(b)?(a):(b)) #endif -//#define n 3 +#ifdef _MSC_VER +#define n 3 +#else static int n = 3; +#endif static double hypot2(double x, double y) { return sqrt(x*x+y*y); diff --git a/amcl/src/amcl/pf/pf.c b/amcl/src/amcl/pf/pf.c index 8855b314ba..ad59fff2b4 100644 --- a/amcl/src/amcl/pf/pf.c +++ b/amcl/src/amcl/pf/pf.c @@ -33,6 +33,7 @@ #include "amcl/pf/pf.h" #include "amcl/pf/pf_pdf.h" #include "amcl/pf/pf_kdtree.h" +#include "portable_utils.hpp" // Compute the required number of samples, given that there are k bins @@ -52,7 +53,7 @@ pf_t *pf_alloc(int min_samples, int max_samples, pf_sample_t *sample; srand48(time(NULL)); - + pf = calloc(1, sizeof(pf_t)); pf->random_pose_fn = random_pose_fn; @@ -216,7 +217,6 @@ int pf_update_converged(pf_t *pf) int i; pf_sample_set_t *set; pf_sample_t *sample; - double total; set = pf->sets + pf->current_set; double mean_x = 0, mean_y = 0; diff --git a/amcl/src/amcl/pf/pf_pdf.c b/amcl/src/amcl/pf/pf_pdf.c index 436a66c0f7..06310a5992 100644 --- a/amcl/src/amcl/pf/pf_pdf.c +++ b/amcl/src/amcl/pf/pf_pdf.c @@ -33,6 +33,7 @@ //#include #include "amcl/pf/pf_pdf.h" +#include "portable_utils.hpp" // Random number generator seed value static unsigned int pf_pdf_seed; diff --git a/amcl/src/amcl/pf/pf_vector.c b/amcl/src/amcl/pf/pf_vector.c index 80c6fb8fc2..23d7ccb16c 100644 --- a/amcl/src/amcl/pf/pf_vector.c +++ b/amcl/src/amcl/pf/pf_vector.c @@ -53,7 +53,7 @@ int pf_vector_finite(pf_vector_t a) int i; for (i = 0; i < 3; i++) - if (!finite(a.v[i])) + if (!isfinite(a.v[i])) return 0; return 1; @@ -151,7 +151,7 @@ int pf_matrix_finite(pf_matrix_t a) for (i = 0; i < 3; i++) for (j = 0; j < 3; j++) - if (!finite(a.m[i][j])) + if (!isfinite(a.m[i][j])) return 0; return 1; diff --git a/amcl/src/amcl/sensors/amcl_laser.cpp b/amcl/src/amcl/sensors/amcl_laser.cpp index fe5ad521dd..4563a9c57d 100644 --- a/amcl/src/amcl/sensors/amcl_laser.cpp +++ b/amcl/src/amcl/sensors/amcl_laser.cpp @@ -31,7 +31,9 @@ #include #include #include +#ifdef HAVE_UNISTD_H #include +#endif #include "amcl/sensors/amcl_laser.h" diff --git a/amcl/src/amcl_node.cpp b/amcl/src/amcl_node.cpp index 8cae28929d..c0d85d8ffd 100644 --- a/amcl/src/amcl_node.cpp +++ b/amcl/src/amcl_node.cpp @@ -36,6 +36,7 @@ #include "amcl/pf/pf.h" #include "amcl/sensors/amcl_odom.h" #include "amcl/sensors/amcl_laser.h" +#include "portable_utils.hpp" #include "ros/assert.h" diff --git a/amcl/src/include/portable_utils.hpp b/amcl/src/include/portable_utils.hpp new file mode 100644 index 0000000000..f7eca028a6 --- /dev/null +++ b/amcl/src/include/portable_utils.hpp @@ -0,0 +1,28 @@ +#ifndef PORTABLE_UTILS_H +#define PORTABLE_UTILS_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef HAVE_DRAND48 +// Some system (e.g., Windows) doesn't come with drand48(), srand48(). +// Use rand, and srand to replace it on Windows. +static double drand48(void) +{ + return ((double)rand())/RAND_MAX; +} + +static void srand48(long int seedval) +{ + srand(seedval); +} +#endif + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file From 54e770f681ae392a2c5fc5ed2af56ad6ee1f694b Mon Sep 17 00:00:00 2001 From: Sean Yen Date: Thu, 31 Jan 2019 12:16:35 -0800 Subject: [PATCH 2/2] revert unrelated changes. --- amcl/src/amcl/pf/pf.c | 3 ++- amcl/src/include/portable_utils.hpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/amcl/src/amcl/pf/pf.c b/amcl/src/amcl/pf/pf.c index ad59fff2b4..f02e0ad9b8 100644 --- a/amcl/src/amcl/pf/pf.c +++ b/amcl/src/amcl/pf/pf.c @@ -53,7 +53,7 @@ pf_t *pf_alloc(int min_samples, int max_samples, pf_sample_t *sample; srand48(time(NULL)); - + pf = calloc(1, sizeof(pf_t)); pf->random_pose_fn = random_pose_fn; @@ -217,6 +217,7 @@ int pf_update_converged(pf_t *pf) int i; pf_sample_set_t *set; pf_sample_t *sample; + double total; set = pf->sets + pf->current_set; double mean_x = 0, mean_y = 0; diff --git a/amcl/src/include/portable_utils.hpp b/amcl/src/include/portable_utils.hpp index f7eca028a6..8570393301 100644 --- a/amcl/src/include/portable_utils.hpp +++ b/amcl/src/include/portable_utils.hpp @@ -9,7 +9,7 @@ extern "C" { #ifndef HAVE_DRAND48 // Some system (e.g., Windows) doesn't come with drand48(), srand48(). -// Use rand, and srand to replace it on Windows. +// Use rand, and srand for such system. static double drand48(void) { return ((double)rand())/RAND_MAX;