TEB Tuning Guide
Timed Elastic Band (TEB) locally optimizes the robot's trajectory with respect to execution time, distance from obstacles and kinodynamic constraints at runtime.

How to refine teb_local_planner for navigation

This guide is for you if you choose to use teb_local_planner to navigate your robots. For more information, click here.

1. Setting up

1.1. Configure local planner

Filepath: catkin_ws/movel_ai/config/movel/config/
File to modify: base_local_planner_params.yaml
Note that config files for local planner is located in the movel package. In the yaml file itself, you see there are actually 3 local planners included. But we will only use one of them. Uncomment the entire long section under TebLocalPlannerROS.
One good practice will be to include only things you need (uncomment if previously commented) and comment out the rest.
These are the parameters that can be configured. Will explain how to tune these parameters later.
base_local_planner_params.yaml
1
TebLocalPlannerROS:
2
3
odom_topic: /odom
4
#odom_topic: /rtabmap/odom
5
map_frame: map
6
7
# Trajectory
8
9
teb_autosize: True
10
dt_ref: 0.3 #0.2
11
dt_hysteresis: 0.1
12
global_plan_overwrite_orientation: True
13
max_global_plan_lookahead_dist: 3.0
14
feasibility_check_no_poses: 5
15
16
# Robot
17
18
max_vel_x: 0.40 #0.25
19
max_vel_x_backwards: 0.4 #0.2
20
max_vel_theta: 1.0 #0.5
21
acc_lim_x: 0.5 # 0.2
22
acc_lim_theta: 0.6283 #0.5, 0.26
23
min_turning_radius: 0.0
24
footprint_model: # types: "point", "circular", "two_circles", "line", "polygon"
25
type: "polygon" #"circular"
26
radius: 0.38 # for type "circular"
27
#line_start: [-0.3, 0.0] # for type "line"
28
#line_end: [0.3, 0.0] # for type "line"
29
#front_offset: 0.2 # for type "two_circles"
30
#front_radius: 0.2 # for type "two_circles"
31
#rear_offset: 0.2 # for type "two_circles"
32
#rear_radius: 0.2 # for type "two_circles"
33
vertices: [ [0.26, 0.26], [0.26, -0.26], [-0.26, -0.26], [-0.26,0.26] ] # for type "polygon"
34
35
# GoalTolerance
36
37
xy_goal_tolerance: 0.2 #0.2
38
yaw_goal_tolerance: 0.1571
39
free_goal_vel: False
40
41
# Obstacles
42
43
min_obstacle_dist: 0.05
44
inflation_dist: 0.0
45
dynamic_obstacle_inflation_dist: 0.05
46
include_costmap_obstacles: True
47
costmap_obstacles_behind_robot_dist: 0.1
48
obstacle_poses_affected: 25 #30
49
costmap_converter_plugin: ""
50
costmap_converter_spin_thread: True
51
costmap_converter_rate: 5
52
53
# Optimization
54
55
no_inner_iterations: 5 #5
56
no_outer_iterations: 4 #4
57
optimization_activate: True
58
optimization_verbose: False
59
penalty_epsilon: 0.1
60
weight_max_vel_x: 2 #2
61
weight_max_vel_theta: 1 #1
62
weight_acc_lim_x: 1 # 1
63
weight_acc_lim_theta: 1 # 1
64
weight_kinematics_nh: 1000 #1000
65
weight_kinematics_forward_drive: 1000 #1000
66
weight_kinematics_turning_radius: 1 #1 #only for car-like robots
67
weight_optimaltime: 1.0 #1
68
weight_obstacle: 50 #50
69
weight_viapoint: 5.0 #5.0 #1.0
70
weight_inflation: 0.1 #0.1
71
weight_dynamic_obstacle: 10 # not in use yet
72
selection_alternative_time_cost: False # not in use yet
73
74
# Homotopy Class Planner
75
76
enable_homotopy_class_planning: False #True
77
enable_multithreading: True
78
simple_exploration: False
79
max_number_classes: 2 #4
80
roadmap_graph_no_samples: 15
81
roadmap_graph_area_width: 5
82
h_signature_prescaler: 0.5
83
h_signature_threshold: 0.1
84
obstacle_keypoint_offset: 0.1
85
obstacle_heading_threshold: 0.45
86
visualize_hc_graph: False
87
88
#ViaPoints
89
global_plan_viapoint_sep: 0.5 #negative if none
90
via_points_ordered: False #adhere to order of via points
91
92
#Feedback
93
publish_feedback: true #false
Copied!
Warn: yaml forbids tabs. Do not use tabs to indent when editing yaml files. Also, check your indentations align properly.

