Note: This tutorial assumes that you have completed the previous tutorials: trajectory_filters/Tutorials/Tutorial 1.

# Generating collision free cubic spline trajectories

Description: In this tutorial, you will learn to configure the joint trajectory filter node to generate collision free cubic spline trajectories.

Tutorial Level: INTERMEDIATE

In this tutorial, you will learn how to create collision free trajectories to follow a path returned from a planner. This type of filter is most suitable for use with probabilistic planners like RRTs which tend to return paths that are not very smooth. The filter functions by shortcutting between random waypoints in the path with cubic splines, checking collisions for the splines and taking the shortcut if it's collision free.

## Details

The setup for this tutorial is almost identical to the previous tutorial. It differs in the type of trajectory filter used. The filters.yaml for this new set of filters is the following:

```service_type: FilterJointTrajectoryWithConstraints
filter_chain:
-
name: unnormalize_trajectory
type: UnNormalizeFilterJointTrajectoryWithConstraints
-
name: cubic_spline_short_cutter_smoother
type: CubicSplineShortCutterFilterJointTrajectoryWithConstraints
params: {discretization: 0.01}```

The discretization parameter for the short cutter specifies the time discretization of the returned trajectory from that filter.

To learn more about what the filter actually does, we will look at plots of the filtered output for a simple trajectory for a single joint. Consider the plot below which shows a sample straight line path input to the filter (the y axis shows the joint position while the x axis plots the timestamp (time from epoch):

After filtering, the path will be smoother and will obey velocity and acceleration constraints (set in the joint_limits.yaml file, see previous tutorial).

Here's a better example from a run on the PR2 robot. The first plot is the raw desired path from a probabilistic planner:

and here's the filtered trajectory:

2019-12-07 13:12