Skip to content

Commit 48c41c1

Browse files
authored
Merge pull request #49 from kalyanvasudev/cleanup
gpmp2 python bindings and examples
2 parents ea2e74e + afeadc0 commit 48c41c1

35 files changed

+4066
-62
lines changed

CHANGELOG

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22
Changelog for GPMP2
33
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44

5+
0.3.0 (2021-08-13)
6+
------------------
7+
* Python wrapper with utils and examples
8+
* Self collision factor
9+
* Bugfix for theta_bias in Arm.h
10+
* Contributors: Kalyan Vasudev Alwala, Mustafa Mukadam
11+
12+
0.2.1 (2021-07-21)
13+
------------------
14+
* Joint limit factors with examples
15+
* Optimizer no increase feature
16+
* More robot models (two arm, w/ mobile base, w/ linear actuator)
17+
* Workspace i.e. end effector position, orientation, and full pose constraint
18+
* Updated documentation and some bugfixes
19+
* Contributors: Jing Dong, Mustafa Mukadam
20+
521
0.2.0 (2017-06-16)
622
------------------
723
* Update installation documentation

CMakeLists.txt

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
cmake_minimum_required(VERSION 2.6)
1+
cmake_minimum_required(VERSION 3.0)
22
enable_testing()
33
project(gpmp2 CXX C)
4+
set(CMAKE_CXX_STANDARD 14)
5+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w")
46

57
# Mac ONLY. Define Relative Path on Mac OS
68
if(NOT DEFINED CMAKE_MACOSX_RPATH)
@@ -9,14 +11,15 @@ endif()
911

1012
# version indicator
1113
set(GPMP2_VERSION_MAJOR 0)
12-
set(GPMP2_VERSION_MINOR 2)
14+
set(GPMP2_VERSION_MINOR 3)
1315
set(GPMP2_VERSION_PATCH 0)
1416
set(GPMP2_VERSION_STRING "${GPMP2_VERSION_MAJOR}.${GPMP2_VERSION_MINOR}.${GPMP2_VERSION_PATCH}")
1517

1618

1719
# option: whether turn on Matlab toolbox
1820
option(GPMP2_BUILD_STATIC_LIBRARY "whether build static library" OFF)
1921
option(GPMP2_BUILD_MATLAB_TOOLBOX "whether build matlab toolbox, need shared lib" OFF)
22+
option(GPMP2_BUILD_PYTHON_TOOLBOX "whether build python toolbox, need shared lib" OFF)
2023

2124
if(GPMP2_BUILD_STATIC_LIBRARY AND GPMP2_BUILD_MATLAB_TOOLBOX)
2225
message(FATAL_ERROR "matlab toolbox needs shared lib")
@@ -71,6 +74,22 @@ if(GPMP2_BUILD_MATLAB_TOOLBOX)
7174
endif()
7275

7376

77+
# Wrapping to Python
78+
if(GPMP2_BUILD_PYTHON_TOOLBOX)
79+
include_directories(${GTSAM_DIR}/cython)
80+
include_directories(/usr/local/cython)
81+
include(GtsamCythonWrap)
82+
include_directories(${GTSAM_EIGENCY_INSTALL_PATH})
83+
84+
wrap_and_install_library_cython("gpmp2.h"
85+
"from gtsam.gtsam cimport *" # extra import of gtsam/gtsam.pxd Cython header
86+
"${CMAKE_INSTALL_PREFIX}/cython" # install path
87+
gpmp2 # library to link with
88+
"gtsam" # dependencies which need to be built before wrapping
89+
)
90+
add_definitions(-DBOOST_OPTIONAL_ALLOW_BINDING_TO_RVALUES -DBOOST_OPTIONAL_CONFIG_ALLOW_BINDING_TO_RVALUES)
91+
endif()
92+
7493
# Install config and export files
7594
GtsamMakeConfigFile(gpmp2)
7695
export(TARGETS ${GPMP2_EXPORTED_TARGETS} FILE gpmp2-exports.cmake)

CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ TODO List
1818
------
1919
More or less in order of priority
2020

