Skip to content

Commit bca24d7

Browse files
committed
initial commit
0 parents  commit bca24d7

File tree

101 files changed

+8193
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+8193
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build*

CHANGELOG

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2+
Changelog for GPMP2
3+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
5+
0.1.0 (2016-06-16)
6+
------------------
7+
* Initial release
8+
* Contributors: Jing Dong, Mustafa Mukadam

CMakeLists.txt

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
cmake_minimum_required(VERSION 2.6)
2+
enable_testing()
3+
project(gpmp2 CXX C)
4+
5+
# Mac ONLY. Define Relative Path on Mac OS
6+
if(NOT DEFINED CMAKE_MACOSX_RPATH)
7+
set(CMAKE_MACOSX_RPATH 0)
8+
endif()
9+
10+
# version indicator
11+
set(GPMP2_VERSION_MAJOR 0)
12+
set(GPMP2_VERSION_MINOR 1)
13+
set(GPMP2_VERSION_PATCH 0)
14+
set(GPMP2_VERSION_STRING "${GPMP2_VERSION_MAJOR}.${GPMP2_VERSION_MINOR}.${GPMP2_VERSION_PATCH}")
15+
16+
17+
# option: whether turn on Matlab toolbox
18+
option(GPMP2_BUILD_MATLAB_TOOLBOX "whether build matlab toolbox" OFF)
19+
20+
21+
# Find GTSAM components
22+
find_package(GTSAM REQUIRED) # Uses installed package
23+
include_directories(${GTSAM_INCLUDE_DIR})
24+
set(GTSAM_LIBRARIES gtsam) # TODO: automatic search libs
25+
26+
find_package(GTSAMCMakeTools)
27+
include(GtsamMakeConfigFile)
28+
include(GtsamBuildTypes)
29+
include(GtsamTesting)
30+
31+
32+
# for unittest scripts
33+
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${GTSAM_DIR}/../GTSAMCMakeTools")
34+
35+
# Boost - same requirement as gtsam
36+
find_package(Boost 1.50 REQUIRED)
37+
find_package(Boost COMPONENTS filesystem REQUIRED)
38+
find_package(Boost COMPONENTS system REQUIRED)
39+
find_package(Boost COMPONENTS thread REQUIRED)
40+
find_package(Boost COMPONENTS serialization REQUIRED)
41+
42+
include_directories(${Boost_INCLUDE_DIR})
43+
44+
45+
# include current source folder, at the very beginning
46+
include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR})
47+
48+
# Process source subdirs
49+
add_subdirectory(gpmp2)
50+
51+
52+
# Wrapping to MATLAB
53+
if(GPMP2_BUILD_MATLAB_TOOLBOX)
54+
# wrap
55+
include(GtsamMatlabWrap)
56+
wrap_and_install_library(gpmp2.h ${PROJECT_NAME} "${CMAKE_CURRENT_SOURCE_DIR}" "")
57+
58+
# install matlab functions and scripts
59+
add_subdirectory(matlab)
60+
endif()
61+
62+
# Install config and export files
63+
GtsamMakeConfigFile(gpmp2)
64+
export(TARGETS ${gpmp2_EXPORTED_TARGETS} FILE gpmp2-exports.cmake)
65+

