zesage / motion_sensors Goto Github PK
View Code? Open in Web Editor NEWFlutter plugin for accessing the Android and iOS accelerometer gyroscope and magnetometer sensors.
License: Apache License 2.0
Flutter plugin for accessing the Android and iOS accelerometer gyroscope and magnetometer sensors.
License: Apache License 2.0
What went wrong:
The Android Gradle plugin supports only Kotlin Gradle plugin version 1.5.20 and higher.
The following dependencies do not satisfy the required version:
project ':motion_sensors' -> org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.50
Thank you for your work, it has been really helpful. Could you please tell me if there is a way we can change the sampling rate of the sensors? particularly accelerometer, if it is possible?
Hi! I am currently choosing which sensors package to use in a new application and I am confused as to what is the advantace of this package compared to the official sensors package?
I can see that here we also have the magnetometer, is there any other advantage?
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.0.4, on macOS 11.1 20C69 darwin-x64, locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.1)
[✓] VS Code (version 1.55.0)
[✓] Connected device (2 available)
Thank you for developing such a good plug-in. Could you test the example again? Maybe it is a new bug, thank you very much.
Please, could you add null safety support?
When awaiting setSensorUpdateInterval (as used in the line below), the plugin hangs forever and never returns. I have found the same behavior on both Android and IOS. Isnt it important to await this call to ensure the sensor update interval is set before the sensor is started?
motionSensors.setSensorUpdateInterval(MotionSensors.TYPE_USER_ACCELEROMETER, 20000);
Hello,
I need to detect when the user stands up and sit down on a chair. I was trying to use the orientation.y but I realized thats not the correct way to detect it.
How can I do it?
I appreciate the help!
Output:
[VERBOSE-2:shell.cc(1004)] The 'motion_sensors/accelerometer' channel sent a message from native to Flutter on a non-platform thread. Platform channel messages must be sent on the platform thread. Failure to do so may result in data loss or crashes, and must be fixed in the plugin or application code creating that channel.
See https://docs.flutter.dev/platform-integration/platform-channels#channels-and-platform-threading for more information.
This same warning is repeated for all sensor types; I've only included the accelerometer one here.
It seems like changing absoluteOrientationUpdateInterval
has no effect on Android.
At least myFunction
in motionSensors.absoluteOrientation.listen(myFunction);
is called rapidly regardless of the value I set in absoluteOrientationUpdateInterval
.
Tested on Android Emulator with API 29 and on real device running latest Android 10.
Adding motion_sensors to my pubspec and integrating the example into my code, I run into the following error when trying to build it
`FAILURE: Build failed with an exception.
Could not resolve all files for configuration ':motion_sensors:androidApis'.
Failed to transform android.jar to match attributes {artifactType=android-platform-attr, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
> Execution failed for PlatformAttrTransform: C:\Users\user\AppData\Local\Android\sdk\platforms\android-28\android.jar.
> C:\Users\user\AppData\Local\Android\sdk\platforms\android-28\android.jar
Run with --stacktrace option to get the stack trace.
Run with --info or --debug option to get more log output.
Run with --scan to get full insights.
BUILD FAILED in 2s
Exception: Gradle task assembleDebug failed with exit code 1`
Is there a way to determine whether a set update interval is accepted (accelerometer)? A way to get the maximum update interval? Is the expected dt varying from sample to sample? Is it possible to read a timestamp for each received data? I would assume a timer duration would be inaccurate.
Dear @zesage,
Thank you for creating a useful package.
I need to determine the rotation matrix according to the attitude of the device.
In iOS it is motionManager.deviceMotion.attitude.rotationMatrix
,
in there:
CMDeviceMotion deviceMotion
CMAttitude attitude
CMRotationMatrix rotationMatrix
Can you help me?
I am trying to build an app which will
1)capture accelerometer, gyroscope data
2)write the data into a file for 1 hour and after 1 hour send that file to the server without pressing any button
Now, I tried to define the timer class to perform that 1 hour countdown. But It didn't show the result.
Can anyone suggest me how can I write the accelerometer data for an hour into a file?
Since updating to Flutter 3.0, I've noticed that any forced quit in iOS (swipe up, exit app) triggers an exception. I've validated that this is isolated to the motion_sensors plugin by building a bare-bones app using the example code on pub.dev and doing the following:
For what it is worth, I've also noticed this same behavior when using the sensors_plus plugin. However, the flutter_sensors plugin does not exhibit this 'crash on exit' behavior'. I prefer motion_sensors to these plugins, however, for the easy access to the Absolute Orientation stream.
Below are my flutter doctor output and a crash log from TestFlight
[✓] Flutter (Channel stable, 3.0.5, on macOS 12.4 21F79 darwin-x64, locale
en-US)
• Flutter version 3.0.5 at /Users/sean/Documents/dev/sdk/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision f1875d570e (6 days ago), 2022-07-13 11:24:16 -0700
• Engine revision e85ea0e79c
• Dart version 2.17.6
• DevTools version 2.12.2
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
• Android SDK at /Users/sean/Library/Android/sdk
• Platform android-32, build-tools 33.0.0
• Java binary at: /Applications/Android
Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build
11.0.12+0-b1504.28-7817840)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• CocoaPods version 1.11.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build
11.0.12+0-b1504.28-7817840)
[✓] VS Code (version 1.69.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.44.0
[✓] Connected device (2 available)
• macOS (desktop) • macos • darwin-x64 • macOS 12.4 21F79 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 103.0.5060.114
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 19
Last Exception Backtrace:
0 CoreFoundation 0x1b1589288 __exceptionPreprocess + 220 (NSException.m:200)
1 libobjc.A.dylib 0x1ca283744 objc_exception_throw + 60 (objc-exception.mm:565)
2 Foundation 0x1b2e16360 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 204 (NSException.m:242)
3 Flutter 0x10119a56c 0x101188000 + 75116
4 motion_sensors 0x10103daf8 thunk for @escaping @callee_unowned @convention(block) (@unowned Swift.AnyObject?) -> () + 176 (<compiler-generated>:0)
5 motion_sensors 0x10103fe24 $s14motion_sensors21AttitudeStreamHandlerC8onListen13withArguments9eventSinkSo12FlutterErrorCSgypSg_yAJctFySo14CMDeviceMotionCSg_s0M0_pSgtcfU_ + 448 (SwiftMotionSensorsPlugin.swift:0)
6 motion_sensors 0x10103fe24 partial apply for closure #1 in AttitudeStreamHandler.onListen(withArguments:eventSink:) + 496 (<compiler-generated>:0)
7 motion_sensors 0x10103e1b4 thunk for @escaping @callee_guaranteed (@guaranteed CMGyroData?, @guaranteed Error?) -> () + 80 (<compiler-generated>:0)
8 Foundation 0x1b2d35c1c __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 24 (NSOperation.m:1545)
9 Foundation 0x1b2d47f94 -[NSBlockOperation main] + 104 (NSOperation.m:1564)
10 Foundation 0x1b2d20214 __NSOPERATION_IS_INVOKING_MAIN__ + 24 (NSOperation.m:2189)
11 Foundation 0x1b2d315dc -[NSOperation start] + 788 (NSOperation.m:2206)
12 Foundation 0x1b2d34c68 __NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION__ + 24 (NSOperation.m:2220)
13 Foundation 0x1b2d42e10 __NSOQSchedule_f + 184 (NSOperation.m:2231)
14 libdispatch.dylib 0x1b11ff830 _dispatch_block_async_invoke2 + 148 (queue.c:560)
15 libdispatch.dylib 0x1b11f0a30 _dispatch_client_callout + 20 (object.m:560)
16 libdispatch.dylib 0x1b11f3eec _dispatch_continuation_pop + 500 (inline_internal.h:2622)
17 libdispatch.dylib 0x1b11f35f0 _dispatch_async_redirect_invoke + 736 (queue.c:835)
18 libdispatch.dylib 0x1b1202164 _dispatch_root_queue_drain + 396 (inline_internal.h:0)
19 libdispatch.dylib 0x1b120296c _dispatch_worker_thread2 + 164 (queue.c:6935)
20 libsystem_pthread.dylib 0x222e48080 _pthread_wqthread + 228 (pthread.c:2612)
21 libsystem_pthread.dylib 0x222e47e5c start_wqthread + 8 (:-1)
When using motionSensors.orientation
or motionSensors.absoluteOrientation
to get pitch
, the value is the same if I move the device down or up. Therefore you cannot differentiate from up and down.
Measurements on ios:
device pointing up: pitch = 0
device pointing a little bit up: pitch = 1
device pointing straight, pitch = 1.57
device pointing a little bit down: pitch = 1
device pointing down: pitch = 1
Orientation
Absolute Orientation
Orientation (accelerometer + magnetometer)
it seem 3 of them are return orientation . But I am not sure what is the different between this three
Currently there is many fixes on maser branch but not published to pub.dev. Thus we can not ref it with version number.
FAILURE: Build failed with an exception.
user@Mac ~ % flutter doctor -v
[✓] Flutter (Channel stable, 3.19.6, on macOS 14.4.1 23E224 darwin-x64, locale
en-YE)
• Flutter version 3.19.6 on channel stable at
/Users/user/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 54e66469a9 (3 weeks ago), 2024-04-17 13:08:03 -0700
• Engine revision c4cd48e186
• Dart version 3.3.4
• DevTools version 2.31.1
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/user/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 15E204a
• CocoaPods version 1.15.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2023.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
[✓] VS Code (version 1.89.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.88.0
[✓] Connected device (3 available)
• sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 14 (API 34)
(emulator)
• macOS (desktop) • macos • darwin-x64 • macOS 14.4.1 23E224
darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome
124.0.6367.119
[✓] Network resources
• All expected network resources are available.
• No issues found!
Thanks for posting this package to pub.dev. I see you are keeping it current, which is great! Can you do the community the great favour of updating your package on pub.dev? I and other would be indebted.
Hey, thanks for the package!
How can I change the degree for orientation.x to use full 360? thanks for the help
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.