I am trying to build an application wherein I need only the device rotation values. I want the application support to be as low as possible, so my preference would be to read the values from Gyroscope first if the device has its hardware (iPhone 4) or get the values from Accelerometer (iPhone 3G & 3GS).
I would like to write a RotationManager class which would handle interacting with either Gyroscope or Accelerometer, its internal operation will be abstract for the rest of the application. How do I design the RotationManager class? What are the things that should be considered in order to build a good reusable RotationManager instance?
Thanks,
Raj
Apple's Core Motion framework already does that job for you. Using the CMMotionManager, you can opt to receive accelerometer and gyroscope events separately or register for combined device motion events that automatically uses all the hardware that is available on the user's device.
Related
From what I know iPhone 5/5C do not have the motion processor like 5S and newer phones have, but when I request the motion permission the default alert with Allow and Don't allow still appears, even if I check before if the motion is available for device with MotionManager.isDeviceMotionAvailable. I would expect the alert not to appear for 5 and 5C.
What am I doing wrong here? Does 5 and 5C actually support motion?
No, you are getting this wrong; isDeviceMotionAvailable detects the presence of a gyroscope and an accelerometer. It's actually available since iOS 4, which came out way before the M7 motion coprocessor inside the iPhone 5s.
From Apple Documentation:
The device-motion service is available if a device has both an accelerometer and a gyroscope.
As #the4kman said the device motion is available through accelerometer and a gyroscope.
But what I actually meant and needed in this case is the user's activity, which is available through the M7 processor that is installed on 5S and newer and to check if that is available on a device I did CMMotionActivityManager.isActivityAvailable()
I have been building on top of the iphone augmented reality framework found here
but sadly, on mobiles without gyro (namely the 3GS) it doesn't work (as it states.)
Does anyone know of a fix to make it work with the motion sensors and compass heading instead ? Or would anyone be so bounty-hungry to provide the codes to a such framework ?
I will need a way to either make the vectors work, and if it is not possible, I will need to push through and just use heading only.
CoreMotion do work in devices like 3GS. However, this Framework pARk is for devices with gyroscopes (Runtime Requirements: iPad 2 or iPhone 4 running iOS 5.0 or later)
Gyroscope is a fundamental piece of inertial navigation systems (INS) and thus without it you'll have a severe loss in precision.
Check the paper: "Usability of apple iPhones for inertial navigation systems" for a comparison of the performance of iPhone 3GS and iPhone 4. The author's conclusion is:
However, the tests show that even with the use of filters
it is challenging to build a precise INS using sensors from
common devices because of their inaccuracies and high
error rate. The results show that the iPhone 4 can provide
tolerable results for a short time, but then the deviation
becomes too high because of the error rate. Currently we are
implementing a multi-dimensional Kalman filter to examine
possible enhancements. Furthermore we try to improve the
system by using more sensors from the iPhone 4, e.g. light
sensors and camera.
I believe you should think your app to support only iPhone4 or newer.
I know some basic about iOS programming, now i want to connect my app to another non iphone device e.g. connecting to a bluetooth device that can control a light bulb on and off, or control any furnitures.
My question is, besides iOS xcode, what kind of program i need to learn in order to achieve my goal?
Is there any sources that i can learn from it?
For Bluetooth Low Energy devices, you can use the CoreBluetooth framework to access them.
For Classic Bluetooth devices or accessories that make use of the Dock connector, the protocols are not open, and joining the Made for iPhone (MFi) program is required. I do not suggest this for beginning.
My suggestion is to buy for example a Polar Heart Rate Belt that supports Bluetooth Low Energy. These use standard protocols. Sample code is available from Apple that shows how to read out the heart rate from such a device.
As soon as you have mastered the heart rate monitor example, a next step would be to acquire a programmable Bluetooth Low Energy chip (however, often, the development tools for those are rather expensive!). Those chips can be programmed with custom profiles to listen for Bluetooth Low Energy connections and then performing defined operations (lighting a LED) when writes to characteristics occur. So, you are not limited to heart rate monitors and similar devices.
Keywords that you can search for: GATT protocol, Bluetooth Low Energy, CoreBluetooth.
I know that it's a steep learning curve for beginners, but the area is pretty new. However, I can assure you that it's a fun area.
I also think that you should look in to embedded C programming for the slave device (Heart Rate Monitor)
You could get a tod Smart Beacon Development kit for ~$150 and then use BGScript to code the firmware to control the BLE device from your phone or pc. todhq.com for more info.
Do someone know, for each property of CMMotionmanager.deviceMotion and their subproperties, on what kind of hardware they are based on (magnetometer, accelerometer, gyroscope, ...) ?
My question is about HARDWARE, not software.
I need to know from which piece of hardware the CMMotionManager get its values to know on which kind of iPhone my CMMotionManager calls will work. And to write consequent text on my web site.
So what piece of hardware is use to build :
deviceMotion.attitude.roll
deviceMotion.attitude.pitch
deviceMotion.attitude.yaw
deviceMotion.rotationRate (sole gyroscope ? Iphone 4 / 4S with iOS4)
deviceMotion.gravity (sole accelerometer ? So it should work on all iPhones with iOS4)
deviceMotion.userAcceleration (sole accelerometer ? So it should work on all iPhones with iOS4)
deviceMotion.magneticFied (sole magnetometer ? Iphone 3GS / 4 / 4S with iOS4)
Update (hardware):
The deviceMotion property is only available on devices having both an accelerometer and a gyroscope. This is because its sub-properties are the result of a sensor fusion algorithm i.e. both signals are evaluated together in order to decrease the estimation errors. Especially gravity estimation on fast moved devices is still hard work when high precision is demanded (car navigation, satellite positioning,... face the same problems). Popular fusion algorithms are for instance the Kalman filter and derivatives but I guess the CMMotionManager's internal implementation is based on simpler and thus faster algorithms.
Given that, you have only the raw sensor data properties of CMMotionManger accelerometerData and gyroData that are related 1:1 to a sensor - and in case of iOS 5 magnetometerData. deviceMotion and all its sup-properties are the calculated result of the internal implementation of fusion algorithms.
Old answer:
iOS 4.x:
CMMotionManager supports gyroscope and accelerometer. It provides for isXxxAvailable and isXxxActive to query hardware capabilities and determine the status, e.g. accelerometerAvailable and accelerometerActive. Furtheron there is a simple but quite efficient sensor fusion algorithm called DeviceMotion if the device has an accelerometer and a gyroscope on board - compass is not needed and thus not used. Analog to the sensors you use deviceMotionAvailable and deviceMotionActive for getting information.
Magnetometer is only available via CLLocationManager.
I experienced sometimes trouble with deviceMotionActive when the app is getting to foreground again after suspending (got true although DeviceMotion was definitely stopped before).
iOS 5.x:
Magnetometer support is added to CMMotionManager and handled like the two other sensors.
General:
You can use CMMotionManager even on iPhone 3g (with iOS4). You don't have access to CMDeviceMotion but can query accelerometer updates. Thus you have to use low pass filtering to get a gravity estimation and it's far more worse than DeviceMotion.
You should not use the pre-iOS 4 interface UIAccelerometerDelegate.
See the reference
A CMMotionManager object is the gateway to the motion services
provided by iOS. These services provide an application with
accelerometer data, rotation-rate data, magnetometer data, and other
device-motion data such as attitude. These types of data originate
with a device’s accelerometers and (on some models) its magnetometer
and gyroscope.
I have an external device (some kind of sensor) that can do a measurement. This sensor can be connected to a PC via Bluetooth or USB cable, and it also comes with it's own software.
I want to develop an App for iPhone that will analyze the data that this sensor is measuring (for example creating a graph, calculating some equations etc.).
How can I make my iPhone to "recognize" this sensor, so the app will get the data that has been measured from the sensor?
Is there any manual which explains how to code this? Our preferred way of transferring the data is via Bluetooth, so there will be no need of using cables.
Thanks a lot!
You can't use Bluetooth to transfer data unless the device is custom designed in compliance with Apple's MFi program. Only those specially manufactured devices can be recognized by an iOS app.
You can use wifi for high bandwidth data, and perhaps audio for encoding low bandwidth data.
Not sure what kind of sensor you have but PASCO scientific has a Made For iPhone Bluetooth device called AirLink2 that works with their sensors. I don't think that could easily co-opt the device for your purposes ... but it might be possible. I mention this because there's an off chance that this would useful information. I am not trying to peddle hardware here ;-)