This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
How to get gyroscope data in pythonista?
WoodBridge last edited by ccc
I want to get the acceleration values and angular velocity values of the device via Pythonista. Through the motion module, I can get the acceleration. But how do I get the value of the angular speed (gyroscope value)?
And I post the documentation of
motion — Motion Sensor Data on iOS The motion module allows you to access your iOS device’s motion sensor data (accelerometer, gyroscope, magnetometer). Functions in the motion module: motion.start_updates() Start monitoring the device’s motion sensors. You should balance this with a stop_updates() call to improve battery life. All the get... functions require that you call start_updates() first, otherwise, no meaningful data will be returned. motion.stop_updates() Stop monitoring the device’s motion sensors. motion.get_gravity() Return the gravity vector (x, y, z). motion.get_user_acceleration() Return the acceleration the user is giving to the device. The total acceleration is equal to the gravity vector returned from get_gravity() plus the user acceleration. motion.get_attitude() Return the attitude of the device (roll, pitch, yaw). motion.get_magnetic_field() Return the magnetic field vector with respect to the device (x, y, z, accuracy).
ccc last edited by
cvp last edited by cvp
@WoodBridge The Pythonista
motionmodule only gives a part of the gyroscopic data.
But iOS ObjectiveC CMMotionManager class gives full gyroscopic data.
Could you try this little script which allows you to select a photo in your camera roll and displays it as a 3D box that you can rotate in all directions with your finger. Check the code and you will see how to get rotation rate from gyroscopic data.
@ccc Thank you for your replay. But I can't find any port to get gyro data in pythonista in this link. On the other hand , I usually to get eular angle by fusion accl and gyro with mahony or kalman filter.
But I can't get gyro data in motion. (Motion module privide angle x, y ,z ).
cvp last edited by
@WoodBridge in the code, you find these lines and
# https://forum.omz-software.com/topic/3030 CMMotionManager = ObjCClass('CMMotionManager').alloc().init() #print(CMMotionManager.isDeviceMotionAvailable()) CMMotionManager.startGyroUpdates() while True: # EulerAngles is a SCNVector3 # The order of components in this vector matches the axes of rotation: # Pitch (the x component) is the rotation about the node’s x-axis. # Yaw (the y component) is the rotation about the node’s y-axis. # Roll (the z component) is the rotation about the node’s z-axis. #pitch += (random() - 0.5) * delta_ang #yaw += (random() - 0.5) * delta_ang #roll += (random() - 0.5) * delta_ang gyro_data = CMMotionManager.gyroData() if not gyro_data: #print('data not available (yet?)') continue # Using the custom struct here: rate = gyro_data.rotationRate(argtypes=, restype=self.CMRotationRate) # You can now access the struct's fields as x, y, z: roll = rate.z pitch = rate.x yaw = rate.y #print(rate.x, rate.y, rate.z)
@cvp I find the method you provided useful, but I think I need to spend some time validating it. I want to get both the original acceleration value and the gyroscope value. This way I can implement a lot of algorithm verification and testing with them.
cvp last edited by cvp
@WoodBridge please read Apple doc here CMMotionManager
@cvp said in How to get gyroscope data in pythonista?:
Thanks very much, It's very useful!