Changeset 876e42b in orbit


Ignore:
Timestamp:
12/30/13 13:23:09 (6 years ago)
Author:
Steve Castellotti <sc@…>
Branches:
master, Servo
Children:
bfa2ba1
Parents:
7f21a20
Message:
Location:
iOS/Orbit
Files:
16 added
6 edited

Legend:

Unmodified
Added
Removed
  • iOS/Orbit/Orbit/AppDelegate.h

    rab9d63b r876e42b  
    33//  Orbit 
    44// 
    5 //  Copyright (c) 2012 Puzzlebox Productions, LLC. All rights reserved. 
     5//  Copyright (c) 2012-2013 Puzzlebox Productions, LLC. All rights reserved. 
    66//  Originally created by Jonathon Horsman. 
    77// 
     
    1111 
    1212#import <UIKit/UIKit.h> 
     13#import <CoreMotion/CoreMotion.h> 
    1314#import "SignalConverter.h" 
    1415 
  • iOS/Orbit/Orbit/AppDelegate.m

    rde10cbc r876e42b  
    33//  Orbit 
    44// 
    5 //  Copyright (c) 2012 Puzzlebox Productions, LLC. All rights reserved. 
     5//  Copyright (c) 2012-2013 Puzzlebox Productions, LLC. All rights reserved. 
    66//  Originally created by Jonathon Horsman. 
    77// 
     
    1212#import "AppDelegate.h" 
    1313#import "SignalConverter.h" 
    14 #import "CorePlot-CocoaTouch.h" 
    1514 
    1615@implementation AppDelegate 
     
    5453} 
    5554 
     55//- (CMMotionManager *)motionManager 
     56//{ 
     57//   if (!motionManager) motionManager = [[CMMotionManager alloc] init]; 
     58//   return motionManager; 
     59//} 
     60 
    5661@end 
  • iOS/Orbit/Orbit/controllers/AdvancedViewController.h

    r0a45bc8 r876e42b  
    1111 
    1212#import <UIKit/UIKit.h> 
     13#import <CoreMotion/CoreMotion.h> 
     14 
     15double defaultControlYaw = 0.5; 
     16double defaultControlPitch = 0.5; 
     17double defaultControlThrottle = 0.5; 
     18double referenceTiltX = 0; 
     19double referenceTiltY = 0; 
    1320 
    1421@interface AdvancedViewController : UIViewController 
     
    4855- (IBAction)changeSwitchTiltSensorControlThrottle:(id)sender; 
    4956 
     57@property (strong, nonatomic) CMMotionManager *motionManager; 
     58 
     59 
    5060@end 
  • iOS/Orbit/Orbit/controllers/AdvancedViewController.m

    r7f21a20 r876e42b  
    1414#import "AppDelegate.h" 
    1515 
    16 @interface AdvancedViewController () 
    17  
    18 @end 
     16//@interface AdvancedViewController () 
     17// 
     18//@end 
    1919 
    2020@implementation AdvancedViewController { 
    21     SignalConverter *signalConverter; 
     21   SignalConverter *signalConverter; 
    2222} 
    2323 
     
    2626- (void)viewDidLoad 
    2727{ 
    28     [super viewDidLoad]; 
    29     AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 
    30     signalConverter = appDelegate.signalConverter; 
    31     
    32 //   UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Help Wanted" message:@"Please join our Open Source development community to help us port this feature! See link to Forums under Support tab" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
    33 //   [alert show]; 
    34       
     28   [super viewDidLoad]; 
     29   AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 
     30   signalConverter = appDelegate.signalConverter; 
     31    
     32   //   UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Help Wanted" message:@"Please join our Open Source development community to help us port this feature! See link to Forums under Support tab" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
     33   //   [alert show]; 
     34    
     35   self.motionManager = [[CMMotionManager alloc] init]; 
     36   self.motionManager.accelerometerUpdateInterval = .2; 
     37   self.motionManager.gyroUpdateInterval = .2; 
     38    
     39   [self.motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue] 
     40                                            withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) { 
     41                                               [self outputAccelertionData:accelerometerData.acceleration]; 
     42                                               if(error){ 
     43                                                  NSLog(@"%@", error); 
     44                                               } 
     45                                            }]; 
     46    
     47   [self.motionManager startGyroUpdatesToQueue:[NSOperationQueue currentQueue] 
     48                                   withHandler:^(CMGyroData *gyroData, NSError *error) { 
     49                                      [self outputRotationData:gyroData.rotationRate]; 
     50                                   }]; 
     51    
    3552} 
    3653 
    3754- (IBAction) resetButtonPressed:(id)button 
    3855{ 
    39    pitch.value = 0.5; 
    40    yaw.value = 0.5; 
    41    throttle.value = 0.5; 
     56   pitch.value = defaultControlPitch; 
     57   yaw.value = defaultControlYaw; 
     58   throttle.value = defaultControlThrottle; 
    4259   NSString *zero = @"0%"; 
    4360   throttlePercent.text = zero; 
     
    4966- (IBAction) pitchChanged:(id) sender 
    5067{ 
    51     pitchPercent.text = [self percentStringFromSlider:pitch]; 
    52     [self adjustValues]; 
     68   pitchPercent.text = [self percentStringFromSlider:pitch]; 
     69   [self adjustValues]; 
    5370} 
    5471 
    5572- (IBAction) yawChanged:(id) sender 
    5673{ 
    57     yawPercent.text = [self percentStringFromSlider:yaw]; 
    58     [self adjustValues]; 
     74   yawPercent.text = [self percentStringFromSlider:yaw]; 
     75   [self adjustValues]; 
    5976} 
    6077 
    6178- (IBAction) throttleChanged:(id) sender 
    6279{ 
    63     throttlePercent.text = [self percentStringFromSlider:throttle]; 
    64     [self adjustValues]; 
     80   throttlePercent.text = [self percentStringFromSlider:throttle]; 
     81   [self adjustValues]; 
    6582} 
    6683 
    6784- (NSString *) percentStringFromSlider:(UISlider *) slider 
    6885{ 
    69     return [NSString stringWithFormat:@"%i%%", (int)((slider.value - 0.5) * 200)]; // between -100% and 100% 
     86   return [NSString stringWithFormat:@"%i%%", (int)((slider.value - 0.5) * 200)]; // between -100% and 100% 
    7087} 
    7188 
    7289- (void) adjustValues 
    7390{ 
    74     [signalConverter setYaw:[self yawValue]throttle:[self throttleValue] pitch:[self pitchValue]]; 
     91   [signalConverter setYaw:[self yawValue]throttle:[self throttleValue] pitch:[self pitchValue]]; 
    7592} 
    7693 
    7794- (int) yawValue 
    7895{ 
    79     return round(yaw.value * 100); 
     96   return round(yaw.value * 100); 
    8097} 
    8198 
    8299- (int) pitchValue 
    83100{ 
    84     return round(pitch.value * 100); 
     101   return round(pitch.value * 100); 
    85102} 
    86103 
    87104- (int) throttleValue 
    88105{ 
    89     return round(throttle.value * 100); 
     106   return round(throttle.value * 100); 
    90107} 
    91108 
     
    96113 
    97114- (IBAction) forwardButtonPressed:(id)sender { 
    98    NSLog(@"DEBUG: forwardButtonPressed"); 
    99     
    100115   pitch.value = 0.8; 
    101116   yaw.value = 0.5; 
     
    106121 
    107122- (IBAction) leftButtonPressed:(id)sender { 
    108    NSLog(@"DEBUG: leftButtonPressed"); 
    109123   pitch.value = 0.5; 
    110124   yaw.value = 0.1; 
    111125   throttle.value = 0.5; 
    112126   [self adjustValues]; 
    113  
     127    
    114128} 
    115129 
    116130- (IBAction) rightButtonPressed:(id)sender { 
    117    NSLog(@"DEBUG: rightButtonPressed"); 
    118131   pitch.value = 0.5; 
    119132   yaw.value = 0.9; 
    120133   throttle.value = 0.5; 
    121134   [self adjustValues]; 
    122  
    123 } 
    124  
    125  
     135    
     136} 
    126137 
    127138- (IBAction)changeSwitchTiltSensorControl:(id)sender{ 
    128  
     139    
     140   // With thanks to Kyro Apps 
     141   // http://kyroapps.weebly.com/xcode-tutorial-452---uiswitch.html 
     142    
    129143   if([sender isOn]){ 
    130144      NSLog(@"DEBUG: Tilt Sensor Enabled"); 
     
    148162} 
    149163 
     164-(void)outputAccelertionData:(CMAcceleration)acceleration 
     165{ 
     166   // With thanks to NSCookbook 
     167   // http://nscookbook.com/2013/03/ios-programming-recipe-19-using-core-motion-to-access-gyro-and-accelerometer/ 
     168    
     169   //   // Sensor.TYPE_GRAVITY 
     170   //   if (checkBoxTiltSensorControlThrottle.isChecked()) { 
     171   //      seekBarThrottle.setProgress(defaultControlThrottle - (int) ((tiltX * 2) - (referenceTiltX * 2))); 
     172   //   } else { 
     173   //      seekBarYaw.setProgress(defaultControlYaw + (int) (tiltY - referenceTiltY)); 
     174   //      seekBarPitch.setProgress(defaultControlPitch + (int) (tiltX - referenceTiltX)); 
     175   //   } 
     176    
     177   double tiltX = acceleration.x; 
     178   double tiltY = acceleration.y * -1;  // invert the Y axis so that negative values equal left 
     179    
     180   NSLog(@"DEBUG: tiltX:%f tiltY:%f", tiltX, tiltY); 
     181 
     182   double newYaw = defaultControlYaw + (tiltX - referenceTiltX); 
     183   double newPitch = defaultControlPitch - (tiltY - referenceTiltY); 
     184    
     185   NSLog(@"DEBUG: yaw:%f pitch:%f", yaw.value, pitch.value); 
     186   NSLog(@"DEBUG: newYaw:%f newPitch:%f", newYaw, newPitch); 
     187    
     188   yaw.value = newYaw; 
     189   pitch.value = newPitch; 
     190    
     191   [self adjustValues]; 
     192    
     193} 
     194 
     195-(void)outputRotationData:(CMRotationRate)rotation 
     196{ 
     197    
     198} 
     199 
     200- (void)didReceiveMemoryWarning 
     201{ 
     202   [super didReceiveMemoryWarning]; 
     203   // Dispose of any resources that can be recreated. 
     204} 
     205 
     206 
    150207@end 
  • iOS/Orbit/orbit.xcodeproj/project.pbxproj

    r274a89d r876e42b  
    3838                28F901301799436F003FB5ED /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 28F9012F1799436F003FB5ED /* CoreBluetooth.framework */; }; 
    3939                28F90133179973EC003FB5ED /* AudioGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 28F90132179973EC003FB5ED /* AudioGenerator.m */; }; 
     40                5218A688187157F5003DDE17 /* CoreMotion.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5218A687187157F5003DDE17 /* CoreMotion.framework */; }; 
    4041                524B4A3D17AF6E72009076BA /* step05-4.html in Resources */ = {isa = PBXBuildFile; fileRef = 524B4A3C17AF6E72009076BA /* step05-4.html */; }; 
    4142                5255A29017CAEA1C00AD4349 /* tab_welcome-30x30.png in Resources */ = {isa = PBXBuildFile; fileRef = 5255A28E17CAEA1C00AD4349 /* tab_welcome-30x30.png */; }; 
     
    159160                28F90131179973EC003FB5ED /* AudioGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AudioGenerator.h; sourceTree = "<group>"; }; 
    160161                28F90132179973EC003FB5ED /* AudioGenerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AudioGenerator.m; sourceTree = "<group>"; }; 
     162                5218A687187157F5003DDE17 /* CoreMotion.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMotion.framework; path = System/Library/Frameworks/CoreMotion.framework; sourceTree = SDKROOT; }; 
    161163                524B4A3C17AF6E72009076BA /* step05-4.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = "step05-4.html"; path = "tutorial/step05-4.html"; sourceTree = "<group>"; }; 
    162164                5255A28E17CAEA1C00AD4349 /* tab_welcome-30x30.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "tab_welcome-30x30.png"; sourceTree = "<group>"; }; 
     
    315317                        buildActionMask = 2147483647; 
    316318                        files = ( 
     319                                2815BC15167F496C00F7E6DA /* QuartzCore.framework in Frameworks */, 
     320                                5218A688187157F5003DDE17 /* CoreMotion.framework in Frameworks */, 
    317321                                282B687517ABEE33003DA675 /* AVFoundation.framework in Frameworks */, 
    318322                                286608E417A7D40F003FA806 /* AudioToolbox.framework in Frameworks */, 
    319323                                28F901301799436F003FB5ED /* CoreBluetooth.framework in Frameworks */, 
    320324                                52922BA817004D1400A39146 /* libCorePlot-CocoaTouch.a in Frameworks */, 
    321                                 2815BC15167F496C00F7E6DA /* QuartzCore.framework in Frameworks */, 
    322325                                2815BC13167F48BB00F7E6DA /* libTGAccessory.a in Frameworks */, 
    323326                                2815BC0E167F42F500F7E6DA /* Accelerate.framework in Frameworks */, 
     
    416419                        isa = PBXGroup; 
    417420                        children = ( 
     421                                28174C83167F30C400104752 /* AVFoundation.framework */, 
     422                                28174C64167F2EA900104752 /* CoreGraphics.framework */, 
     423                                5218A687187157F5003DDE17 /* CoreMotion.framework */, 
    418424                                2815BC0C167F42F500F7E6DA /* Accelerate.framework */, 
    419425                                2815BC0D167F42F500F7E6DA /* ExternalAccessory.framework */, 
    420                                 28174C83167F30C400104752 /* AVFoundation.framework */, 
    421426                                28174C60167F2EA900104752 /* UIKit.framework */, 
    422427                                28174C62167F2EA900104752 /* Foundation.framework */, 
    423                                 28174C64167F2EA900104752 /* CoreGraphics.framework */, 
    424428                        ); 
    425429                        name = Frameworks; 
     
    853857                        isa = XCBuildConfiguration; 
    854858                        buildSettings = { 
     859                                FRAMEWORK_SEARCH_PATHS = ( 
     860                                        "$(inherited)", 
     861                                        /Users/sc/development/orbit/iOS/Orbit, 
     862                                ); 
    855863                                GCC_PRECOMPILE_PREFIX_HEADER = YES; 
    856864                                GCC_PREFIX_HEADER = "Orbit/Orbit-Prefix.pch"; 
     
    874882                        isa = XCBuildConfiguration; 
    875883                        buildSettings = { 
     884                                FRAMEWORK_SEARCH_PATHS = ( 
     885                                        "$(inherited)", 
     886                                        /Users/sc/development/orbit/iOS/Orbit, 
     887                                ); 
    876888                                GCC_PRECOMPILE_PREFIX_HEADER = YES; 
    877889                                GCC_PREFIX_HEADER = "Orbit/Orbit-Prefix.pch"; 
Note: See TracChangeset for help on using the changeset viewer.