1.2. Configure velocity setter

After configuring Seirios to use teb planner, you need to sync the velocity with maximum velocity specified by teb planner.
Filepath: catkin_ws/movel_ai/config/velocity_setter/config/
File to modify: velocity_setter.yaml
velocity_setter.yaml
1
local_planner: "TebLocalPlannerROS"
2
parameter_name_linear: "max_vel_x"
3
parameter_name_angular: "max_vel_theta"
Copied!
Check local_planner match the name of the planner in the base local planner configuration. You are configuring the maximum velocities to be the maximum velocities you specified in teb planner.

1.3. Checks

  • rostopic list in terminal to check you have /odom published.
  • Planners require a map to work so make sure you have already mapped the location you want to navigate in.
  • Boot up rviz, change your Fixed Frame to /map.
  • In Seirios, load the map from the library.

2. Localizing your robot

rviz: Use the 2D Pose Estimator tool to pinpoint the location of your robot on the map. You can use LaserScan to help you – increase the Size (m) to at least 0.05 and try to match the lines from the LaserScan as closely as possible with the map.
Seirios: Go to Localize. Use either your keyboard or the joystick button to align the laser with the map as closely as possible.

2.1. AMCL configurations

Filepath: catkin_ws/movel_ai/config/movel/config/amcl.yaml
File to modify: amcl.yaml
Amcl configuration file is in the same directory as base_local_planner_params.yaml.
Similarly, there are a lot of paramters in the amcl file although we are only interested in these 2 parameters:
amcl.yaml
1
min_particles: 50
2
max_particles: 1000
Copied!
Configure min_particles and max_particles to adjust the precision.
You can increase the values if you want a more precise localization.
However, tune the values with respects to the size of your map. Too many particles on a small map means there are redundant particles which only wastes computing power.
Click here for more information.

2.2. Checks

  • Robot's position in rviz/Seirios must correspond to the actual position of the robot as accurately as possible. Inaccurate localization could cause problems such as bad routing, robot going to restricted areas, robot getting stuck at awkward corners etc.

3. Tuning teb_local_planner parameters

This section provides some suggestions on what values to give to the long list of parameters for TebLocalPlannerROS. Go back to the same base_local_planner_params.yaml file.
TEB requires a lot of tuning to get it to behave the way you want. Probably a lot of it is through trial and error.
For all kinds of robot tuning, always refer to the robot manufacturer’s configs. Whatever params you set must be within what that is handleable by your robot.
General tip: Make changes to only one/a few parameters at a time to observe how the robot behaves.
Tuneable parameters can be grouped into the following categories
  • Robot
  • Goal Tolerance
  • Trajectory
  • Obstacles
  • Optimisation

3.1. Robot

Tune robot related params with respects to the configurations specified by the manufacturer. i.e. The values set for velocity and acceleration should not exceed the robot's hardware limitations.
Kinematics
vel parameters limits how fast the robot can move. acc parameters limits how fast robot can accelerate. _x specifies linear kinematics whereas _theta specifies angular kinematics.
1
max_vel_x: 0.40 #0.25
2
max_vel_x_backwards: 0.4 #0.2
3
max_vel_theta: 1.0 #0.5
4
acc_lim_x: 0.5 # 0.2
5
acc_lim_theta: 0.6283 #0.5, 0.26
Copied!
Footprint Model
Literally a footprint.
👣
Ideally, configure the footprint to be slightly bigger than the actual measurement of the robot. footprint_model should be configured with respects to the robot's measurements.
1
footprint_model: # types: "point", "circular", "two_circles", "line", "polygon"
2
type: "polygon" #"circular"
3
radius: 0.38 # for type "circular"
4
#line_start: [-0.3, 0.0] # for type "line"
5
#line_end: [0.3, 0.0] # for type "line"
6
#front_offset: 0.2 # for type "two_circles"
7
#front_radius: 0.2 # for type "two_circles"
8
#rear_offset: 0.2 # for type "two_circles"
9
#rear_radius: 0.2 # for type "two_circles"
10
vertices: [ [0.26, 0.26], [0.26, -0.26], [-0.26, -0.26], [-0.26,0.26] ] # for type "polygon"
Copied!
You must indicate the type of the robot footprint. Different types include polygon, circular, two_circles, line, point etc. For simplicity sake, footprints are usually circular or polygon. Click here for more footprint information.
radius is required for type: "circular"
vertices is required for type: "polygon"

