Visual SLAM
| Related documentations |
|---|
| Map Manager |
| Tracker Coordinate System |
| Visual SLAM Learning Guide |
The Visual SLAM(Simultaneous Localization and Mapping) creates a map by scanning 3D space.
Please refer Visual SLAM Learning Guide to create a map more precisely while scanning 3D space.
Create Instants
Start / Stop Tracker
Start / Stop Map Creation & Map Saving
Set Rendering Options
Create Instants
>SlamViewController.swift
var cameraDevice:MasCameraDevice = MasCameraDevice() var sensorDevice:MasSensorDevice = MasSensorDevice() var trackingManager:MasTrackerManager = MasTrackerManager()
Start / Stop Tracker
To start / stop tracker, refer to the following code.
>SlamViewController.swift
@objc func resumeAR()
{
...
trackingManager.start(.TRACKER_TYPE_SLAM)
}
@objc func pauseAR()
{
trackingManager.stopTracker()
...
}
Start / Stop Map Creation & Map Saving
- To start a map generation, refer to the following code.
trackingManager.findSurface()
- To stop generating a map, refer to the following code.
trackingManager.quitFindingSurface()
- Saving map is only possible while tracking. Refer to the following code for the file storage location when you save the generated map data as a file.
>SlamViewController.swift
func getFilePath() -> String {
let documentPaths:[String] = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
let documentPath:String = documentPaths[0]
let contentsPath:String = "\(documentPath)/3DMap"
let fileManager:FileManager = FileManager.default
var isDir:ObjCBool = false
let exists = fileManager.fileExists(atPath: contentsPath, isDirectory: &isDir)
if exists == false {
try! fileManager.createDirectory(atPath: contentsPath, withIntermediateDirectories: true, attributes: [:])
}
let filePath:String = "\(contentsPath)/\(getDateForFileName())"
return filePath
}
Set Rendering Options
Feature points, SLAM initialization progress, and axis can be created with 'FeaturePoint', 'Axis' class. Refer to the following code.
>SlamViewController.swift
func startEngin() {
...
featurePoint = FeaturePoint()
axis = Axis()
...
}
override func glkView(_ view: GLKView, drawIn rect: CGRect) {
...
if let feature = featurePoint {
feature.draw(trackingManager: trackingManager, projectionMatrix: projectionMatrix)
}
glEnable(GLenum(GL_DEPTH_TEST))
let trackingCount:Int32 = result.getCount()
for i in stride(from: 0, to: trackingCount, by: 1) {
let trackable:MasTrackable = result.getTrackable(i)
axis.setProjectionMatrix(projectionMatrix: projectionMatrix)
axis.setPoseMatrix(poseMatrix: trackable.getPose())
axis.setTranslation(x: 0.0, y: 0.0, z: 0.0)
axis.setScale(x: 0.3, y: 0.3, z: 0.3)
axis.draw()
}
...
}
Preferably, use landscape left mode (screen orientation) for Visual SLAM.
