Documente Academic
Documente Profesional
Documente Cultură
iOS Sensors
Where Mobile Begins
Roadmap
100
Roadmap
Where Were Going
96
Teaser
What to Expect!
Compass Ball Game Air Level Navigation System Audio Sampler Digital Camera
92
Mobile Sensors
88
75.00%
50.00%
25.00%
0%
Speaker Microphone Accelerometer GPS Camera Gyroscope Magnetometer
84
75.00%
50.00%
Majority
25.00%
0%
Speaker Microphone Accelerometer GPS Camera Gyroscope Magnetometer
Delegate Pattern
80
Delegate Pattern
Quick Look
Delegate
Roadmap
76
Roadmap
Where Were Going
72
Light
Implementing a Camera
// setup image picker controller imagePickerController = [[UIImagePickerController alloc] init]; imagePickerController.allowsEditing = NO; imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera; imagePickerController.delegate = self;
Camera Demo
// grab photo as soon as it was taken -(void) imagePickerController:(UIImagePickerController *)picker / didFinishPickingMediaWithInfo:(NSDictionary *)info{ // captured image UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; // dismiss image picker [viewController dismissModalViewControllerAnimated:YES]; }
68
Sound
// get audio session AVAudioSession *audioSession = [AVAudioSession sharedInstance]; [audioSession setCategory:AVAudioSessionCategoryRecord error:nil]; [audioSession setActive:YES error:nil]; // some settings NSMutableDictionary *settings = [[NSMutableDictionary alloc] init]; [settings setValue:[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey]; [settings setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; [settings setValue:[NSNumber numberWithInt:2] forKey:AVNumberOfChannelsKey]; tmpRecording = [NSURL fileURLWithPath:[NSTemporaryDirectory() / stringByAppendingPathComponent:@"recording.caf"]]; // start recording audioRecorder = [[AVAudioRecorder alloc] initWithURL:tmpRecording settings:settings error:nil]; [audioRecorder setDelegate:self]; [audioRecorder prepareToRecord]; [audioRecorder recordForDuration:2.0]; // do when recording is finished - (void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag{ isRecording = NO; }
64
Sound
// get audio session AVAudioSession *audioSession = [AVAudioSession sharedInstance]; [audioSession setCategory:AVAudioSessionCategoryPlayback error:nil]; [audioSession setActive:YES error:nil]; tmpRecording = [NSURL fileURLWithPath:[NSTemporaryDirectory() / stringByAppendingPathComponent:@"recording.caf"]];
Sound Demo
// start playing AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:tmpRecording error:nil]; [player setDelegate:self]; [player prepareToPlay]; [player play]; // do when recording is finished - (void)audioRecorderDidFinishPlaying:(AVAudioRecorder *)recorder successfully: (BOOL)flag{ isPlaying = NO; }
60
Location
// create location manager locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // start location update [locationManager startUpdatingLocation];
Positioning Demo
// process position -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{ // access position float latitude = newLocation.coordinate.latitude; float longitude = newLocation.coordinate.longitude; // one position is enough [locationManager stopUpdatingLocation]; }
56
Magnetic Field
Implementing a Compass
// setup location manager locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; [locationManager startUpdatingHeading];
Compass Demo
// receive update of heading -(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading{ // device is pointing heading away from north float heading = manager.heading.magneticHeading; }
Roadmap
52
Roadmap
Where Were Going
48
Accelerometer
May the Force be with you
Force
in g-force
Rotation
in degrees
Accelerometer Demo
-1.0 0.0 0.0 -0.5
0.0 0.5
44
Accelerometer
May the Force be with you // enable accelerometer [[UIAccelerometer sharedAccelerometer] setDelegate:self]; // receive the acceleration values - (void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration { // move ball ball.x += acceleration.x * kBallSpeed; ball.y += acceleration.y * kBallSpeed; // rotate air level level.rotation = acceleration.y * 90; }
40
Gyroscope
Im spinnin around
Rotation Rate
in radians per second
Absolute Rotation
in radians by adding all rates to reference frame
Gyroscope Demo
0.0 0.0 0.78 0.0
0.0 0.0
36
Gyroscope
Im spinnin around
// create core motion manager motionManager = [[CMMotionManager alloc] init]; motionManager.gyroUpdateInterval = 1.0/60.0; [motionManager startGyroUpdates]; // frequently call the update method [self schedule:@selector(update:)]; // frequently read the gyro data -(void)update:(ccTime)dt { // absolute rotation rotationX += motionManager.gyroData.rotationRate.x; rotationY += motionManager.gyroData.rotationRate.y; // move ball ball.x += rotationX + kBallSpeed; ball.y += rotationY + kBallSpeed; // rotate air level level.rotation = rotationY * 180/PI; }
32
CoreMotion
Use this!
+
Raw data
Accelerometer + Gyroscope
28
CoreMotion
Use this!
// create core motion manager motionManager = [[CMMotionManager alloc] init]; motionManager.motionUpdateInterval = 1.0/60.0; [motionManager startMotionUpdates]; // frequently call the update method [self schedule:@selector(update:)];
20
CoreMotion
Use this!
// frequently read the gyro data -(void)update:(ccTime)dt { // absolute rotationX = rotationY = rotationZ = rotation motionManager.deviceMotion.attitude.pitch; motionManager.deviceMotion.attitude.yaw; motionManager.deviceMotion.attitude.roll;
CoreMotion Demo
// absolute gravity gravityX = motionManager.deviceMotion.gravity.x; gravityY = motionManager.deviceMotion.gravity.y; gravityZ = motionManager.deviceMotion.gravity.z; // user acceleration accelerationX = motionManager.deviceMotion.userAcceleration.x; accelerationY = motionManager.deviceMotion.userAcceleration.y; accelerationZ = motionManager.deviceMotion.userAcceleration.z; }
Roadmap
16
Roadmap
Where Were Going
10
Summary
Summary
What we learned!
Finding
Magnetic North
Download!
https://github.com/southdesign/SuperBall
Read!
Me!
Thomas Fankhauser
tommylefunk@googlemail.com
Thank you
You learned a lot!
Hire!
southdesign.de
Buy!
Beatfreak PianoTabs QuestionPad