sensor_based_nav 2.0.1
sensor_based_nav: ^2.0.1 copied to clipboard
A Flutter package for sensor-based navigation using ONNX models.
Make predictions using a .onnx
model file directly in the Flutter app.
Key Files #
- onnx_model.dart
: Loads
model.onnxand provides a
predict()` function. sensor_based_nav_controller.dart
: Collects sensor data and triggers the prediction.
How It Works #
-
HardwareSensorService
provides sensor data (accelerometer, gyroscope, magnetometer). -
SensorBasedNavController
:- Collects 10 current sensor values (
_currentSensorSamples
) - Stores historical values (
_historicalBursts
) and past predictions (_historicalDeltas
) - Prediction Trigger: Once 10 samples are collected,
OnnxModel.predict()
is called with both current and historical data
[Code Reference] on GitLab: Sensor-Based-Navigation -> MainBranch - After prediction, old data stores are updated
- Data is updated every 100ms
- Collects 10 current sensor values (
-
The prediction result is displayed or used within the app.
-
Prerequisite: @ build.gradle
android { compileSdk = flutter.compileSdkVersion ndkVersion = "27.0.12077973" defaultConfig { minSdk = 24 targetSdk = 35 }
Usage #
-
Subscribe to predictions:
class _MyHomePageState extends State<MyHomePage> { String northing = "0", easting = "0", delta_h = "0"; final _controller = SensorBasedNavController.instance; @override void initState() { super.initState(); initModel(); startPrediction(); } Future<void> initModel() async { _controller.initialize(); } Future<void> startPrediction() async { _controller.predictions.listen((predictedValues) { setState(() { easting = predictedValues[0].toString(); northing = predictedValues[1].toString(); delta_h = predictedValues[2].toString(); }); }); } // UI Output Text('$easting, $northing, $delta_h'),
-
Add as dependency
dependencies: sensor_based_nav: 1.1.2
ONNX Runtime Setup for Release #
- Create or update the file:
android/app/proguard-rules.pro
and add the following lines:-keep class ai.onnxruntime.** { *; } -keep class com.microsoft.** { *; }
- Update your
build.gradle
file to include the ProGuard rules:configre your build.gradle file to use the proguard rules:
buildTypes {
release {
signingConfig = signingConfigs.debug
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}