The Motions of Core MotionRob Caporetto (@rob_caporetto)www.rob-caporetto.com // github.com/robc
AgendaHistory of Motion on iOSWhat Core Motion IsUsing Core Motion in Your AppDemos & CodeFinal Points
A (brief) history of Motion
AccelerometerPresent on all iOS devicesMeasures Gravity & User AccelerationRead via UIAccelerometer
Accelerometers aren’t 100%         perfect
Not 100%?Can’t measure rotations in certain casesFast movements by the user result in instability
Enter the GyroscopeThe Gyroscope was one of the big additions with theiPhone 4
Enter the GyroscopeThe Gyroscope is available on  iPhone 4 & 4S  iPad 2 & 3  iPod touch 4th generation (2010)
Enter the GyroscopeGyroscope provides device’s rotation rateNot impacted by gravityCan suffer accuracy issues over time
Enter Core Motion
What is Core Motion?Framework to consolidate reading motion inputsAlso performs specialised processingProvides access to  ...
Device MotionDevice Motion contains  Attitude  Gravity  User Acceleration  Rotation Rate  Magnetic Field (iOS 5.0 only)
Core Motion in Action
Using Core MotionCreate an instance of CMMotionManagerTest for the necessary sourceKick it off - Push or Pull
PushCollects all Motion EventsRequires both a Queue & block for deliveryBest for Data Collection
Pull Doesn’t rely on a fixed schedule Lighter to implement (code & CPU) Best for Games & Interactive Apps
Reference FramesDefines the base position of the deviceSet when tracking enabled  Can custom the default under iOS 5Can be ...
Demo
Final Points
ResourcesSession 423 - WWDC 2010 & 2011Apple Samples  CoreMotionTeapot from WWDC 2010’s samples  pARk sample from develope...
Upcoming SlideShare
Loading in …5
×