3.2. Goal Tolerance

Specifies how much deviation from the goal point that you are willing to tolerate.
1
xy_goal_tolerance: 0.2 #0.2
2
yaw_goal_tolerance: 0.1571
Copied!
xy_goal_tolerance is the acceptable linear distance away from the goal, in meters.
Should not set xy value too high, else the robot will stop at a very different location. However, some leeway is required to account for robot drift etc.
yaw_goal_tolerance is the deviation in the robot's orientation. i.e. Goal specifies that the robot should face directly in front of the wall but in actual, the robot faces slightly to the left.
Should not give a too tight yaw tolerance, else the robot could be jerking around just to get the orientation right. Which might not be ideal in terms of efficiency.

3.3. Obstacles

Decides how the robot should behave in front of obstacles.
Experimentation is required to tune the planner to approach obstacles optimally. A riskier configuration will allow the robot to move in obstacle ridden paths i.e. narrow corridors but it might get itself stuck around obstacles or bump into obstacles. A more conservative configuration might cause the robot to rule out its only available path because it thinks its too close to obstacles.
The tricky part is really to achieve a balance between those two scenarios.
1
min_obstacle_dist: 0.05
2
inflation_dist: 0.0
3
dynamic_obstacle_inflation_dist: 0.05
4
include_costmap_obstacles: True
5
costmap_obstacles_behind_robot_dist: 0.1
6
obstacle_poses_affected: 25 #30
7
costmap_converter_plugin: ""
8
costmap_converter_spin_thread: True
9
costmap_converter_rate: 5
Copied!
min_obstacle_dist is the minimum distance you want to maintain away from obstacles.
inflation_dist is the buffer zone to add around obstacles.
Click here for more information about obstacle avoidance and penalty. And click here for known problems with regards to obstacle avoidance tuning.

4. Tuning costmap for obstacle avoidance

Besides configuring obstacle handling behaviours in local planner, we can also configure the costmaps.
A costmap tells a robot how much does it cost to move the robot to a particular point. The higher the cost, the more the robot shouldn’t go there. Lethal obstacles that could damage the robot will have super high cost.
Filepath: catkin_ws/movel_ai/config/movel/config/
File to modify: costmap_common_params.yaml
File is in the same directory as base_local_planner_params.
costmap_common_params.yaml
1
footprint: [ [0.26, 0.26], [0.26, -0.26], [-0.26, -0.26], [-0.26,0.26] ]
2
# robot_radius: 0.38 #0.38
3
# footprint_padding: 0.05
4
map_type: voxel
5
#track_unknown_space: true
6
7
obstacle_layer:
8
origin_z: -0.1
9
z_resolution: 1.8 #1.5 This must be higher than the z coordinate of the mounted lidar
10
z_voxels: 1
11
obstacle_range: 10.0 #10.0
12
raytrace_range: 15.0 #15.0
13
observation_sources: laser_scan_sensor
14
track_unknown_space: true
15
lethal_cost_threshold: 100
16
unknown_cost_value: 255
17
18
laser_scan_sensor: {data_type: LaserScan, topic: /scan, marking: true, clearing: true, min_obstacle_height: 0.00, max_obstacle_height: 3.00}
19
#point_cloud_sensor: {sensor_frame: lslidar_c16_frame, data_type: PointCloud2, topic: /lslidar_c16/lslidar_point_cloud, marking: true, clearing: true}
20
21
lowbstacle_layer:
22
origin_z: -0.1
23
z_resolution: 1.8
24
z_voxels: 1
25
obstacle_range: 3.5 #if beyond this threshold, then will not mark as obstacle
26
raytrace_range: 5.0 #5.0 Lower this value to detect nearer obstacles with better accuracy
27
observation_sources: obs_cloud mock_scan #butt_scan1 butt_scan2
28
publish_voxel_map: true
29
track_unknown_space: true
30
lethal_cost_threshold: 100
31
unknown_cost_value: 255
32
33
obs_cloud:
34
data_type: PointCloud2
35
topic: /obstacles_cloud
36
marking: true
37
clearing: true
38
min_obstacle_height: 0.01
39
max_obstacle_height: 0.99
40
mock_scan:
41
data_type: LaserScan
42
topic: /obstacles_scan
43
marking: false
44
clearing: true
45
min_obstacle_height: 0.00
46
max_obstacle_height: 1.00
47
inf_is_valid: true
48
49
inflation_layer:
50
enabled: true
51
cost_scaling_factor: 6.0 #added in by John
52
inflation_radius: 0.39 #0.45 #Minimum value: 0.379
53
54
dynamic_obstacle_layer:
55
enabled: false
56
map_tolerance: 0.2
57
footprint_radius: 0.5
58
range: 2.0
Copied!
There are several layers added into the costmap. Usually we follow the specifications here.
footprintmust match the measurements specified in base_local_planner_params.yaml.
You can choose to add some or all of the layers in the common_costmap_params into global_costmap_params and local_costmap_params.
For the costmap layers that you have decided to use, you must mount the layers into global_costmap_params.yaml and local_costmap_params.yaml as plugins. Click here for more information on the difference between global and local costmaps.
global_costmap_params.yaml
local_costmap_params.yaml
1
plugins:
2
- {name: static_layer, type: "costmap_2d::StaticLayer"}
3
- {name: obstacle_layer, type: "costmap_2d::VoxelLayer"}
4
- {name: lowbstacle_layer, type: "costmap_2d::VoxelLayer"}
5
- {name: dynamic_obstacle_layer, type: "dynamic_obstacle_layer::DynamicLayer"} # Uncomment to apply dynamic_obstacle_layer
6
- {name: inflation_layer, type: "costmap_2d::InflationLayer"}
Copied!
1
plugins:
2
- {name: obstacle_layer, type: "costmap_2d::VoxelLayer"}
3
- {name: lowbstacle_layer, type: "costmap_2d::VoxelLayer"}
4
- {name: inflation_layer, type: "costmap_2d::InflationLayer"}
5
# - {name: range_sensor_layer, type: "range_sensor_layer::RangeSensorLayer"}
6
Copied!
The most important thing in this section is to get the robot's footprint right.
Tip: Tune the teb_local_planner params first. Modify the costmap only if you need more fine tuning after that.

