- VSLAM-plugin-sample
This is a sample application to demonstrate how to use VSLAM service in RICOH THETA X. VSLAM service is a service that provides the ability to perform visual SLAM (Simultaneous Localization and Mapping) on the THETA X. This sample application is a simple application that uses VSLAM service to perform visual SLAM on the THETA X. The application is written in Kotlin and uses the Android Studio IDE.
- RICOH THETA X (firmware version 1.30 or later)
- Android Studio (Chipmunk | 2021.2.1)
- Android Gradle Plugin (version: 7.2.0)
- Gradle (version: 7.3.3)
- Pluginlibrary (version 3.0.4 or later)
The VSLAM-plugin-sample is composed of the following components:
- VSLAM-plugin-sample: The VSLAM-plugin-sample is a sample application that uses the VSLAM service.
- VSLAM: The VSLAM service is a service that provides VSLAM functions.
These components communicates with each other using the following sequence diagram:
The VSLAM service provides the AIDL files which defines the interfaces for the VSLAM-plugin-sample application. The VSLAM-plugin-sample application uses the interfaces defined in the AIDL files to communicate with the VSLAM service.
The AIDL files are located in the src/main/aidl directory.
IVSLAMService.aidl defines the interface for the VSLAM service. The VSLAM-plugin-sample application uses this interface to communicate with the VSLAM service.
IVSLAMServiceListener.aidl defines the interface for the VSLAM service callback. The VSLAM service uses this interface to communicate with the VSLAM-plugin-sample application.
To use camera feature, you need to add the following permissions to the AndroidManifest.xml file.
<uses-permission android:name="android.permission.CAMERA" />
To use VSLAM service, you need to add the following code to your application.
// Create a VSLAM service IVSLAMServiceListener instance.
private val vslamServiceListener = object : IVSLAMServiceListener.Stub() {
override fun onUpdatePossition(
x: Double, // camera position x
y: Double, // camera position y
z: Double, // camera position z
timestamp: Double, // timestamp [msec] of the frame
status: Int, // result of the tracking
numLands: Long, // number of the tracking landmarks
message: String? // error message
) {
// Handle the position of the camera.
}
}
// Create a VSLAM service ServiceConnection instance.
private val vslamServiceConnection = object : ServiceConnection {
override fun onServiceConnected(name: ComponentName, service: IBinder) {
// Get the VSLAM service instance.
vslamService = IVSLAMService.Stub.asInterface(service)
// Set the VSLAM service listener.
vslamService?.addListener(vslamServiceListener)
}
override fun onServiceDisconnected(name: ComponentName) {
vslamService = null
}
}
VSLAM service uses the shared memory. You need to prepare the shared memory for the VSLAM service.
// Create a shared memory.
val preview_w = 1024 // width of the preview image
val preview_h = 512 // height of the preview image
val shmemLen = preview_w * preview_h + 8 // 8 is the size of the timestamp.
val sharedMemory = SharedMemory.create("VSLAM", shmemLen)
To use VSLAM service, you need to bind the VSLAM service.
// Bind the VSLAM service.
private fun bindVSLAMService() {
val intent = Intent()
intent.setClassName("com.theta360.vslam", "com.theta360.vslam.VSLAMService")
bindService(intent, vslamServiceConnection, Context.BIND_AUTO_CREATE)
}
To use VSLAM service, you need to call the VSLAM service.
// Call the VSLAM service.
vslamService?.start(
"VSLAM-Sample", // name of the application
preview_w, // width of the frame
preview_h, // height of the frame
sharedMemory // shared memory
)
To conduct VSLAM, you need to process the frame by VSLAM service. RICOH THETA X has the interface to get the frame with timestamp from the camera. You can use the Camera.PreviewCallbackWithTime class to get the frame with timestamp. Preview size is 1024x512.
// Create a Camera.PreviewCallbackWithTime instance.
private val previewCallbackWithTime = object : Camera.PreviewCallbackWithTime {
override fun onPreviewFrame(
data: ByteArray, // frame data
camera: Camera, // camera instance
timestamp: Long // timestamp [msec] of the frame
) {
// ByteArray -> ByteBuffer
val tsbytes = ByteBuffer.allocate(8).putLong(timestamp).array()
// Fill the frame data to the shared memory.
val mappedMem = sharedMemory?.map(OsConstants.PROT_WRITE, 0, shmemLen)
val wrote = 0
mappedMem?.put(tsbytes, wrote, 8) // timestamp
mappedMem?.put(data, wrote, len); // frame data
SharedMemory.unmap(mappedMem!!)
// Process the frame by VSLAM service.
val result = vslamService?.frame(
wrote, // filled data size of the shared memory
shmemLen // size of the shared memory
)
}
}
To stop VSLAM service, you need to call the VSLAM service.
// Call the VSLAM service.
vslamService?.stop()
To unbind VSLAM service, you need to unbind the VSLAM service.
// Unbind the VSLAM service.
unbindService(vslamServiceConnection)
You agree to comply with all applicable export and import laws and regulations applicable to the jurisdiction in which the Software was obtained and in which it is used. Without limiting the foregoing, in connection with use of the Software, you shall not export or re-export the Software into any U.S. embargoed countries (currently including, but necessarily limited to, Crimea – Region of Ukraine, Cuba, Iran, North Korea, Sudan, and Syria) or to anyone on the U.S. Treasury Department's list of Specially Designated Nationals or the U.S. Department of Commerce Denied Person's List or Entity List. By using the Software, you represent and warrant that you are not located in any such country or on any such list. You also agree that you will not use the Software for any purposes prohibited by any applicable laws, including, without limitation, the development, design, manufacture, or production of missiles, nuclear, chemical, or biological weapons.
See LICENSE file.
By using the VSLAM-plugin-sample, you agree to the Terms of Service and the terms of LICENSE.
Copyright © 2022 Ricoh Company, Ltd.