LICENSE

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright (c) 2016, Georgia Tech Research Corporation
2+
Atlanta, Georgia 30332-0415
3+
All Rights Reserved
4+
5+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6+
7+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8+
9+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
10+
11+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
12+
13+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
GPMP2
2+
===================================================
3+
This library is an implementation of GPMP2 (Gaussian Process Motion Planner 2) algorithm described in Motion Planning
4+
as Probabilistic Inference using Gaussian Processes and Factor Graphs (RSS 2016). The core library is developed in C++
5+
language, and an optional Matlab toolbox is provided. Examples are provided in Matlab scripts.
6+
An OpenRAVE plugin, [orgpmp2](https://github.com/gtrll/gpmp2_orplugin), is also avaible with examples.
7+
8+
GPMP2 is being developed by [Jing Dong](mailto:thu.dongjing@gmail.com) and
9+
[Mustafa Mukadam](mailto:mmukadam3@gatech.edu) as part of their work at Georgia Tech Robot Learning Lab.
10+
11+
Prerequisites
12+
------
13+
14+
- CMake >= 2.6 (Ubuntu: `sudo apt-get install cmake`), compilation configuration tool.
15+
- [Boost](http://www.boost.org/) >= 1.50 (Ubuntu: `sudo apt-get install libboost-all-dev`), portable C++ source libraries.
16+
- [GTSAM](https://bitbucket.org/gtborg/gtsam) >= 4.0 alpha, a C++ library that implement smoothing and mapping (SAM) framework in robotics and vision.
17+
Here we use factor graph implementations and inference/optimization tools provided by GTSAM.
18+
19+
Compilation & Installation
20+
------
21+
22+
In the library folder excute:
23+
24+
```
25+
$ mkdir build
26+
$ cd build
27+
$ cmake ..
28+
$ make check # optonal, run unit tests
29+
$ make install
30+
```
31+
32+
Matlab Toolbox
33+
-----
34+
35+
An optional Matlab toolbox is provided to use our library in Matlab. To enable Matlab toolbox during compilation:
36+
37+
```
38+
$ cmake -DGPMP2_BUILD_MATLAB_TOOLBOX:OPTION=ON -DGTSAM_TOOLBOX_INSTALL_PATH:PATH=/path/install/toolbox ..
39+
$ make install
40+
```
41+
42+
After you install the Matlab toolbox, don't forget to add `/path/install/toolbox` to your Matlab path.
43+
44+
Tested Compatibility
45+
-----
46+
47+
The gpmp2 library is designed to be cross-platform, however it's only tested on Ubuntu Linux for now.
48+
49+
- Compilers: GCC 4.8, 4.9, 5.3
50+
- Boost version: 1.50 - 1.60
51+
52+
53+
Questions & Bug reporting
54+
-----
55+
56+
Please use Github issue tracker to report bugs. For other questions please contact [Jing Dong](mailto:thu.dongjing@gmail.com)
57+
or [Mustafa Mukadam](mailto:mmukadam3@gatech.edu) .
58+
59+
60+
Citing
61+
-----
62+
63+
If you use GPMP2 in an academic context, please cite following publications:
64+
65+
```
66+
@inproceedings{Dong-RSS-16,
67+
Author = "Jing Dong and Mustafa Mukadam and Frank Dellaert and Byron Boots",
68+
booktitle = {Proceedings of Robotics: Science and Systems (RSS-2016)},
69+
Title = "Motion Planning as Probabilistic Inference using Gaussian Processes and Factor Graphs",
70+
year = {2016}
71+
}
72+
```
73+
74+
75+
License
76+
-----
77+
78+
GPMP2 is released under the BSD license, reproduced in the file LICENSE in this directory.

doc/CplusplusDevelopment.md

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
C++ development guide
2+
=========================================
3+
Although all examples are given in Matlab scripts, all the core APIs are developed in C++,
4+
and it's easy to develop your C++ examples or use GPMP2 in your C++ projects.
5+
Here we briefly explain how to use GPMP2 in a C++ project.
6+
7+
Link to your own projects
8+
-----
9+
10+
We provide easy linking to external *CMake* projects. Add the following lines to your CMakeLists.txt
11+
12+
```cmake
13+
find_package(gpmp2 REQUIRED)
14+
include_directories(${gpmp2_INCLUDE_DIR})
15+
```
16+
17+
and link your targets to gpmp2
18+
19+
```cmake
20+
target_link_libraries(${YOUR_BUILD_TARGET} gpmp2)
21+
```
22+
23+
It's also OK to directly add header files and shared library path to your compiler's flags, if you are not using CMake.
24+
25+
C++ source code structure
26+
-----
27+
28+
All the C++ source code is located in [gpmp2](../gpmp2/) folder. The source files are divided in several sub folders,
29+
based on their functionalities.
30+
31+
- **gp** contains all Gaussian Process related classes and functions that include GP prior factors, and GP interpolation.
32+
- **kinematics** contains all robot model related classes and functions that include forward kinematics models, and sphere-based robot physical models.
33+
- **obstacle** contains all obstacle related classes and functions that include signed distance fields, obstacle cost/likelihood functions, and obstacle avoidance factors.
34+
- **planner** contains all integrated GPMP2 motion planners that include batch planners and iSAM2 replanners.
35+
- **utils** contains some utility functions.
36+
37+
You can explore the header files in sub folders to further learn the interfaces.
38+
39+
Build your own robot arm
40+
-----
41+
42+
If you want to build your own robot arm model in C++, there are two steps needed:
43+
first is to build an *abstract* robot arm, which contains only forward kinematics information,
44+
second is to build a *physical* robot arm, which contains forward kinematics information plus physical body information.
45+
46+
To construct an abstract robot arm, call [Arm](../gpmp2/kinematics/Arm.h) class constructor:
47+
48+
```cpp
49+
class Arm : public ForwardKinematics<gtsam::Vector, gtsam::Vector> {
50+
...
51+
/// Contructor take in number of joints for the arm, its DH parameters
52+
/// the base pose (default zero pose), and theta bias (default zero)
53+
Arm(size_t dof, const gtsam::Vector& a, const gtsam::Vector& alpha, const gtsam::Vector& d,
54+
const gtsam::Pose3& base_pose = gtsam::Pose3(gtsam::Rot3(), gtsam::Point3(0,0,0)),
55+
boost::optional<const gtsam::Vector&> theta_bias = boost::none);
56+
...
57+
```
58+
59+
The constructor takes degree of freedom, DH parameters (a, \alpha, d, and optional \theta bias),
60+
and optional arm base pose (default zero), builds an abstract arm object.
61+
62+
In GPMP2, the physical robot information is stored by a series of spheres, in [BodySphereVector](../gpmp2/kinematics/RobotModel.h) class.
63+
64+
```cpp
65+
/// vector of body sphere, typedef here to wrap in matlab
66+
typedef std::vector<BodySphere> BodySphereVector;
67+
```
68+
69+
Each sphere in [BodySphere](../gpmp2/kinematics/RobotModel.h) needs a radius, attached
70+
link index (0 - nr_link-1), and relative position to the link.
71+
72+
```cpp
73+
/// body sphere class, each one indicate a body sphere
74+
struct BodySphere {
75+
size_t link_id; // attched link id, 0 - nr_link-1
76+
double radius; // sphere radius
77+
gtsam::Point3 center; // sphere center position to the link base
78+
// constructor
79+
BodySphere(size_t id, double r, const gtsam::Point3& c) : link_id(id), radius(r), center(c) {}
80+
...
81+
```
82+
Once you initialize the sphere information in [BodySphereVector](../gpmp2/kinematics/RobotModel.h),
83+
you can construct an [ArmModel](../gpmp2/kinematics/ArmModel.h) class, which is a templated version of
84+
[RobotModel](../gpmp2/kinematics/RobotModel.h), with the forward kinematics [Arm](../gpmp2/kinematics/Arm.h)
85+
and physical model information [BodySphereVector](../gpmp2/kinematics/RobotModel.h).
86+
87+
Matlab toolbox wrapping
88+
-----
89+
90+
All the code APIs should be first developed in C++, and then wrapped in Matlab.
91+
All the C++ classes and functions need to be wrapped in Matlab and are declared in [gpmp2.h](../gpmp2.h) header,
92+
and GPMP2 uses GTSAM matlab wrapper to automatically generate .mex library and .m files for all C++ interfaces wrapped.
93+
94+
If you would like to wrap your own C++ interfaces (classes and functions) in Matlab,
95+
just put the declarations in [gpmp2.h](../gpmp2.h) header file, and to import the Matlab toolbox
96+
add the following line at the beginning of Matlab script before using it.
97+
98+
```matlab
99+
import gpmp2.*
100+
```

doc/ExampleMatlab2D.md

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
Example: A simple 2D Matlab example
2+
===================================================
3+
We start with a very simple Matlab example, with a 3-link planer arm avoiding obstacles.
4+
Make sure you have properly installed gpmp2 with Matlab toolbox, and added the toolbox path to Matlab paths.
5+
The full example is available at [matlab/Arm3PlannerExample.m](../matlab/Arm3PlannerExample.m).
6+
7+
Dataset
8+
-----
9+
The generate2Ddataset utility function will generate a dataset object that includes the ground truth 2D occupancy grid,
10+
cell size of the occupancy grid, and the occupancy grid origin (in gtsam.Point2 object) in world coordinate frame.
11+
12+
```matlab
13+
%% small dataset
14+
dataset = generate2Ddataset('TwoObstaclesDataset');
15+
```
16+
17+
Signed Distance Field
18+
-----
19+
After generating datasets, the signed distance field can be calculated from the ground truth occupancy grid.
20+
21+
In 2D cases, the signed distance field is just a matrix. Matrix column index represents X direction,
22+
and row index represents Y direction.
23+
The origin is the position of cell (1,1) in the matrix.
24+
A [PlanarSDF](../gpmp2/obstacle/PlanarSDF.h) object which stores the signed distance field is initialized as follows:
25+
26+
```matlab
27+
% signed distance field
28+
field = signedDistanceField2D(dataset.map, cell_size);
29+
sdf = PlanarSDF(origin_point2, cell_size, field);
30+
```
31+
32+
Robot Arm
33+
-----
34+
A simple 3-link arm in an ArmModel object can be generated from Matlab generateArm utility function for convenience:
35+
36+
```matlab
37+
% arm model
38+
arm = generateArm('SimpleThreeLinksArm');
39+
```
40+
41+
[ArmModel](../gpmp2/kinematics/ArmModel.h) class consists of a forward kinematics model (DH parameter arm implemented by [Arm](../gpmp2/kinematics/Arm.h) class)
42+
and a physical arm represented by a series of spheres (implemented by [BodySphereVector](../gpmp2/kinematics/RobotModel.h) class).
43+
Details can be found in [generateArm.m](../matlab/+gpmp2/generateArm.m).
44+
45+
We can now visualize the dataset setting and start/goal configurations in Matlab
46+
47+
|**Figure 1:** WAM arm dataset visualized in Matlab, with start (blue) and end (red) configuration.|
48+
|:-----------|
49+
|![Matlab scene](pics/3link_setting.png)|
50+
51+
Initialize the Trajectory
52+
-----
53+
54+
To start the iterative non-linear least square optimization, we need to give an initial trajectory.
55+
Here we initialize the trajectory as straight line in configuration space. The initial trajectory should be stored in a gtsam.Values object.
56+
GPMP2 provides a utility function [initArmTrajStraightLine](../gpmp2/planner/TrajUtils.h) to initialize straight line given start/end configuration,
57+
and total number of states/waypoints for optimization.
58+
59+
```matlab
60+
%% init values
61+
init_values = initArmTrajStraightLine(start_conf, end_conf, total_time_step);
62+
```
63+
64+
Parameters
65+
-----
66+
All the trajectory optimization related parameters are stored in [TrajOptimizerSetting](../gpmp2/planner/TrajOptimizerSetting.h) class.
67+
Please check [parameters](Parameters.md) page for details on tuning/setting these parameters.
68+
69+
```matlab
70+
%% optimization settings
71+
opt_setting = TrajOptimizerSetting(3); % initialization with DOF
72+
opt_setting.set_total_step(total_time_step); % total number of states/waypoints for optimization
73+
opt_setting.set_total_time(total_time_sec); % total runtime (second) of the trajectory
74+
opt_setting.set_epsilon(epsilon_dist); % \epsilon for hingeloss function, see the paper
75+
opt_setting.set_cost_sigma(cost_sigma); % \sigma_obs for obstacle cost, see the paper
76+
opt_setting.set_obs_check_inter(check_inter); % number of waypoints are checked by GP interpolation, 0 means GP interpolation is not used
77+
opt_setting.set_conf_prior_model(pose_fix_sigma); % start/end pose prior sigma, leave as default (0.0001) for most cases
78+
opt_setting.set_vel_prior_model(vel_fix_sigma); % start/end velocity prior sigma, leave as default (0.0001) for most cases
79+
opt_setting.set_Qc_model(Qc); % GP hyperparameter
80+
opt_setting.setGaussNewton(); % optimization method
81+
```
82+
83+
Optimization
84+
-----
85+
Factor graph generation and optimization are performed in [BatchTrajOptimize2DArm](../gpmp2/planner/BatchTrajOptimizer.h) function. The BatchTrajOptimize2DArm needs input of arm model, signed distance field, start/end configuration+velocity,
86+
initial trajectory values, and parameters.
87+
88+
```matlab
89+
% optimize!
90+
result = BatchTrajOptimize2DArm(arm, sdf, start_conf, start_vel, end_conf, end_vel, init_values, opt_setting);
91+
```
92+
93+
Densify the Trajectory by GP Interpolation (Optional)
94+
-----
95+
If you need dense trajectory for robot execution, you can densify the trajectory by GP Interpolation.
96+
GPMP2 provides a utility function [interpolateArmTraj](../gpmp2/planner/TrajUtils.h) to densify the trajectory using GP Interpolation and by providing optimized values, GP hyperparameter, time interval between states, and number of points you would like to interpolate between each two states (0 means not interpolation).
97+
98+
```matlab
99+
plot_values = interpolateArmTraj(result, Qc_model, delta_t, plot_inter-1);
100+
```
101+
102+
Display
103+
-----
104+
Once optimized trajectory values are available, we can query the configuration and plot the arm.
105+
The configuration vector can be queried from a gtsam.Values object by ```plot_values.atVector(symbol('x', i));```,
106+
where ```i``` is the index of the state you query (starting from 0 and ending at ```opt_setting.total_step```).
107+
Then [plotPlanarArm](../matlab/+gpmp2/plotPlanarArm.m) is used to plot the arm
108+
109+
```matlab
110+
% plot arm
111+
conf = plot_values.atVector(symbol('x', i));
112+
plotPlanarArm(arm.fk_model(), conf, 'b', 2);
113+
```
114+
115+
Here's the output results of non-densified and densified trajectory
116+
117+
|**Figure 2:** Non-densified trajectory for 2D 3-link arm example.|
118+
|:-----------|
119+
|![2D 3-link arm non-densified](pics/2d_3link_arm_nondense.gif)|
120+
121+
|**Figure 3:** Densified trajectory for 2D 3-link arm example.|
122+
|:-----------|
123+
|![2D 3-link arm densified](pics/2d_3link_arm_dense.gif)|

0 commit comments

Comments
 (0)