From f2afc7a66b22e5d1abe7a1c7a84fac886ef283b0 Mon Sep 17 00:00:00 2001 From: Alexander Khoury <akhoury727@gmail.com> Date: Sun, 9 Jun 2019 01:03:42 -0700 Subject: [PATCH] cleanup --- .travis.yml | 2 +- CMakeLists.txt | 2 +- bc_exploration/agents/frontier_agent.py | 2 -- bc_exploration/cpp/CMakeLists.txt | 2 +- bc_exploration/cpp/__init__.py | 10 ++++++++ bc_exploration/cpp/src/exploration/python.cpp | 3 ++- bc_exploration/cpp/test_bindings.py | 25 +++++++++++++------ bc_exploration/footprints/collision_cpp.py | 4 +-- bc_exploration/planners/astar_cpp.py | 5 ++-- bc_exploration/planners/test_astar_cpp.py | 12 +++------ pylint_rc | 4 +-- pytest.ini | 4 ++- setup.py | 2 +- 13 files changed, 46 insertions(+), 31 deletions(-) diff --git a/.travis.yml b/.travis.yml index ee78fc3..2dc418b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ python: script: # install the package and test - pip install -e .[tests] - - ./bc_exploration/build.sh +# - ./bc_exploration/build.sh - py.test --pep8 -m pep8 -n8 - py.test -n8 - ./test_pylint \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 754c319..c0a49d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,4 +26,4 @@ set(SOURCE_FILES add_library(exploration_cpp SHARED ${PROJECT_SOURCE_DIR} ${SOURCE_FILES} bc_exploration/cpp/src/exploration/python.cpp) target_link_libraries(exploration_cpp ${PYTHON_LIBRARIES}) -set_target_properties(exploration_cpp PROPERTIES SUFFIX ".so" PREFIX "") +set_target_properties(exploration_cpp PROPERTIES SUFFIX ".so" PREFIX "_") diff --git a/bc_exploration/agents/frontier_agent.py b/bc_exploration/agents/frontier_agent.py index 192ec66..6fcd1c0 100644 --- a/bc_exploration/agents/frontier_agent.py +++ b/bc_exploration/agents/frontier_agent.py @@ -318,7 +318,6 @@ def plan(self, state, occupancy_map, debug=False, is_last_plan=False): start=state, occupancy_map=exploration_map, footprint_masks=self._footprint_masks, - mask_radius=self._footprint_mask_radius, outline_coords=self._footprint_outline_coords, obstacle_values=[Costmap.OCCUPIED, Costmap.UNEXPLORED], planning_scale=planning_scale, @@ -418,7 +417,6 @@ def plan(self, state, occupancy_map, debug=False, is_last_plan=False): start=state, occupancy_map=exploration_map, footprint_masks=self._footprint_masks, - mask_radius=self._footprint_mask_radius, outline_coords=self._footprint_outline_coords, obstacle_values=[Costmap.OCCUPIED, Costmap.UNEXPLORED], planning_scale=planning_scale, diff --git a/bc_exploration/cpp/CMakeLists.txt b/bc_exploration/cpp/CMakeLists.txt index e01cd7e..aa04f1d 100644 --- a/bc_exploration/cpp/CMakeLists.txt +++ b/bc_exploration/cpp/CMakeLists.txt @@ -26,4 +26,4 @@ set(SOURCE_FILES add_library(exploration_cpp SHARED ${PROJECT_SOURCE_DIR} ${SOURCE_FILES} src/exploration/python.cpp) target_link_libraries(exploration_cpp ${PYTHON_LIBRARIES}) -set_target_properties(exploration_cpp PROPERTIES SUFFIX ".so" PREFIX "") +set_target_properties(exploration_cpp PROPERTIES SUFFIX ".so" PREFIX "_") diff --git a/bc_exploration/cpp/__init__.py b/bc_exploration/cpp/__init__.py index e69de29..662a5a6 100644 --- a/bc_exploration/cpp/__init__.py +++ b/bc_exploration/cpp/__init__.py @@ -0,0 +1,10 @@ +"""cpp.__init__.py +definitions for the cpp bindings to be importable under bc_exploration.cpp +""" +from __future__ import print_function, absolute_import, division + +from bc_exploration._exploration_cpp import __doc__ as exploration_cpp_doc +from bc_exploration._exploration_cpp import c_astar, c_oriented_astar, c_get_astar_angles, c_check_for_collision + +__doc__ = exploration_cpp_doc +__all__ = ["c_astar", "c_oriented_astar", "c_get_astar_angles", "c_check_for_collision"] diff --git a/bc_exploration/cpp/src/exploration/python.cpp b/bc_exploration/cpp/src/exploration/python.cpp index 7f44449..6d935ea 100644 --- a/bc_exploration/cpp/src/exploration/python.cpp +++ b/bc_exploration/cpp/src/exploration/python.cpp @@ -6,7 +6,7 @@ #include "exploration/astar.h" #include "safe_array.h" -PYBIND11_MODULE(exploration_cpp, m) { +PYBIND11_MODULE(_exploration_cpp, m) { std::string functions; functions += "c_check_for_collision(pybind11::safe_array<int, 1> position,\n" " pybind11::safe_array<uint8_t, 2> occupancy_map,\n" @@ -37,6 +37,7 @@ PYBIND11_MODULE(exploration_cpp, m) { m.doc() = "Python bindings for the bc_exploration c++ code\n" "To have more documentation call the __doc__ method of the function\n\n" "Available functions:\n\n" + functions; + m.def("c_check_for_collision", &check_for_collision, "Collision checking for custom footprints. \n" " \n" ":param position: 1x2 array with robot coordinate [row, column] \n" diff --git a/bc_exploration/cpp/test_bindings.py b/bc_exploration/cpp/test_bindings.py index a77f019..5c3751e 100644 --- a/bc_exploration/cpp/test_bindings.py +++ b/bc_exploration/cpp/test_bindings.py @@ -1,11 +1,22 @@ from __future__ import print_function, absolute_import, division -from bc_exploration import exploration_cpp +import bc_exploration.cpp -def test_bindings(): - assert exploration_cpp.__doc__ - assert exploration_cpp.c_astar.__doc__ - assert exploration_cpp.c_oriented_astar.__doc__ - assert exploration_cpp.c_get_astar_angles.__doc__ - assert exploration_cpp.c_check_for_collision.__doc__ +def test_bindings(debug=False): + assert bc_exploration.cpp.__doc__ + assert bc_exploration.cpp.c_astar.__doc__ + assert bc_exploration.cpp.c_oriented_astar.__doc__ + assert bc_exploration.cpp.c_get_astar_angles.__doc__ + assert bc_exploration.cpp.c_check_for_collision.__doc__ + + if debug: + print(bc_exploration.cpp.__doc__) + print(bc_exploration.cpp.c_astar.__name__) + print(bc_exploration.cpp.c_oriented_astar.__doc__) + print(bc_exploration.cpp.c_get_astar_angles.__doc__) + print(bc_exploration.cpp.c_check_for_collision.__doc__) + + +if __name__ == '__main__': + test_bindings(debug=True) diff --git a/bc_exploration/footprints/collision_cpp.py b/bc_exploration/footprints/collision_cpp.py index 6076327..2e89051 100644 --- a/bc_exploration/footprints/collision_cpp.py +++ b/bc_exploration/footprints/collision_cpp.py @@ -6,8 +6,7 @@ import numpy as np from bc_exploration.utilities.util import xy_to_rc -from bc_exploration.exploration_cpp import c_check_for_collision - +from bc_exploration.cpp import c_check_for_collision def check_for_collision(state, occupancy_map, footprint_mask, outline_coords, obstacle_values): @@ -18,7 +17,6 @@ def check_for_collision(state, occupancy_map, footprint_mask, outline_coords, ob :param footprint_mask array(N,N)[int]: mask of the footprint rotated at the corresponding angle needed for checking, i.e state[2]. N is 2 * mask_radius + 1, the values are -1 for not footprint, 0 for footprint. - :param mask_radius int: (footprint_mask.shape[0] - 1) / 2 the radius of the mask in pixels :param outline_coords array(N, 2)[int]: the coordinates that define the outline of the footprint. N is the number of points that define the outline of the footprint :param obstacle_values array(N)[uint8]: an array containing values that the collision checker should deem as an obstacle diff --git a/bc_exploration/planners/astar_cpp.py b/bc_exploration/planners/astar_cpp.py index c42850e..1b89c58 100644 --- a/bc_exploration/planners/astar_cpp.py +++ b/bc_exploration/planners/astar_cpp.py @@ -6,7 +6,7 @@ import numpy as np from bc_exploration.utilities.util import xy_to_rc, rc_to_xy -from bc_exploration.exploration_cpp import c_astar, c_oriented_astar, c_get_astar_angles +from bc_exploration.cpp import c_astar, c_oriented_astar, c_get_astar_angles def get_astar_angles(): @@ -56,7 +56,7 @@ def astar(start, goal, occupancy_map, obstacle_values, planning_scale=1, delta=0 return success, np.vstack(([start], path)) -def oriented_astar(start, goal, occupancy_map, footprint_masks, mask_radius, +def oriented_astar(start, goal, occupancy_map, footprint_masks, outline_coords, obstacle_values, planning_scale=1, delta=0.0, epsilon=1.0, allow_diagonal=True): """ Oriented Astar C++ wrapper for python. Formats input data in required format for c++ function, the calls it, @@ -68,7 +68,6 @@ def oriented_astar(start, goal, occupancy_map, footprint_masks, mask_radius, needed for checking, i.e state[2]. N is 2 * mask_radius + 1, the values are -1 for not footprint, 0 for footprint. N is the dimension across angles, (M, M) is the mask shape - :param mask_radius int: (footprint_mask.shape[0] - 1) / 2 the radius of the mask in pixels :param outline_coords array(N, 2)[int]: the coordinates that define the outline of the footprint. N is the number of points that define the outline of the footprint :param obstacle_values array(N)[uint8]: an array containing values that the collision checker should deem as an obstacle diff --git a/bc_exploration/planners/test_astar_cpp.py b/bc_exploration/planners/test_astar_cpp.py index 70a6282..1770550 100644 --- a/bc_exploration/planners/test_astar_cpp.py +++ b/bc_exploration/planners/test_astar_cpp.py @@ -85,13 +85,12 @@ def test_oriented_astar(debug=False): footprint_masks = footprint.get_footprint_masks(occupancy_map.resolution, angles=angles) outline_coords = footprint.get_outline_coords(occupancy_map.resolution, angles=angles) - mask_radius = footprint.get_mask_radius(occupancy_map.resolution) start = rc_to_xy([1956, 137, 0], occupancy_map) goal = rc_to_xy([841, 3403, 0.], occupancy_map) start_time = time.time() - success, path = oriented_astar(start, goal, occupancy_map, footprint_masks, mask_radius, outline_coords, + success, path = oriented_astar(start, goal, occupancy_map, footprint_masks, outline_coords, obstacle_values=[0, 127], planning_scale=10) time_elapsed = time.time() - start_time @@ -122,13 +121,12 @@ def test_impossible_path(debug=False): footprint_masks = footprint.get_footprint_masks(occupancy_map.resolution, angles=angles) outline_coords = footprint.get_outline_coords(occupancy_map.resolution, angles=angles) - mask_radius = footprint.get_mask_radius(occupancy_map.resolution) start = rc_to_xy([425, 50, 0.], occupancy_map) goal = rc_to_xy([232, 339, 0.], occupancy_map) start_time = time.time() - success, path = oriented_astar(start, goal, occupancy_map, footprint_masks, mask_radius, outline_coords, + success, path = oriented_astar(start, goal, occupancy_map, footprint_masks, outline_coords, obstacle_values=[0, 127], planning_scale=10) time_elapsed = time.time() - start_time @@ -155,7 +153,6 @@ def debug_real_case(): goal = data[1] occupancy_map = data[2] footprint_masks = data[3] - mask_radius = data[4] outline_coords = data[5] obstacle_values = data[6] planning_scale = data[7] @@ -167,7 +164,6 @@ def debug_real_case(): goal=goal, occupancy_map=occupancy_map, footprint_masks=footprint_masks, - mask_radius=mask_radius, outline_coords=outline_coords, obstacle_values=obstacle_values, planning_scale=planning_scale, @@ -199,8 +195,8 @@ def main(): debug = True test_one_astar(debug=debug) test_oriented_astar(debug=debug) - # test_multithread_astar(debug=debug) - # test_impossible_path(debug=debug) + test_multithread_astar(debug=debug) + test_impossible_path(debug=debug) # debug_real_case() diff --git a/pylint_rc b/pylint_rc index 7cdd333..905b084 100644 --- a/pylint_rc +++ b/pylint_rc @@ -3,7 +3,7 @@ # A comma-separated list of package or module names from where C extensions may # be loaded. Extensions are loading into the active Python interpreter and may # run arbitrary code -extension-pkg-whitelist= +extension-pkg-whitelist= bc_exploration._exploration_cpp # Add files or directories to the blacklist. They should be base names, not # paths. @@ -12,7 +12,7 @@ ignore=bc_linters, pybind11 # Add files or directories matching the regex patterns to the blacklist. The # regex matches against base names, not paths. -ignore-patterns= +ignore-patterns=_exploration_cpp # Python code to execute, usually for sys.path manipulation such as # pygtk.require(). diff --git a/pytest.ini b/pytest.ini index a31808f..eba1964 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,4 +1,4 @@ -# Configuration of py.test + # Configuration of py.test [pytest] addopts=-v -n 8 @@ -11,6 +11,8 @@ filterwarnings = error::DeprecationWarning error::PendingDeprecationWarning +markers = pep8 + # PEP-8 The following are ignored: # E501 line too long (82 > 79 characters) pep8ignore=E501 diff --git a/setup.py b/setup.py index cbb48e7..fc02ec3 100644 --- a/setup.py +++ b/setup.py @@ -47,7 +47,7 @@ ], packages=find_packages(), ext_package='bc_exploration', - ext_modules=[Extension('exploration_cpp', + ext_modules=[Extension('_exploration_cpp', extra_compile_args=['-std=c++1y', '-O3', '-Wall', '-fpic'], include_dirs=['deps/pybind11/include', 'bc_exploration/cpp/inc'],