omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    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?

    Pythonista
    3
    8
    94
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • WoodBridge
      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 — 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 cvp 2 Replies Last reply Reply Quote 0
      • ccc
        ccc @WoodBridge last edited by

        https://forum.omz-software.com/topic/1031

        WoodBridge 1 Reply Last reply Reply Quote 0
        • cvp
          cvp @WoodBridge last edited by cvp

          @WoodBridge The Pythonista motion module 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.

          code is here

          WoodBridge 1 Reply Last reply Reply Quote 0
          • WoodBridge
            WoodBridge @ccc last edited by

            @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 1 Reply Last reply Reply Quote 0
            • cvp
              cvp @WoodBridge last edited by

              @WoodBridge in the code, you find these lines and CMMotionManager.gyroData()

              		# 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)
              
              WoodBridge 1 Reply Last reply Reply Quote 0
              • WoodBridge
                WoodBridge @cvp last edited by

                @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 1 Reply Last reply Reply Quote 0
                • cvp
                  cvp @WoodBridge last edited by cvp

                  @WoodBridge please read Apple doc here CMMotionManager

                  1 Reply Last reply Reply Quote 1
                  • WoodBridge
                    WoodBridge @cvp last edited by

                    @cvp said in How to get gyroscope data in pythonista?:

                    CMMotionManager

                    Thanks very much, It's very useful!

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post
                    Powered by NodeBB Forums | Contributors