4.1. Inflation Layer

This layer inflates the margin around lethal obstacles and specifies how much bigger you want to inflate the obstacles by.
1
inflation_layer:
2
enabled: true
3
cost_scaling_factor: 6.0 #added in by John
4
inflation_radius: 0.39 #0.45 #Minimum value: 0.379
Copied!
inflation_radius is the radius, in meters, to which the map inflates obstacle cost value. Usually it is the width of the bot, plus some extra space.
cost_scaling_factors is the scaling factor to apply to cost values during inflation.
Additional information to configure it correctly (directly lifted from here)
The inflation_radius is actually the radius to which the cost scaling function is applied, not a parameter of the cost scaling function. Inside the inflation radius, the cost scaling function is applied, but outside the inflation radius, the cost of a cell is not inflated using the cost function.
You'll have to make sure to set the inflation radius large enough that it includes the distance you need the cost function to be applied out to, as anything outside the inflation_radius will not have the cost function applied.
For the correct cost_scaling_factor, solve the equation there ( exp(-1.0 * cost_scaling_factor * (distance_from_obstacle - inscribed_radius)) * (costmap_2d::INSCRIBED_INFLATED_OBSTACLE - 1)), using your distance from obstacle and the cost value you want that cell to have.
Ideally, we want to set these two parameters such that the inflation layer almost covers the corridors. And the robot is moving in the center between the obstacles. (See figure below)
Image from https://kaiyuzheng.me/documents/navguide.pdf (Pg 12)

4.2. Obstacle Layer