21+
- Update to latest GTSAM version
22+
- Support Python 3.x
2123
- Load environments from urdf/xml style formats to construct signed distance fields
2224
- Load robot urdf/xml files and construct forward kinematics for them automatically
23-
- Basic python wrapper for front end scripting that can replace the matlab wrapper
2425
- Simple visualizer for environment, robot, trajectory, etc on the python wrapper side
2526
- Alternate obstacle cost functions like, barrier function

README.md

Lines changed: 72 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,86 @@
11
GPMP2
22
===================================================
3-
This library is an implementation of GPMP2 (Gaussian Process Motion Planner 2) algorithm described in [Motion Planning as Probabilistic Inference using Gaussian Processes and Factor Graphs](http://www.cc.gatech.edu/~bboots3/files/GPMP2.pdf) (RSS 2016). The core library is developed in C++ language, and an optional Matlab toolbox is provided. Examples are provided in Matlab scripts. A ROS interface is also available within [PIPER](https://github.com/gtrll/piper). GPMP2 was started at Georgia Tech Robot Learning Lab, see [THANKS](THANKS.md) for contributors.
3+
4+
This library is an implementation of GPMP2 (Gaussian Process Motion Planner 2) algorithm described in [Motion Planning as Probabilistic Inference using Gaussian Processes and Factor Graphs](http://www.cc.gatech.edu/~bboots3/files/GPMP2.pdf) (RSS 2016). The core library is developed in C++ language with an optional Python 2.7 toolbox. GPMP2 was started at the Georgia Tech Robot Learning Lab, see [THANKS](THANKS.md) for contributors.
45

56

67
Prerequisites
78
------
89

9-
- CMake >= 2.6 (Ubuntu: `sudo apt-get install cmake`), compilation configuration tool.
10+
- CMake >= 3.0 (Ubuntu: `sudo apt-get install cmake`), compilation configuration tool.
1011
- [Boost](http://www.boost.org/) >= 1.50 (Ubuntu: `sudo apt-get install libboost-all-dev`), portable C++ source libraries.
11-
- [GTSAM](https://github.com/borglab/gtsam) >= 4.0 alpha, a C++ library that implement smoothing and mapping (SAM) framework in robotics and vision.
12-
Here we use factor graph implementations and inference/optimization tools provided by GTSAM.
13-
14-
Compilation & Installation
15-
------
16-
17-
In the library folder execute:
18-
19-
```
20-
$ mkdir build
21-
$ cd build
22-
$ cmake ..
23-
$ make check # optional, run unit tests
24-
$ make install
25-
```
26-
27-
Matlab Toolbox
28-
-----
12+
- [Anaconda2](https://docs.anaconda.com/anaconda/install/linux/), virtual environment needed if installing python toolbox.
13+
- [GTSAM](https://github.com/borglab/gtsam/tree/wrap-export) == `wrap_export`, a C++ library that implements smoothing and mapping (SAM) framework in robotics and vision. Here we use the factor graph implementations and inference/optimization tools provided by GTSAM.
2914

30-
An optional Matlab toolbox is provided to use our library in Matlab. To enable Matlab toolbox during compilation:
3115

32-
```
33-
$ cmake -DGPMP2_BUILD_MATLAB_TOOLBOX:OPTION=ON -DGTSAM_TOOLBOX_INSTALL_PATH:PATH=/path/install/toolbox ..
34-
$ make install
35-
```
36-
37-
After you install the Matlab toolbox, don't forget to add `/path/install/toolbox` to your Matlab path.
38-
39-
40-
Tested Compatibility
41-
-----
42-
43-
The gpmp2 library is designed to be cross-platform. It has been tested on Ubuntu Linux and Windows for now.
16+
Installation (C++ only)
17+
------
4418

45-
- Ubuntu: GCC 4.8 - 4.9, 5.3 - 5.4
46-
- Windows: Visual C++ 2015 (Matlab toolbox not tested)
47-
- Boost: 1.50 - 1.61
19+
- Install GTSAM.
20+
```bash
21+
git clone https://github.com/borglab/gtsam.git
22+
cd gtsam
23+
git checkout wrap-export
24+
mkdir build && cd build
25+
cmake ..
26+
make check # optional, run unit tests
27+
sudo make install
28+
```
29+
- Setup paths.
30+
```bash
31+
echo 'export LD_LIBRARY_PATH=/usr/local/lib:${LD_LIBRARY_PATH}' >> ~/.bashrc
32+
echo 'export LD_LIBRARY_PATH=/usr/local/share:${LD_LIBRARY_PATH}' >> ~/.bashrc
33+
source ~/.bashrc
34+
```
35+
- Install gpmp2.
36+
```bash
37+
git clone https://github.com/gtrll/gpmp2.git
38+
cd gpmp2 && mkdir build && cd build
39+
cmake ..
40+
make check # optional, run unit tests
41+
sudo make install
42+
```
43+
44+
45+
Installation (C++ with Python toolbox)
46+
------
47+
- Setup virtual environment.
48+
```bash
49+
conda create -n gpmp2 pip python=2.7
50+
conda activate gpmp2
51+
pip install cython numpy scipy matplotlib
52+
conda deactivate
53+
```
54+
- Install GTSAM.
55+
```bash
56+
conda activate gpmp2
57+
git clone https://github.com/borglab/gtsam.git
58+
cd gtsam
59+
git checkout wrap-export
60+
mkdir build && cd build
61+
cmake -DGTSAM_INSTALL_CYTHON_TOOLBOX:=ON ..
62+
make check # optional, run unit tests
63+
sudo make install
64+
conda deactivate
65+
```
66+
- Setup paths.
67+
```bash
68+
echo 'export LD_LIBRARY_PATH=/usr/local/lib:${LD_LIBRARY_PATH}' >> ~/.bashrc
69+
echo 'export LD_LIBRARY_PATH=/usr/local/share:${LD_LIBRARY_PATH}' >> ~/.bashrc
70+
echo 'export PYTHONPATH=/usr/local/cython:${PYTHONPATH}' >> ~/.bashrc
71+
source ~/.bashrc
72+
```
73+
- Install gpmp2.
74+
```bash
75+
conda activate gpmp2
76+
git clone https://github.com/gtrll/gpmp2.git
77+
cd gpmp2 && mkdir build && cd build
78+
cmake -DGPMP2_BUILD_PYTHON_TOOLBOX:=ON ..
79+
make check # optional, run unit tests
80+
sudo make install
81+
cd ../gpmp2_python && pip install -e .
82+
conda deactivate
83+
```
4884

4985

5086
Citing

THANKS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ GPMP2 was made possible by the efforts of the following people:
33
- [Jing Dong](https://github.com/dongjing3309)
44
- [Mustafa Mukadam](https://github.com/mhmukadam)
55
- [Xinyan Yan](https://github.com/XinyanGT)
6+
- [Kalyan Vasudev Alvala](https://github.com/kalyanvasudev)

gpmp2.h

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,35 @@
11
// gpmp2 matlab wrapper declarations
22

3+
/* * Forward declarations and class definitions for Cython:
4+
* - Need to specify the base class (both this forward class and base
5+
class are declared in an external cython header)
6+
* This is so Cython can generate proper inheritance.
7+
* Example when wrapping a gtsam-based project:
8+
* // forward declarations
9+
* virtual class gtsam::NonlinearFactor
10+
* virtual class gtsam::NoiseModelFactor : gtsam::NonlinearFactor
11+
* // class definition
12+
* #include <MyFactor.h>
13+
* virtual class MyFactor : gtsam::NoiseModelFactor {...};
14+
* - *DO NOT* re-define overriden function already declared in the external (forward-declared) base class
15+
* - This will cause an ambiguity problem in Cython pxd header file*/
16+
317
// gtsam deceleration
418
class gtsam::Vector6;
519
class gtsam::Vector3;
620
class gtsam::Point3;
721
class gtsam::Pose3;
822
class gtsam::Point2;
923
class gtsam::Pose2;
24+
//class gtsam::Vector;
1025

1126
class gtsam::GaussianFactorGraph;
1227
class gtsam::Values;
1328
virtual class gtsam::noiseModel::Base;
1429
virtual class gtsam::NonlinearFactor;
1530
virtual class gtsam::NonlinearFactorGraph;
16-
virtual class gtsam::NoiseModelFactor;
31+
virtual class gtsam::NoiseModelFactor : gtsam::NonlinearFactor;
32+
//virtual class gtsam::NoiseModelFactor;
1733

1834
namespace gpmp2 {
1935

@@ -40,11 +56,21 @@ class Pose2Vector {
4056
////////////////////////////////////////////////////////////////////////////////
4157

4258
// prior factor
43-
#include <gpmp2/gp/GaussianProcessPriorLinear.h>
4459

60+
//template<class VALUE1, class VALUE2, class VALUE3, class VALUE4>
61+
//template<Vector, Vector, Vector, Vector>
62+
//virtual class gtsam::NoiseModelFactor4: gtsam::NoiseModelFactor;
63+
64+
#include <gpmp2/gp/GaussianProcessPriorLinear.h>
65+
//template<gtsam::Vector, gtsam::Vector, gtsam::Vector, gtsam::Vector>
4566
virtual class GaussianProcessPriorLinear : gtsam::NoiseModelFactor {
4667
GaussianProcessPriorLinear(size_t key1, size_t key2, size_t key3, size_t key4,
4768
double delta, const gtsam::noiseModel::Base* Qc_model);
69+
//Vector evaluateError(Vector pose) const;
70+
Vector evaluateError(const Vector& pose1, const Vector& vel1,
71+
const Vector& pose2, const Vector& vel2);
72+
// enabling serialization functionality
73+
void serialize() const;
4874
};
4975

5076
#include <gpmp2/gp/GaussianProcessPriorPose2.h>
@@ -469,6 +495,7 @@ virtual class ObstaclePlanarSDFFactorArm : gtsam::NoiseModelFactor {
469495
size_t posekey, const gpmp2::ArmModel& arm,
470496
const gpmp2::PlanarSDF& sdf, double cost_sigma, double epsilon);
471497
Vector evaluateError(Vector pose) const;
498+
void serialize() const;
472499
};
473500

474501

@@ -657,6 +684,13 @@ virtual class ObstacleSDFFactorGPPose2MobileVetLin2Arms : gtsam::NoiseModelFacto
657684
double delta_t, double tau);
658685
};
659686

687+
// self collision Arm
688+
#include <gpmp2/obstacle/SelfCollisionArm.h>
689+
virtual class SelfCollisionArm : gtsam::NoiseModelFactor {
690+
SelfCollisionArm(size_t poseKey, const gpmp2::ArmModel& arm, Matrix data);
691+
Vector evaluateError(Vector pose) const;
692+
};
693+
660694
////////////////////////////////////////////////////////////////////////////////
661695
// planner
662696
////////////////////////////////////////////////////////////////////////////////

gpmp2/gp/GaussianProcessPriorLinear.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,21 @@ class GaussianProcessPriorLinear: public gtsam::NoiseModelFactor4<
6262
boost::optional<gtsam::Matrix&> H3 = boost::none,
6363
boost::optional<gtsam::Matrix&> H4 = boost::none) const {
6464

65-
using namespace gtsam;
65+
//using namespace gtsam;
6666

6767
// state vector
68-
Vector x1 = (Vector(2*dof_) << pose1, vel1).finished();
69-
Vector x2 = (Vector(2*dof_) << pose2, vel2).finished();
68+
gtsam::Vector x1 = (gtsam::Vector(2*dof_) << pose1, vel1).finished();
69+
gtsam::Vector x2 = (gtsam::Vector(2*dof_) << pose2, vel2).finished();
7070

7171
// Jacobians
72-
if (H1) *H1 = (Matrix(2*dof_, dof_) << Matrix::Identity(dof_, dof_),
73-
Matrix::Zero(dof_, dof_)).finished();
74-
if (H2) *H2 = (Matrix(2*dof_, dof_) << delta_t_ * Matrix::Identity(dof_, dof_),
75-
Matrix::Identity(dof_, dof_)).finished();
76-
if (H3) *H3 = (Matrix(2*dof_, dof_) << -1.0 * Matrix::Identity(dof_, dof_),
77-
Matrix::Zero(dof_, dof_)).finished();
78-
if (H4) *H4 = (Matrix(2*dof_, dof_) << Matrix::Zero(dof_, dof_),
79-
-1.0 * Matrix::Identity(dof_, dof_)).finished();
72+
if (H1) *H1 = (gtsam::Matrix(2*dof_, dof_) << gtsam::Matrix::Identity(dof_, dof_),
73+
gtsam::Matrix::Zero(dof_, dof_)).finished();
74+
if (H2) *H2 = (gtsam::Matrix(2*dof_, dof_) << delta_t_ * gtsam::Matrix::Identity(dof_, dof_),
75+
gtsam::Matrix::Identity(dof_, dof_)).finished();
76+
if (H3) *H3 = (gtsam::Matrix(2*dof_, dof_) << -1.0 * gtsam::Matrix::Identity(dof_, dof_),
77+
gtsam::Matrix::Zero(dof_, dof_)).finished();
78+
if (H4) *H4 = (gtsam::Matrix(2*dof_, dof_) << gtsam::Matrix::Zero(dof_, dof_),
79+
-1.0 * gtsam::Matrix::Identity(dof_, dof_)).finished();
8080

8181
// transition matrix & error
8282
return calcPhi(dof_, delta_t_) * x1 - x2;

gpmp2/kinematics/Arm.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,9 @@ namespace gpmp2 {
1414

1515
/* ************************************************************************** */
1616
Arm::Arm(size_t dof, const Vector& a, const Vector& alpha, const Vector& d,
17-
const gtsam::Pose3& base_pose, boost::optional<const Vector&> theta_bias) :
18-
Base(dof, dof), a_(a), alpha_(alpha), d_(d), base_pose_(base_pose) {
19-
20-
// theta bias
21-
if (theta_bias)
22-
theta_bias_ = *theta_bias;
23-
else
24-
theta_bias_ = Vector::Zero(dof);
17+
const Pose3& base_pose, const Vector& theta_bias) :
18+
Base(dof, dof), a_(a), alpha_(alpha), d_(d), base_pose_(base_pose),
19+
theta_bias_(theta_bias) {
2520

2621
// DH transformation for each link, without theta matrix
2722
// Spong06book, page. 69, eq. (3.10)

gpmp2/kinematics/Arm.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,16 @@ class GPMP2_EXPORT Arm : public ForwardKinematics<gtsam::Vector, gtsam::Vector>
4444

4545
/// Contructor take in number of joints for the arm, its DH parameters
4646
/// the base pose (default zero pose), and theta bias (default zero)
47+
Arm(size_t dof, const gtsam::Vector& a, const gtsam::Vector& alpha, const gtsam::Vector& d) :
48+
Arm(dof, a, alpha, d, gtsam::Pose3(gtsam::Rot3(), gtsam::Point3(0,0,0)), gtsam::Vector::Zero(dof)) {}
49+
50+
Arm(size_t dof, const gtsam::Vector& a, const gtsam::Vector& alpha, const gtsam::Vector& d,
51+
const gtsam::Pose3& base_pose) :
52+
Arm(dof, a, alpha, d, base_pose, gtsam::Vector::Zero(dof)) {}
53+
4754
Arm(size_t dof, const gtsam::Vector& a, const gtsam::Vector& alpha, const gtsam::Vector& d,
48-
const gtsam::Pose3& base_pose = gtsam::Pose3(gtsam::Rot3(), gtsam::Point3(0,0,0)),
49-
boost::optional<const gtsam::Vector&> theta_bias = boost::none);
55+
const gtsam::Pose3& base_pose, const gtsam::Vector& theta_bias);
56+
5057

5158
/// Default destructor
5259
virtual ~Arm() {}

0 commit comments

Comments
 (0)