This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

transformScan

Transform laser scan based on relative pose

Syntax

transScan = transformScan(scan,relPose)
[transRanges,transAngles] = transformScan(ranges,angles,relPose)

Description

example

transScan = transformScan(scan,relPose) transforms the laser scan specified in scan by using the specified relative pose, relPose.

example

[transRanges,transAngles] = transformScan(ranges,angles,relPose) transforms the laser scan specified in ranges and angles by using the specified relative pose, relPose.

Examples

collapse all

Create a lidarScan object. Specify the ranges and angles as vectors.

refRanges = 5*ones(1,300);
refAngles = linspace(-pi/2,pi/2,300);
refScan = lidarScan(refRanges,refAngles);

Translate the laser scan by an [x y] offset of (0.5,0.2).

transScan = transformScan(refScan,[0.5 0.2 0]);

Rotate the laser scan by 20 degrees.

rotScan = transformScan(refScan,[0,0,deg2rad(20)]);

Use the matchScans function to find the relative transformation between two laser scans. Then transform the second laser scan into the coordinate frame of the first laser scan.

This example requires an Optimization Toolbox™ license.

Specify a laser scan as ranges and angles. Create a second laser scan that is offset from the first using transformScan. This transformation simulates a second laser scan being collected from a new coordinate frame.

refRanges = 5*ones(1,300);
refRanges(51:150) = 3*ones(1,100);
refAngles = linspace(-pi/2,pi/2,300);
offset = [0.5 0.2 0];
[currRanges,currAngles] = transformScan(refRanges,refAngles,offset);

Use scan matching to find the relative pose between the two laser scans. This pose is close to the specified offset. You must have an Optimization Toolbox™ license to use the matchScans function.

pose = matchScans(currRanges,currAngles,refRanges,refAngles,'SolverAlgorithm','fminunc')
pose = 1×3

   -0.5102   -0.1806   -0.0394

Transform the second scan to the coordinate frame of the first scan. Plot the two scans to see how they overlap.

[currRanges2,currAngles2] = transformScan(currRanges,currAngles,pose);
clf
polarplot(refAngles,refRanges,'or')
hold on
polarplot(currAngles2,currRanges2,'.b')
legend('First laser scan','Second laser scan')
hold off

Input Arguments

collapse all

Lidar scan readings, specified as a lidarScan object.

Range values from scan data, specified as a vector 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.

Angle values from scan data, specified as a vector 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.

Relative pose of current scan, specified as [x y theta], where [x y] is the translation in meters and theta is the rotation in radians.

Output Arguments

collapse all

Transformed lidar scan readings, specified as a lidarScan object.

Range values of transformed scan, returned as a vector in meters. These range values are distances from a sensor at specified transAngles. The vector is the same length as the corresponding transAngles vector.

Angle values of transformed scan, returned as a vector in radians. These angle values are the specific angles of the specified transRanges. The vector is the same length as the corresponding ranges vector.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Introduced in R2017a