The obstacle layer marks out obstacles on the costmap. It tracks the obstacles as registered by sensor data.
1
obstacle_layer:
2
origin_z: -0.1
3
z_resolution: 1.8 #1.5 This must be higher than the z coordinate of the mounted lidar
4
z_voxels: 1
5
obstacle_range: 10.0 #10.0
6
raytrace_range: 15.0 #15.0
7
observation_sources: laser_scan_sensor
8
track_unknown_space: true
9
lethal_cost_threshold: 100
10
unknown_cost_value: 255
11
12
laser_scan_sensor: {data_type: LaserScan, topic: /scan, marking: true, clearing: true, min_obstacle_height: 0.00, max_obstacle_height: 3.00}
13
#point_cloud_sensor: {sensor_frame: lslidar_c16_frame, data_type: PointCloud2, topic: /lslidar_c16/lslidar_point_cloud, marking: true, clearing: true}
Copied!
For 2D mapping, laser_scan_sensor must be selected.
obstacle_range is the maximum distance from the robot that an obstacle will be inserted into the costmap. A value of 10 means the costmap will mark out obstacles that are within 10 meters from the robot.
raytrace_range is the range in meters at which to raytrace out obstacles. The value must be set with respects to your sensors.
max_obstacle_height is the maximum height of obstacles to be added to the costmap. Increase this number if you have very tall obstacles. The value must be set with respects to your sensors.
Voxel layer parameters
Voxels are 3D cubes that has a relative position in space. Can be used for 3D reconstruction with depth cameras. Ignore the parameters below if you are not using 3D. More information here.
origin_z is the z-origin of the map (meters)
z_resolution is the height of the cube
z_resolution controls how dense the voxels is on the z-axis. If it is higher, the voxel layers are denser. If the value is too low (e.g. 0.01), you won’t get useful costmap information. If you set z resolution to a higher value, your intention should be to obtain obstacles better, therefore you need to increase z_voxels parameter which controls how many voxels in each vertical column. It is also useless if you have too many voxels in a column but not enough resolution, because each vertical column has a limit in height.
z_voxels is the number of voxels

4.3. lowbstacle layer

Low obstacle layer is obstacle layer, but with additional parameters. Change your observation_sources to the topic that you want to take in data from.
Use obs_cloud if you want a PointCloud (3D) or mock_scan if you want a LaserScan (2D). Or you can specify your own method.
1
lowbstacle_layer:
2
origin_z: -0.1
3
z_resolution: 1.8
4
z_voxels: 1
5
obstacle_range: 3.5 #if beyond this threshold, then will not mark as obstacle
6
raytrace_range: 5.0 #5.0 Lower this value to detect nearer obstacles with better accuracy
7
observation_sources: obs_cloud mock_scan #butt_scan1 butt_scan2
8
publish_voxel_map: true
9
track_unknown_space: true
10
lethal_cost_threshold: 100
11
unknown_cost_value: 255
12
13
obs_cloud:
14
data_type: PointCloud2
15
topic: /obstacles_cloud
16
marking: true
17
clearing: true
18
min_obstacle_height: 0.01
19
max_obstacle_height: 0.99
20
mock_scan:
21
data_type: LaserScan
22
topic: /obstacles_scan
23
marking: false
24
clearing: true
25
min_obstacle_height: 0.00
26
max_obstacle_height: 1.00
27
inf_is_valid: true
Copied!
There are only two important parameters to note.
min_obstacle_height is the height of the obstacle below the base of the robot. Examples includes stairs. Specify this param so that the robot can detect obstacles below its base link and prevent it from falling into the pit...
This is the reason why we need a min_obstacle_height.
max_obstacle_height is the maximum height of obstacle. It is usually specified as the height of the robot.

5. Uncomfortable situations

You WILL definitely be encountering some of the issues. Because param tuning requires experimentation, it is suggested you test out your values in the console first before modifying the yaml files.
rosrun rqt_reconfigure rqt_reconfigure
List of known issues and possible fixes is not exhaustive. There will be many more issues yet to be encountered when extensively using the robot. Thus it is good practice to keep a list of problems and solutions so you know how to deal with the problem should it come up again.

5.1. Some known uncomfortable situations

Issue #1: Problems getting the robot to go to the other side of the narrow path.
It is noted from observations that the robot will be returning goal failure, or that robot will get itself uncomfortably close to walls and get stuck there.
Issue #2: Problems getting the robot to turn 90 degrees.
The planner somehow disregards the wall and direct the robot to go through it instead of making a 90 degree turn around the wall. Though it seems most robots are smart enough to recognize they cannot go through walls and will either abort the goal or get stuck trying.

5.2. Some attempted fix

Solution #1: Reducing the velocity and acceleration. The intuition is that by slowing down the movement and rotation of the robot, the planner might have more time to react to the obstacle and plan accordingly.
Solution #2: (For robots that refuses to go to the other side of the corridor.)
Shrink the inflation_radius in both costmaps so that it does not cover the corridor. (Right figure) Noted with observation that if the radius covers the entire corridor, robot may refuse to move.
left: inflation_radius covering corridor; robot refuses to move
right: cleared inflation_radius
Check that the robot's footprint size is correct and check that the costmaps aren't blocking the paths.

References

External resources if you need more information about planners and tuning planners.