Pythonista-Issues icon indicating copy to clipboard operation
Pythonista-Issues copied to clipboard

Motion module doesn’t work on iPod touch

Open Ivoah opened this issue 7 years ago • 5 comments

I’m using the latest TestFlight Pythonista beta (311016) on iOS 11.2.1.

After calling motion.start_updates() any motion.get_ function just returns (0.0, 0.0, 0.0).

Ivoah avatar Dec 21 '17 06:12 Ivoah

@Ivoah, I am using same beta and iOS as you. I am on latest iPad Pro 12.9' The below works for me

import ui
import motion


class MyClass(ui.View):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.make_view()
        self.update_interval = 1

    def make_view(self):
        motion.start_updates()

    def will_close(self):
        motion.stop_updates()

    def update(self):
        print(motion.get_gravity()) 

if __name__ == '__main__':
    f = (0, 0, 300, 400)
    v = MyClass(frame=f)
    v.present(style='sheet', animated=False)

Phuket2 avatar Dec 22 '17 08:12 Phuket2

I think the problem may be that the iPod touch doesn't have a magnetometer. At least that's what this StackOverflow post is suggesting, and it makes sense to me.

omz avatar Dec 22 '17 08:12 omz

@omz But the accelerometer and gyroscope should still be usable, right? As I understand it, currently all the functions are returning zeros, not just the one for the magnetic field.

dgelessus avatar Dec 22 '17 08:12 dgelessus

@dgelessus Core Motion combines the data of different sensors. The culprit seems to be the reference frame that is used for initializing the motion manager.

omz avatar Dec 22 '17 09:12 omz

@omz It would be nice to have this bug fixed. I especially bought an ipod touch 6 to enjoy pythonista... Until then, as little consolation we can use objc_util module to get discrete device orientation... https://github.com/njmcn/Pythonista/blob/master/facedown.py

francois-baptiste avatar Nov 08 '19 11:11 francois-baptiste