# Vector Field Histogram

Avoid obstacles using vector field histogram

**Libraries:**

Navigation Toolbox /
Control Algorithms

## Description

The Vector Field Histogram (VFH) block enables your vehicle to avoid obstacles based on range sensor data. Given a range sensor reading in terms of ranges and angles, and a target direction to drive toward, the VFH controller computes an obstacle-free steering direction.

For more information on the algorithm details, see Vector Field Histogram under Algorithms.

## Examples

### Path Following with Obstacle Avoidance in Simulink®

Use Simulink to avoid obstacles while following a path for a differential drive robot. This example uses ROS to send and receive information from a MATLAB®-based simulator. You can replace the simulator with other ROS-based simulators such as Gazebo®.

## Limitations

The

`Ranges`

and`Angles`

inputs are limited to 4000 elements when generating code for models that use this block.

## Ports

### Input

**Ranges** — Range values from scan data

vector of scalars

Range values from scan data, specified as a vector of scalars
in meters. These range values are distances from a sensor at specified
angles. The vector must be the same length as the corresponding **Angles** vector.

**Angles** — Angle values from scan data

vector of scalars

Angle values from scan data, specified as a vector of scalars
in radians. These angle values are the specific angles of the specified
ranges. The vector must be the same length as the corresponding **Ranges** vector.

**TargetDir** — Target direction for vehicle

scalar

Target direction for the vehicle, specified as a scalar in radians.
The forward direction of the vehicle is considered zero radians, with
positive angles measured counterclockwise. You can use the
**TargetDir** output from the Pure Pursuit block when
generating controls from a set of waypoints.

### Output

**SteerDir** — Steering direction for vehicle

scalar

Steering direction for the vehicle, specified as a scalar in radians. This obstacle-free direction is calculated based on the VFH+ algorithm. The forward direction of the vehicle is considered zero radians, with positive angles measured counterclockwise.

## Parameters

**Main**

**Number of angular sectors** — Number of bins used to create the histograms

`180`

(default) | scalar

Number of bins used to create the histograms, specified as a scalar. This parameter is nontunable. You can set this parameter only when the object is initialized.

**Range distance limits (m)** — Limits for range readings

`[0.05 2]`

(default) | two-element vector of scalars

Limits for range readings in meters, specified as a two-element vector of scalars. The range readings input are only considered if they fall within the distance limits. Use the lower distance limit to ignore false positives from poor sensor performance at lower ranges. Use the upper limit to ignore obstacles that are too far away from the vehicle.

**Histogram thresholds** — Thresholds for computing binary histogram

`[3 10]`

(default) | two-element vector of scalars

Thresholds for computing binary histogram, specified as a two-element vector of scalars. The algorithm uses these thresholds to compute the binary histogram from the polar obstacle density. Polar obstacle density values higher than the upper threshold are represented as occupied space (1) in the binary histogram. Values smaller than the lower threshold are represented as free space (0). Values that fall between the limits are set to the values of a previous computed binary histogram if one exists from previous iterations. If a previous histogram does not exist, the value is set as free space (0).

**vehicle radius (m)** — Radius of the vehicle

`0.1`

(default) | scalar

Radius of the vehicle, specified as a scalar in meters. This dimension defines the smallest circle that can circumscribe your vehicle. The vehicle radius is used to account for vehicle size when computing the obstacle-free direction.

**Safety distance (m)** — Safety distance around the vehicle

`0.1`

(default) | scalar

Safety distance left around the vehicle position in addiction to
**vehicle radius**, specified as a scalar in meters.
The vehicle radius and safety distance are used to compute the obstacle-free
direction.

**Minimum turning radius (m)** — Minimum turning radius at current speed

`0.1`

(default) | scalar

Minimum turning radius for the vehicle moving at its current speed, specified as a scalar in meters.

**Simulate using** — Specify type of simulation to run

`Code generation`

(default) | `Interpreted execution`

`Code generation`

— Simulate model using generated C code. The first time you run a simulation, Simulink^{®}generates C code for the block. The C code is reused for subsequent simulations, as long as the model does not change. This option requires additional startup time but the speed of the subsequent simulations is comparable to`Interpreted execution`

.`Interpreted execution`

— Simulate model using the MATLAB^{®}interpreter. This option shortens startup time but has a slower simulation speed than`Code generation`

. In this mode, you can debug the source code of the block.

**Tunable:** No

**Cost Function Weights**

**Target direction weight** — Cost function weight for target direction

`5`

(default) | scalar

Cost function weight for moving toward the target direction, specified as
a scalar. To follow a target direction, set this weight to be higher than
the sum of **Current direction weight** and
**Previous direction weight**. To ignore the target
direction cost, set this weight to `0`

.

**Current direction weight** — Cost function weight for current direction

`2`

(default) | scalar

Cost function weight for moving the vehicle in the current heading
direction, specified as a scalar. Higher values of this weight produce
efficient paths. To ignore the current direction cost, set this weight to
`0`

.

**Previous direction weight** — Cost function weight for previous direction

`2`

(default) | scalar

Cost function weight for moving in the previously selected steering
direction, specified as a scalar. Higher values of this weight produce
smoother paths. To ignore the previous direction cost, set this weight to
`0`

.

## Algorithms

### Vector Field Histogram

The block uses the VFH+ algorithm to compute the obstacle-free direction. First, the algorithm takes the ranges and angles from range sensor data and builds a polar histogram for obstacle locations. Then, it uses the input histogram thresholds to calculate a binary histogram that indicates occupied and free directions. Finally, the algorithm computes a masked histogram, which is computed from the binary histogram based on the minimum turning radius of the vehicle.

The algorithm selects multiple steering directions based on the open space and possible driving directions. A cost function, with weights corresponding to the previous, current, and target directions, calculates the cost of different possible directions. The algorithm then returns an obstacle-free direction with minimal cost. Using the obstacle-free direction, you can input commands to move your vehicle in that direction.

To use this block for your own application and environment, you must tune the algorithm
parameters. Parameter values depend on the type of vehicle, the range sensor, and
the hardware you use. For more information on the VFH algorithm, see `controllerVFH`

.

## Extended Capabilities

### C/C++ Code Generation

Generate C and C++ code using Simulink® Coder™.

## Version History

**Introduced in R2019b**

## MATLAB 命令

您点击的链接对应于以下 MATLAB 命令：

请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)