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.


    motion.get_magnetic_field()

    Pythonista
    9
    17
    13755
    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.
    • Omega0
      Omega0 last edited by

      With 1.6 in beta I wanted to bring up an unresolved issue from the past: motion.get_magnetic_field(). I wanted to start doing some tests with magnetism but I keep getting (0.0, 0.0, 0.0, 0) as the return value. Is there any chance this will be fixed in the final release of 1.6?

      1 Reply Last reply Reply Quote 0
      • dgelessus
        dgelessus last edited by

        What kind of device are you using, and does it actually have a magnetic field sensor? (Don't ask me which models have one. I didn't even know that there was such a thing in iDevices or that Pythonista supported it.)

        Do any of the other motion functions return meaningful values? Did you remember to call motion.start_updates()?

        1 Reply Last reply Reply Quote 0
        • Omega0
          Omega0 last edited by

          I'm using an iPhone 5s which does have a magnetic field sensor (and does work in other apps) and I did remeber to call motion.start_updates(), so those aren't the issues. I remeber seeing another thread about this a while ago and don't remember that being resolved so I think this is just a glitch in Pythonista.

          1 Reply Last reply Reply Quote 0
          • wradcliffe
            wradcliffe last edited by

            I just checked it on my ipad4 using 1.6

            >>> import motion
            >>> motion.get_magnetic_field()
            (0.0, 0.0, 0.0, 0)
            >>> motion.start_updates()
            >>> motion.get_magnetic_field()
            (-22.983476638793945, -37.92658233642578, -45.98847198486328, 1)
            >>> motion.stop_updates()
            
            1 Reply Last reply Reply Quote 0
            • zencuke
              zencuke last edited by

              I just tried on my brand new iPhone 6. Failed with:

              '''
              >>> import motion
              >>> motion.get_magnetic_field()
              (0.0, 0.0, 0.0, 0)
              >>> motion.start_updates()
              >>> motion.get_magnetic_field()
              (0.0,0.0,0.0,-1)
              '''
              

              Shouldn't magnetic field require location services. It used to. I can't figure out how to turn on location services for Pythonista.

              1 Reply Last reply Reply Quote 0
              • dgelessus
                dgelessus last edited by

                Settings app > Privacy > Location Services > turn on the switch for Pythonista

                1 Reply Last reply Reply Quote 0
                • Omega0
                  Omega0 last edited by

                  Enabled location services for Pythonista, still not working.

                  1 Reply Last reply Reply Quote 0
                  • polymerchm
                    polymerchm last edited by

                    Some more data points. I get (0.0, 0.0,0.0,0) before enabling updates as above, then (0.0,0.0,0.0,-1) using beta 1.6 on a Ipad Air 2. ioS 8.1.1.

                    Other motion.get_* calls work just fine.

                    The motion request preferences does not include Pythonista as an application requesting access.
                    OMZ needs to work on this. Not fixable by mere mortals.

                    1 Reply Last reply Reply Quote 0
                    • omz
                      omz last edited by

                      For 1.6 beta users: Could you try moving your device after enabling updates to calibrate the compass?

                      import motion
                      import time
                      
                      try:
                          motion.start_updates()
                          while True:
                              print motion.get_magnetic_field()
                              # if you get (0, 0, 0,...) here, try moving your device in circles... like you would in the Compass app
                              time.sleep(0.5)
                      finally:
                          motion.stop_updates()
                      
                      1 Reply Last reply Reply Quote 0
                      • polymerchm
                        polymerchm last edited by

                        After ~10 (0,0,0,-1) returns, it starts to give real values for x,y,z and 1 for the last parameter.

                        1 Reply Last reply Reply Quote 0
                        • omz
                          omz last edited by

                          Okay, I don't think there's more I can do. If you want to use the magnetometer data, you might want to check if the compass is calibrated first, and wait for calibration before using the data otherwise, something like this:

                          import motion
                          import time
                          
                          motion.start_updates()
                          while True:
                              m = motion.get_magnetic_field()
                              if m[3] != -1:
                                  break
                              print 'Please calibrate the compass by moving the device...'
                              time.sleep(0.5)
                          
                          print 'Magnetometer successfully calibrated'
                          print 'Data:', motion.get_magnetic_field()
                          
                          motion.stop_updates()
                          
                          1 Reply Last reply Reply Quote 0
                          • zencuke
                            zencuke last edited by

                            Just tried again. I get (0,0, 0.0, 0.0, -1) forever, i.e hundreds of iterations regardless of motion. Just as I did when I tried 4 days ago. I have calibrated the compass with the compass app. I can switch between Pythonista and the compass app seeing the compass app working but Pythonista still giving the same empty results.

                            I'm using iPhone 6 with iOS 8.1.1. As far as I remember I haven't been able to make get_magnetic_field to work since I upgraded from iPhone 5 to iPhone 6 several days ago. I'm pretty sure it worked on the iPhone 5 but I don't have it anymore to test.

                            Note: I just updated the infinite loop in my test script to print all 4 motion.get_<> function results. Everything prints normal (at least non zero and changing as the iPhone is rotated and tilted) except get_magnetic_field(); all this while jumping back and forth between Pythionista and the compass app.

                            I don't think it is a calibration problem. Also since the compass app works it is hard to imagine that it is a problem with my new iPhone 6 either. Note: I just downloaded 4 of the free compass apps. They all work; even while switching between them and the failing Pythonista script. So far 5 compass apps work every time and my Pythonista script fails every time.

                            I don't know if this helps but I did notice a repeatable state change. When I run the script from a cold start get_magnetic_fileld() reports 0 accuracy before the call to start_updates() and for the first call after the call to start_updates. Then it switches to -1. Rerunning the script always sees accuracy of -1 even after a call to stop_updates(). The only way I can get an accuracy of 0 again is to kill Pythonista and start over.

                            1 Reply Last reply Reply Quote 0
                            • brumm
                              brumm last edited by

                              hi, I tried the same (iphone 6 + pythonista 1.5). Compass app works, but in pythonista I only got (0.0, 0.0, 0.0, -1).

                              
                              import motion
                              import time
                              
                              t1 = time.time()
                              run = True 
                              motion.get_magnetic_field()
                              motion.start_updates()
                              while run:
                                m = motion.get_magnetic_field()
                                t2 = time.time()
                                if (t2 - t1) > 5.0:
                                  run = False
                                else:
                                  print m
                              motion.stop_updates()
                              
                              
                              1 Reply Last reply Reply Quote 0
                              • polymerchm
                                polymerchm last edited by

                                @omz, @Brumm, @zencuke:

                                omz's test ran fine on an Ipad Air 2 w/ 8.1.1. Sounds like an iPhone 6 issue.

                                1 Reply Last reply Reply Quote 0
                                • JonB
                                  JonB last edited by

                                  Ipad 2 has the same issue, w/ 1.5.

                                  1 Reply Last reply Reply Quote 0
                                  • zencuke
                                    zencuke last edited by

                                    @dgelessus - Sorry I wasn't clear. I know how to turn on Location services in general. I just don't see Pythonista in the list when I go there.

                                    Edit: When a script imports location a dialog pops up. After that Pythonista is in the location services list. Hmm. I wonder if this the normal behavior for all apps. I've never noticed it before but this may be the first time I checked location settings before attempting to use the app location functionality.

                                    1 Reply Last reply Reply Quote 0
                                    • ashook
                                      ashook last edited by

                                      Does anyone know of a workaround or fix for this problem? motion.get_magnetic_field() fails on both of my iOS devices: iPad mini 9.02, iPhone 5 9.02.

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