Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Feature: Add Python bindings #276

Draft
wants to merge 35 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
84d471c
Include pybind11 in build
wbthomason Feb 11, 2022
f626e5c
Make DEFAULT_ADAPTERS public for Python bindings
wbthomason Feb 11, 2022
1245b23
WIP: making Python bindings to enable fetch_test to work in Python
wbthomason Feb 11, 2022
84c2eff
Initial binding generator script
wbthomason Feb 12, 2022
4651cb4
WIP adding Python library to install list
wbthomason Feb 12, 2022
1a55353
Add proper argument handling and output to file
wbthomason Feb 12, 2022
edea306
Remove AST print
wbthomason Feb 12, 2022
5e4e628
Fix typos in binding templates
wbthomason Feb 12, 2022
4ebebd4
Fix missing stddef
wbthomason Feb 12, 2022
3849d77
Operate on multiple header files at once
wbthomason Feb 13, 2022
34aabe8
Handle static and const methods
wbthomason Feb 13, 2022
b9064fa
Fix syntax for nested class parent objects
wbthomason Feb 13, 2022
20ac394
Fix comment output for class bindings
wbthomason Feb 13, 2022
b4996ce
WIP basic operator handling
wbthomason Feb 13, 2022
294a6f5
Fix constructor type names
wbthomason Feb 13, 2022
866fbc8
Use correctly qualified names for nested types
wbthomason Feb 13, 2022
d731d44
Special-case the assignment operator for now
wbthomason Feb 13, 2022
707e326
Don't generate bindings for deleted constructors
wbthomason Feb 13, 2022
43c8544
Don't bind constructors for abstract classes
wbthomason Feb 13, 2022
fdf7816
Fix constructors with double-pointer arguments
wbthomason Feb 14, 2022
67cab11
Fix output order of bindings, exception special-casing, and container…
wbthomason Feb 14, 2022
084bc6a
Hack around methods with both instance and static versions
wbthomason Feb 14, 2022
c5e7566
Hack around holder types not always being defined
wbthomason Feb 14, 2022
a24e31b
Python implementation of fetch_test
wbthomason Feb 15, 2022
18b3c06
Wrap double-pointers with reference to vector
wbthomason Feb 15, 2022
d3cf692
Constructor wrappers need to return holder types
wbthomason Feb 15, 2022
67ca172
Fix instantiation of default constructor bindings
wbthomason Feb 15, 2022
e6eabb5
Only bind non-private constructors
wbthomason Feb 15, 2022
5cd3300
More consistently use qualified type names
wbthomason Feb 15, 2022
d63930f
Only bind non-private nested types
wbthomason Feb 15, 2022
f810d83
Fix handling nested namespaces
wbthomason Feb 15, 2022
01038f8
Test that toposort worked
wbthomason Feb 15, 2022
bb6c283
Add missing conversion headers to prelude
wbthomason Feb 15, 2022
8c026b3
Add utility function for printing source locations
wbthomason Feb 15, 2022
d2863d6
Remove forward decl for nonexistent method
wbthomason Feb 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions robowflex_library/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 2.8.3)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
project(robowflex_library)

set(LIBRARY_NAME ${PROJECT_NAME})
Expand All @@ -20,6 +21,7 @@ find_library(YAML yaml-cpp REQUIRED)
find_package(TinyXML2 REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(HDF5 REQUIRED COMPONENTS C CXX)
find_package(pybind11 CONFIG)

##
## Catkin setup
Expand Down Expand Up @@ -112,6 +114,14 @@ add_library(${LIBRARY_NAME} ${SOURCES})
set_target_properties(${LIBRARY_NAME} PROPERTIES VERSION ${${PROJECT_NAME}_VERSION})
target_link_libraries(${LIBRARY_NAME} ${LIBRARIES})

##
## Python bindings
##
if(${pybind11_FOUND})
pybind11_add_module(robowflex_library_python src/python_bindings.cpp)
set_target_properties(robowflex_library_python PROPERTIES OUTPUT_NAME "robowflex")
endif()

##
## Scripts
##
Expand Down Expand Up @@ -154,3 +164,11 @@ add_test_script(robot_scene)
install_scripts()
install_library()
install_directory(yaml)
if(${pybind11_FOUND})
# We do this here because it causes errors with this old version of CMake if we do it before
# finding pybind11
find_package(Python COMPONENTS Development)
install(TARGETS robowflex_library_python
COMPONENT python
LIBRARY DESTINATION "${Python_SITELIB}/robowflex")
endif()
65 changes: 65 additions & 0 deletions robowflex_library/fetch_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from sys import argv

import robowflex_library as rf

GROUP = "arm_with_torso"

DEFAULT_ADAPTERS = [
"default_planner_request_adapters/AddTimeParameterization",
"default_planner_request_adapters/FixWorkspaceBounds",
"default_planner_request_adapters/FixStartStateBounds",
"default_planner_request_adapters/FixStartStateCollision",
"default_planner_request_adapters/FixStartStatePathConstraints"
]

# Startup ROS
print('Starting ROS...')
ros = rf.ROS(len(argv), argv, "robowflex", 1)
print('ROS running!')

# Create the default Fetch robot
print('Creating Fetch robot...')
fetch = rf.FetchRobot()
fetch.initialize(True)

# Create an empty scene
print('Creating scene...')
scene = rf.Scene(fetch)

# Create the default planner for the Fetch
print('Creating planner...')
planner = rf.FetchOMPLPipelinePlanner(fetch, "default")
planner.initialize(rf.Settings(), DEFAULT_ADAPTERS)

# Set the Fetch's base pose
print('Posing Fetch...')
fetch.set_base_pose(1, 1, 0.5)

# Set the Fetch's head pose to look at a point
fetch.point_head([2, 1, 1.5])

# Create a motion planning request with a pose goal
print('Creating planning request...')
request = rf.MotionRequestBuilder(planner, GROUP, '')
fetch.set_group_state(GROUP, [0.05, 1.32, 1.40, -0.2, 1.72, 0.0, 1.66, 0.0])
request.set_start_configuration(fetch.get_scratch_state())

# Unfurl
fetch.set_group_state(GROUP, [0.265, 0.501, 1.281, -2.272, 2.243, -2.774, 0.976, -2.007])
request.set_goal_configuration(fetch.get_scratch_state())
request.set_config("RRTConnect")

# Do motion planning!
print('Motion planning...')
result = planner.plan(scene, request.get_request())
# NOTE: We don't export the MoveIt messages library; could probably get the below constant from the
# Python bindings but I'm lazy
if result.error_code_.val != 1:
raise RuntimeError(f'Motion planning failed with code: {result.error_code_.val}')

# Create a trajectory object for better manipulation
print('Exporting trajectory...')
trajectory = rf.Trajectory(result.trajectory_)

# Output path to a file for visualization
trajectory.to_yaml_file("fetch_path.yml")
Loading