Core Motion Intro (Melbourne Cocoaheads 20120412

1,653 views

Published on

An introduction to the Core Motion Frameworks on iOS covering some the basic steps needed to get accelerometer/gyroscope support in your apps.

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,653
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
37
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Background:\nOriginally, built a project at work late last year using CM.\nLot of interesting things & surprises when getting to grips with CM (hence the talk).\n\n
  • Just the break down\n- History, recap of what motion related capabilities iOS devices carry\n- What it is - just an overview of the goals of the framework\n- Using it - the steps with getting it up & running of course\n- Demos & Code - running through the Apple Samples - as my own original ideas were 100% wrong.\n
  • \n
  • Accelerometer has been with iOS since day one.\n\nGravity determines device orientation.\nAlways points down, so the orientation can be evaluated by how gravity is representation.\nExtracted from the readings via a LP filter.\n\nUser Acceleration determines movement of the device.\nVector of the direction of movement.\nExtracted by applying HP filter over the reading.\n\nUIAccelerometer API used to implement responder calls on a given View Controller.\n\n\n\n\n
  • \n
  • Can’t measure a rotation around gravity. (ie. place phone flat on a table, and spin it around - accelerometer won’t detect the change).\n\nDue to the HP filtering for movement, sometimes faster/larger movements are required to get the desired effect. This has an impact on the stability of the device because of the movements needed.\n
  • \n
  • \n
  • Because the gyro measures the rate, it’s not impacted by the force of gravity.\nThus, you’re able to get readings, regardless of the orientation of the device.\n\nEven when device is stationary, there’s some implicit rotation (because of the planet/etc), over time, this will magnify without tuning & adjustment.\n
  • \n
  • Added in iOS 4.0, has some newer options (covered later) with iOS 5.0\n\nOn iOS 4, we can access the accelerometer & the gyroscope (if supported).\nWith iOS 5, we can also access the magnetometer (again, if supported).\nThere isn’t any processing performed on this - so the problems mentioned earlier will apply.\n\nDevice Motion is constructed from the the raw inputs, which are then processed by a number of operations (filters/etc), returning a processed object.\n
  • Attitude - the device attitude in terms of pitch/yaw/roll\nGravity - the vector towards gravity (from the device’s reference frame)\nUser Acceleration - the vector of acceleration based on the user’s movement\nRotation Rate - the rate of rotation for the given axes (radians/sec)\nMag. Field - the details of the field, along with calibration strength\n
  • \n
  • The basic flow for using it in your application.\nWhen you need it, create the CMMotionManager object (don’t forget to link the CoreMotion framework!)\nCheck to see if the device supports the events (ie. no motion events on the simulator!)\nWhen starting events, you can PUSH or PULL…\n\nOnce you’re finished with your motion events, the reverse applies:\nStop Updates, then dispose of the Motion Manager.\n
  • This method delivers all motion events when active (at the given frequency).\nWhen starting the events, you need to supply an NSOperationQueue & a block\nThe Queue is used by CM to deliver events to.\nThe block contains your necessary handler code.\n\nThe reason it’s best for data collection is because it will deliver all motion samples, which also uses more CPU on the device.\n\nIf you’re running behind - best action is to discard incoming events to catch-up.\n
  • Pull is a more open technique - it doesn’t need a fixed queue (as you will fetch events when you require them).\n\nAs a result, there’s less CPU - as you’re only processing events as needed.\nIt also means you might need to configure your own timer to schedule the polling.\n
  • Reference frame is what is treated as a zero-point.\nThe default reference frame\n- Orients the Z axis vertically (with gravity pointing down)\n- Orients the X & Y axes horizontally \n\nUnder iOS 5, you can tweak this so that X/Y are orientated on True/Magnetic North\nThis does require a device running with a Magnetometer (thus, calibration may be necessary).\nAlso requires Location Services - in order to use your location to assist computing the field details.\n
  • Walkthrough two of Apple’s samples\n- CoreMotionTeapot (Part of the WWDC 2010 sample code)\n- pARK (Available on the developer site)\n
  • \n
  • The Core Motion sessions (both with the same Number!) from 2010 & 2011 are great to watch in sequence.\n\nThey cover the basics, also much going into way more depth.\nIt’s also worth playing with both sample apps - hopefully what I’ve covered is enough to get started\n
  • Core Motion Intro (Melbourne Cocoaheads 20120412

    1. 1. The Motions of Core MotionRob Caporetto (@rob_caporetto)www.rob-caporetto.com // github.com/robc
    2. 2. AgendaHistory of Motion on iOSWhat Core Motion IsUsing Core Motion in Your AppDemos & CodeFinal Points
    3. 3. A (brief) history of Motion
    4. 4. AccelerometerPresent on all iOS devicesMeasures Gravity & User AccelerationRead via UIAccelerometer
    5. 5. Accelerometers aren’t 100% perfect
    6. 6. Not 100%?Can’t measure rotations in certain casesFast movements by the user result in instability
    7. 7. Enter the GyroscopeThe Gyroscope was one of the big additions with theiPhone 4
    8. 8. Enter the GyroscopeThe Gyroscope is available on iPhone 4 & 4S iPad 2 & 3 iPod touch 4th generation (2010)
    9. 9. Enter the GyroscopeGyroscope provides device’s rotation rateNot impacted by gravityCan suffer accuracy issues over time
    10. 10. Enter Core Motion
    11. 11. What is Core Motion?Framework to consolidate reading motion inputsAlso performs specialised processingProvides access to Raw Data before Processing Device Motion after Processing
    12. 12. Device MotionDevice Motion contains Attitude Gravity User Acceleration Rotation Rate Magnetic Field (iOS 5.0 only)
    13. 13. Core Motion in Action
    14. 14. Using Core MotionCreate an instance of CMMotionManagerTest for the necessary sourceKick it off - Push or Pull
    15. 15. PushCollects all Motion EventsRequires both a Queue & block for deliveryBest for Data Collection
    16. 16. Pull Doesn’t rely on a fixed schedule Lighter to implement (code & CPU) Best for Games & Interactive Apps
    17. 17. Reference FramesDefines the base position of the deviceSet when tracking enabled Can custom the default under iOS 5Can be overridden at runtime
    18. 18. Demo
    19. 19. Final Points
    20. 20. ResourcesSession 423 - WWDC 2010 & 2011Apple Samples CoreMotionTeapot from WWDC 2010’s samples pARk sample from developer.apple.com

    ×