Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ackhoury committed Jun 9, 2019
1 parent 7572bb6 commit f2afc7a
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "_")
2 changes: 0 additions & 2 deletions bc_exploration/agents/frontier_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion bc_exploration/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "_")
10 changes: 10 additions & 0 deletions bc_exploration/cpp/__init__.py
Original file line number Diff line number Diff line change
@@ -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"]
3 changes: 2 additions & 1 deletion bc_exploration/cpp/src/exploration/python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
25 changes: 18 additions & 7 deletions bc_exploration/cpp/test_bindings.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 1 addition & 3 deletions bc_exploration/footprints/collision_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions bc_exploration/planners/astar_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
12 changes: 4 additions & 8 deletions bc_exploration/planners/test_astar_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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]
Expand All @@ -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,
Expand Down Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions pylint_rc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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().
Expand Down
4 changes: 3 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Configuration of py.test
# Configuration of py.test
[pytest]
addopts=-v
-n 8
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down

0 comments on commit f2afc7a

Please sign in to comment.