11. What is Core Motion?
Framework to consolidate reading motion inputs
Also performs specialised processing
Provides access to
Raw Data before Processing
Device Motion after Processing
12. Device Motion
Device Motion contains
Attitude
Gravity
User Acceleration
Rotation Rate
Magnetic Field (iOS 5.0 only)
20. Resources
Session 423 - WWDC 2010 & 2011
Apple Samples
CoreMotionTeapot from WWDC 2010’s samples
pARk sample from developer.apple.com
Notas do Editor
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