%% Create a Vector Field Histogram Object and Visualize Data
% This example shows how to calculate a steering direction based on input laser scan data.
% Create a controllerVFH object. Set the UseLidarScan property to true.

vfh = controllerVFH;
vfh.UseLidarScan = true;

%
% Input laser scan data and target direction.

ranges = 10*ones(1,500);
ranges(1,225:275) = 1.0;
angles = linspace(-pi,pi,500);
targetDir = 0;

%
% Create a lidarScan object by specifying the ranges and angles.

scan = lidarScan(ranges,angles);

%
% Compute an obstacle-free steering direction.

steeringDir = vfh(scan,targetDir);

%
% Visualize the VectorFieldHistogram computation.

h = figure;
set(h,'Position',[50 50 800 400])
show(vfh)

% Copyright 2019 The MathWorks, Inc.