Example Matlab© code which loads odometry and laser data, projects laser ranges into 3D and optionally displays in Matlab© and saves to file.
- Download some sample input files such as: QuadTree_Odom.txt, QuadTree_Laser.txt and generatePointCloudFromAlog.m into the same folder (this is Sample 1 from the downloads section). QuadTree_Odom.txt and QuadTree_Laser.txt were both generated using the standalone version of uALogParser (see Windows and Linux examples).
- From the Matlab© Command Prompt type:
The code will fill in the input arguments with the correct values for this example.
- A figure with interpolated trajectory of the research platform.
- A second figure with the laser range data projected into 3D using the vehicle odometry.
- A plain text file called ptsWithRefl.txt in the current directory.
The text file has the following column format:
[ X Y Z R G B ]
R, G and B are 0-255 integer colour channels that have been generated from laser reflectance data.
The following details all generatePointCloudFromALog’s input and output arguments.
All functions use a simple verbosity paradigm to control code reporting:
0 – no text reporting (except errors and messages generated by Matlab©)
1 – essential text only (warnings, errors and messages generated by Matlab©)
2 – text reporting but no graphics
3 – fully verbose
This Matlab© structure contains all the information the code requires to load data in the following fields:
|-To indicate which input method to use:|
|useALog||false||Optional: Boolean to switch between invoking uAlogParser on ALogFile (
|-When useALog=true (uAlogParser invoked to extract data from ALog):|
|ALogFile||QuadTree_Alog.ALog||Required: Full or relative path (depending on useGlobalTime) for the input ALog file (uAlogParser must be pre-mexed and in the Matlab© path).|
|laserStream||LMS_LASER_2D_LEFT||Required: Laser stream to extract from ALog.|
|startTime||1225719873.50||Required: Start time of interest (see Events for examples).|
|endTime||1225719877.00||Required: End time of interest (see Events for examples).|
|useGlobalTime||true||Optional: Boolean to indicate if the supplied times are relative to global time (
|-When useALog=false (load from ASCII text files):|
|odomTxtFile||QuadTree_Odom.txt||Required: Full or relative path (depending on useGlobalTime) for input ASCII text Odometry file, such as those produced by uAlogParser, and available for download above.|
|laserTxtFile||QuadTree_Laser.txt||Required: Full or relative path (depending on useGlobalTime) for input ASCII text Laser file, such as those produced by uAlogParser, and available for download above.|
This Matlab© structure contains all the information the code requires in order to save data to either plain text or X3D XML format in the following fields:
|outputFileName||ptsWithRefl.txt||Optional: Output filename. If none supplied no output file will be generated.|
|colourMap||colormap(‘jet’)||Optional: To generate colours from the reflectance stream a colour mapping is required (see the code and Matlab© help for examples). If none is supplied no colours or output will be generated.|
|colourEncodingSelect||2||Optional: see below. If none supplied the default encoding is
|XML||false||Optional: Boolean to switch between generating an XML file compatible with VRML and its predecessor X3D (
|-If XML=false to indicate if ASCII text file should have a byte RGB format:|
|byteRGB||true||Optional: Boolean to switch between generating integers colour channels (in the range 0 – 255) (
colourEncodingSelect permits two options:
1 – True colour mapping with no attempt to use the supplied colour map spectrum evenly.
2 – Clips the top 0.1% reflectances to the same maximum value to allow a heavier use of the supplied colour map spectrum.
- Download a sample input ALog file such as: QuadTree_Alog.alog and generatePointCloudFromAlog.m into the same folder (this is Sample 1 from the Downloads section). Note: a previously Matlab© mexed uALogParser must be on the path for this example to work.
- Type the following into the Matlab© Command Prompt:
inputStruct = struct('useALog', true, ... 'ALogFile', 'QuadTree_Alog.alog', ... 'laserStream', 'LMS_LASER_2D_LEFT', ... 'startTime', 61.85, ... 'endTime', 65.35, ... 'useGlobalTime', false); outputStruct = struct('outputFileName', 'ptsWithRefl.x3d',... 'colourEncodingSelect', 1, ... 'colourMap', [0 0 0; 1 1 1], ... 'XML', true); verbosity = 3; generatePointCloudFromALog(inputStruct, outputStruct, verbosity);
The code will invoke uAlogParser on the downloaded ALog file, extract and display both Odometry and Laser data from the ALog in Matlab©, project the laser points into 3D, apply a grayscale colour mapping to the reflectance points, then output an X3D XML file. Viewing the X3D point cloud requires a X3D viewer; FreeWrl is available for Windows, Linux, macOS and Android.