Changeset 544a7a5 in orbit
- Timestamp:
- 01/17/15 14:56:43 (8 years ago)
- Branches:
- master
- Children:
- 0dfbfdb
- Parents:
- d98642d
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
iOS/Orbit/Orbit/controllers/AdvancedViewController.h
rc1a500d r544a7a5 13 13 14 14 #if TARGET_IPHONE_SIMULATOR 15 Boolean CORE_MOTION = false; 15 #import <CoreMotion/CoreMotion.h> 16 Boolean CORE_MOTION = false; 16 17 #else 17 #import <CoreMotion/CoreMotion.h>18 #define __CORE_MOTION__19 Boolean CORE_MOTION = true;18 #import <CoreMotion/CoreMotion.h> 19 #define __CORE_MOTION__ 20 Boolean CORE_MOTION = true; 20 21 #endif 21 22 … … 65 66 - (IBAction) changeSwitchTiltSensorControlThrottle:(id)sender; 66 67 67 #ifdef __CORE_MOTION__68 69 #endif68 //#ifdef __CORE_MOTION__ 69 @property (strong, nonatomic) CMMotionManager *motionManager; 70 //#endif 70 71 71 72 @end -
iOS/Orbit/Orbit/controllers/AdvancedViewController.m
r52de6cb r544a7a5 16 16 17 17 @implementation AdvancedViewController { 18 SignalConverter *signalConverter;18 SignalConverter *signalConverter; 19 19 } 20 20 … … 23 23 - (void)viewDidLoad 24 24 { 25 [super viewDidLoad]; 26 AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 27 signalConverter = appDelegate.signalConverter; 28 29 // 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]; 30 // [alert show]; 31 32 // Core Motion 33 @try { 34 self.motionManager = [[CMMotionManager alloc] init]; 35 self.motionManager.accelerometerUpdateInterval = .2; 36 self.motionManager.gyroUpdateInterval = .2; 37 // self.motionManager.accelerometerUpdateInterval = .1; 38 // self.motionManager.gyroUpdateInterval = .1; 39 40 [self.motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue] 41 withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) { 42 [self outputAccelertionData:accelerometerData.acceleration]; 43 if(error){ 44 NSLog(@"%@", error); 45 } 46 }]; 47 48 [self.motionManager startGyroUpdatesToQueue:[NSOperationQueue currentQueue] 49 withHandler:^(CMGyroData *gyroData, NSError *error) { 50 [self outputRotationData:gyroData.rotationRate]; 51 }]; 52 } 53 @catch (NSException * e) { 54 NSLog(@"Exception: %@", e); 55 } 56 57 25 [super viewDidLoad]; 26 AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 27 signalConverter = appDelegate.signalConverter; 28 29 // 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]; 30 // [alert show]; 31 32 // Core Motion 33 if (CORE_MOTION) { 34 @try { 35 self.motionManager = [[CMMotionManager alloc] init]; 36 self.motionManager.accelerometerUpdateInterval = .2; 37 self.motionManager.gyroUpdateInterval = .2; 38 // self.motionManager.accelerometerUpdateInterval = .1; 39 // self.motionManager.gyroUpdateInterval = .1; 40 41 [self.motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue] 42 withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) { 43 [self outputAccelertionData:accelerometerData.acceleration]; 44 if(error){ 45 NSLog(@"%@", error); 46 } 47 }]; 48 49 [self.motionManager startGyroUpdatesToQueue:[NSOperationQueue currentQueue] 50 withHandler:^(CMGyroData *gyroData, NSError *error) { 51 [self outputRotationData:gyroData.rotationRate]; 52 }]; 53 } 54 @catch (NSException * e) { 55 NSLog(@"Exception: %@", e); 56 } 57 } 58 58 59 } 59 60 60 61 - (void) resetValues:(id) sender 61 62 { 62 pitch.value = defaultControlPitch;63 yaw.value = defaultControlYaw;64 throttle.value = defaultControlThrottle;65 NSString *zero = @"0%";66 throttlePercent.text = zero;67 yawPercent.text = zero;68 pitchPercent.text = zero;69 [self adjustValues];63 pitch.value = defaultControlPitch; 64 yaw.value = defaultControlYaw; 65 throttle.value = defaultControlThrottle; 66 NSString *zero = @"0%"; 67 throttlePercent.text = zero; 68 yawPercent.text = zero; 69 pitchPercent.text = zero; 70 [self adjustValues]; 70 71 } 71 72 72 73 - (IBAction) resetButtonPressed:(id) button 73 74 { 74 [self resetValues:(button)];75 [self resetValues:(button)]; 75 76 } 76 77 77 78 - (IBAction) pitchChanged:(id) sender 78 79 { 79 pitchPercent.text = [self percentStringFromSlider:pitch];80 [self adjustValues];80 pitchPercent.text = [self percentStringFromSlider:pitch]; 81 [self adjustValues]; 81 82 } 82 83 83 84 - (IBAction) yawChanged:(id) sender 84 85 { 85 yawPercent.text = [self percentStringFromSlider:yaw];86 [self adjustValues];86 yawPercent.text = [self percentStringFromSlider:yaw]; 87 [self adjustValues]; 87 88 } 88 89 89 90 - (IBAction) throttleChanged:(id) sender 90 91 { 91 throttlePercent.text = [self percentStringFromSlider:throttle];92 [self adjustValues];92 throttlePercent.text = [self percentStringFromSlider:throttle]; 93 [self adjustValues]; 93 94 } 94 95 95 96 - (NSString *) percentStringFromSlider:(UISlider *) slider 96 97 { 97 return [NSString stringWithFormat:@"%i%%", (int)((slider.value - 0.5) * 200)]; // between -100% and 100%98 return [NSString stringWithFormat:@"%i%%", (int)((slider.value - 0.5) * 200)]; // between -100% and 100% 98 99 } 99 100 100 101 - (void) adjustValues 101 102 { 102 [signalConverter setControlSettings:[self yawValue]throttle:[self throttleValue] pitch:[self pitchValue]];103 [signalConverter setControlSettings:[self yawValue]throttle:[self throttleValue] pitch:[self pitchValue]]; 103 104 } 104 105 105 106 - (int) yawValue 106 107 { 107 // We subtract the current Yaw position from the maximum slider value108 // because smaller values instruct the helicopter to spin to the right109 // (clockwise if looking down from above) whereas intuitively moving110 // the slider to the left should cause it to spin left111 112 return round((yaw.maximumValue - yaw.value) * 100);108 // We subtract the current Yaw position from the maximum slider value 109 // because smaller values instruct the helicopter to spin to the right 110 // (clockwise if looking down from above) whereas intuitively moving 111 // the slider to the left should cause it to spin left 112 113 return round((yaw.maximumValue - yaw.value) * 100); 113 114 } 114 115 115 116 - (int) pitchValue 116 117 { 117 return round(pitch.value * 100);118 return round(pitch.value * 100); 118 119 } 119 120 120 121 - (int) throttleValue 121 122 { 122 return round(throttle.value * 100);123 return round(throttle.value * 100); 123 124 } 124 125 125 126 - (IBAction) hoverButtonPressed:(id)sender { 126 [self resetValues:(sender)];127 127 [self resetValues:(sender)]; 128 128 129 } 129 130 130 131 - (IBAction) forwardButtonPressed:(id)sender { 131 throttle.value = defaultControlThrottle;132 pitch.value = defaultControlPitch + 0.2;133 yaw.value = defaultControlYaw;134 [self adjustValues];135 132 throttle.value = defaultControlThrottle; 133 pitch.value = defaultControlPitch + 0.2; 134 yaw.value = defaultControlYaw; 135 [self adjustValues]; 136 136 137 } 137 138 138 139 - (IBAction) leftButtonPressed:(id)sender { 139 throttle.value = defaultControlThrottle;140 pitch.value = defaultControlPitch;141 yaw.value = defaultControlYaw - 0.5;142 [self adjustValues];143 140 throttle.value = defaultControlThrottle; 141 pitch.value = defaultControlPitch; 142 yaw.value = defaultControlYaw - 0.5; 143 [self adjustValues]; 144 144 145 } 145 146 146 147 - (IBAction) rightButtonPressed:(id)sender { 147 throttle.value = defaultControlThrottle;148 pitch.value = defaultControlPitch;149 yaw.value = defaultControlYaw + 0.3;150 [self adjustValues];151 148 throttle.value = defaultControlThrottle; 149 pitch.value = defaultControlPitch; 150 yaw.value = defaultControlYaw + 0.3; 151 [self adjustValues]; 152 152 153 } 153 154 154 155 - (IBAction)changeSwitchTiltSensorControl:(id)sender{ 155 156 // With thanks to Kyro Apps157 // http://kyroapps.weebly.com/xcode-tutorial-452---uiswitch.html158 159 if([sender isOn]){160 // NSLog(@"DEBUG: Tilt Sensor Enabled");161 [_switchTiltSensorControlThrottle setEnabled:YES];162 } else{163 // NSLog(@"DEBUG: Tilt Sensor Disabled");164 [_switchTiltSensorControlThrottle setOn:NO animated:YES];165 [_switchTiltSensorControlThrottle setEnabled:NO];166 referenceTiltX = 0;167 168 }169 156 157 // With thanks to Kyro Apps 158 // http://kyroapps.weebly.com/xcode-tutorial-452---uiswitch.html 159 160 if([sender isOn]){ 161 // NSLog(@"DEBUG: Tilt Sensor Enabled"); 162 [_switchTiltSensorControlThrottle setEnabled:YES]; 163 } else{ 164 // NSLog(@"DEBUG: Tilt Sensor Disabled"); 165 [_switchTiltSensorControlThrottle setOn:NO animated:YES]; 166 [_switchTiltSensorControlThrottle setEnabled:NO]; 167 referenceTiltX = 0; 168 referenceTiltY = 0; 169 } 170 170 171 } 171 172 172 173 - (IBAction)changeSwitchTiltSensorControlThrottle:(id)sender{ 173 174 if([sender isOn]){175 // NSLog(@"DEBUG: Throttle Tilt Sensor Enabled");176 referenceTiltY = 0;177 } else{178 // NSLog(@"DEBUG: Throttle Tilt Sensor Disabled");179 referenceTiltX = 0;180 181 }182 174 175 if([sender isOn]){ 176 // NSLog(@"DEBUG: Throttle Tilt Sensor Enabled"); 177 referenceTiltY = 0; 178 } else{ 179 // NSLog(@"DEBUG: Throttle Tilt Sensor Disabled"); 180 referenceTiltX = 0; 181 referenceTiltY = 0; 182 } 183 183 184 } 184 185 185 186 -(void)outputAccelertionData:(CMAcceleration)acceleration 186 187 { 187 // With thanks to NSCookbook188 // http://nscookbook.com/2013/03/ios-programming-recipe-19-using-core-motion-to-access-gyro-and-accelerometer/189 190 191 if ([_switchTiltSensorControl isOn]) {192 193 if (! [_switchTiltSensorControlThrottle isOn]) {194 195 // Pitch/Yaw Tilt Control196 197 double tiltX = acceleration.x;198 double tiltY = acceleration.y * -1; // invert the Y axis so that negative values equal left199 200 // NSLog(@"DEBUG: tiltX:%f tiltY:%f", tiltX, tiltY);201 202 if (referenceTiltX == 0) {203 referenceTiltX = tiltX;204 referenceTiltY = tiltY;205 }206 207 double newYaw = defaultControlYaw + (tiltX - referenceTiltX);208 double newPitch = defaultControlPitch - (tiltY - referenceTiltY);209 210 // NSLog(@"DEBUG: yaw:%f pitch:%f", yaw.value, pitch.value);211 // NSLog(@"DEBUG: newYaw:%f newPitch:%f", newYaw, newPitch);212 213 // Filter changes below titleSensorMinimumThreshold214 if (((newYaw > yaw.value) && (newYaw - yaw.value > titleSensorMinimumThreshold)) ||215 ((newYaw < yaw.value) && (yaw.value - newYaw > titleSensorMinimumThreshold))) {216 217 yaw.value = newYaw;218 }219 220 if (((newPitch > pitch.value) && (newPitch - pitch.value > titleSensorMinimumThreshold)) ||221 ((newPitch < pitch.value) && (pitch.value - newPitch > titleSensorMinimumThreshold))) {222 pitch.value = newPitch;223 }224 225 } // Pitch/Yaw Tilt Control226 227 else {228 229 // Throttle Tilt Control230 231 double tiltY = acceleration.y * 1; // invert the Y axis so that negative values equal forward232 233 if (referenceTiltY == 0) {234 referenceTiltY = tiltY;235 }236 237 double newThrottle = defaultControlThrottle - (tiltY - referenceTiltY);238 239 if (((newThrottle > throttle.value) && (newThrottle - throttle.value > titleSensorMinimumThreshold)) ||240 ((newThrottle < throttle.value) && (throttle.value - newThrottle > titleSensorMinimumThreshold))) {241 throttle.value = newThrottle;242 }243 244 } // Throttle Tilt Control245 246 247 [self adjustValues];248 249 }250 188 // With thanks to NSCookbook 189 // http://nscookbook.com/2013/03/ios-programming-recipe-19-using-core-motion-to-access-gyro-and-accelerometer/ 190 191 192 if ([_switchTiltSensorControl isOn]) { 193 194 if (! [_switchTiltSensorControlThrottle isOn]) { 195 196 // Pitch/Yaw Tilt Control 197 198 double tiltX = acceleration.x; 199 double tiltY = acceleration.y * -1; // invert the Y axis so that negative values equal left 200 201 // NSLog(@"DEBUG: tiltX:%f tiltY:%f", tiltX, tiltY); 202 203 if (referenceTiltX == 0) { 204 referenceTiltX = tiltX; 205 referenceTiltY = tiltY; 206 } 207 208 double newYaw = defaultControlYaw + (tiltX - referenceTiltX); 209 double newPitch = defaultControlPitch - (tiltY - referenceTiltY); 210 211 // NSLog(@"DEBUG: yaw:%f pitch:%f", yaw.value, pitch.value); 212 // NSLog(@"DEBUG: newYaw:%f newPitch:%f", newYaw, newPitch); 213 214 // Filter changes below titleSensorMinimumThreshold 215 if (((newYaw > yaw.value) && (newYaw - yaw.value > titleSensorMinimumThreshold)) || 216 ((newYaw < yaw.value) && (yaw.value - newYaw > titleSensorMinimumThreshold))) { 217 218 yaw.value = newYaw; 219 } 220 221 if (((newPitch > pitch.value) && (newPitch - pitch.value > titleSensorMinimumThreshold)) || 222 ((newPitch < pitch.value) && (pitch.value - newPitch > titleSensorMinimumThreshold))) { 223 pitch.value = newPitch; 224 } 225 226 } // Pitch/Yaw Tilt Control 227 228 else { 229 230 // Throttle Tilt Control 231 232 double tiltY = acceleration.y * 1; // invert the Y axis so that negative values equal forward 233 234 if (referenceTiltY == 0) { 235 referenceTiltY = tiltY; 236 } 237 238 double newThrottle = defaultControlThrottle - (tiltY - referenceTiltY); 239 240 if (((newThrottle > throttle.value) && (newThrottle - throttle.value > titleSensorMinimumThreshold)) || 241 ((newThrottle < throttle.value) && (throttle.value - newThrottle > titleSensorMinimumThreshold))) { 242 throttle.value = newThrottle; 243 } 244 245 } // Throttle Tilt Control 246 247 248 [self adjustValues]; 249 250 } 251 251 252 } 252 253 253 254 -(void)outputRotationData:(CMRotationRate)rotation 254 255 { 255 256 256 257 } 257 258 258 259 - (void)didReceiveMemoryWarning 259 260 { 260 [super didReceiveMemoryWarning];261 // Dispose of any resources that can be recreated.261 [super didReceiveMemoryWarning]; 262 // Dispose of any resources that can be recreated. 262 263 } 263 264 -
python/Puzzlebox/Orbit/Design_Plugin_Orbit.py
r0d06822 r544a7a5 466 466 self.comboBoxInfraredModelName.addItem("") 467 467 self.comboBoxInfraredModelName.addItem("") 468 self.comboBoxInfraredModelName.addItem("") 468 469 self.verticalLayoutSessionProfile.addWidget(self.comboBoxInfraredModelName) 469 470 self.comboBoxInfraredPortSelect = QtGui.QComboBox(self.horizontalLayoutWidget) … … 563 564 self.comboBoxInfraredModelName.setItemText(1, QtGui.QApplication.translate("Form", "Audio Infrared Dongle", None, QtGui.QApplication.UnicodeUTF8)) 564 565 self.comboBoxInfraredModelName.setItemText(2, QtGui.QApplication.translate("Form", "Arduino Infrared Circuit", None, QtGui.QApplication.UnicodeUTF8)) 566 #self.comboBoxInfraredModelName.setItemText(3, QtGui.QApplication.translate("Form", "Mindfulness, Inc. Lotus", None, QtGui.QApplication.UnicodeUTF8)) 567 self.comboBoxInfraredModelName.setItemText(3, QtGui.QApplication.translate("Form", "Puzzlebox Bloom", None, QtGui.QApplication.UnicodeUTF8)) 565 568 self.comboBoxInfraredPortSelect.setItemText(0, QtGui.QApplication.translate("Form", "Select Port", None, QtGui.QApplication.UnicodeUTF8)) 566 569 self.pushButtonInfraredConnect.setText(QtGui.QApplication.translate("Form", "Connect", None, QtGui.QApplication.UnicodeUTF8)) -
python/Puzzlebox/Orbit/Plugin_Orbit.py
rd98642d r544a7a5 419 419 elif infraredDevice == 'Arduino Infrared Circuit': 420 420 mode = 'arduino' 421 #if infraredDevice == 'Mindfulness, Inc. Lotus': 422 #mode = 'pyramid' 423 if infraredDevice == 'Puzzlebox Bloom': 424 mode = 'bloom' 421 425 422 426 self.protocol = protocol_orbit.puzzlebox_jigsaw_protocol_orbit( \ … … 567 571 if os.path.exists('/dev/tty.usbmodemfd1222'): 568 572 devices.append('/dev/tty.usbmodemfd1222') 573 if os.path.exists('/dev/tty.usbmodem1411'): 574 devices.append('/dev/tty.usbmodem1411') 575 if os.path.exists('/dev/tty.usbmodem14231'): 576 devices.append('/dev/tty.usbmodem14231') 577 569 578 570 579 #if os.path.exists('/dev/tty.usbserial-A602050J'): … … 821 830 self.protocol.land() 822 831 832 elif infraredDevice == 'Mindfulness, Inc. Lotus': 833 834 if self.protocol != None: 835 self.protocol.setLotus(power) 836 837 elif infraredDevice == 'Puzzlebox Bloom': 838 839 if self.protocol != None: 840 self.protocol.setBloom(power) 823 841 824 842 else: … … 851 869 self.protocol.setPitch(self.pitch) 852 870 871 #elif infraredDevice == 'Mindfulness, Inc. Lotus': 872 873 #if self.protocol != None: 874 875 #self.protocol.setLotus(power) 876 877 878 elif infraredDevice == 'Puzzlebox Bloom': 879 880 if self.protocol != None: 881 882 self.protocol.setBloom(power) 883 853 884 854 885 ################################################################## -
python/Puzzlebox/Orbit/Protocol_Orbit.py
r1ad2c9e r544a7a5 50 50 DEFAULT_ARDUINO_BAUD_RATE = 9600 51 51 DEFAULT_PYRAMID_BAUD_RATE = 115200 52 DEFAULT_BLOOM_BAUD_RATE = 57600 52 53 53 54 ARDUINO_INITIALIZATION_TIME = 2 … … 111 112 if self.mode == 'pyramid': 112 113 baudrate = DEFAULT_PYRAMID_BAUD_RATE 114 rts_cts_flow_control = 'f' 115 elif self.mode == 'bloom': 116 baudrate = DEFAULT_BLOOM_BAUD_RATE 113 117 rts_cts_flow_control = 'f' 114 118 else: … … 184 188 185 189 186 self.land() 190 if self.mode != 'bloom': 191 self.land() 187 192 188 193 time.sleep(ARDUINO_INITIALIZATION_TIME) … … 354 359 self.command_queue.append(command) 355 360 #self.device.write(command) 356 357 361 362 363 ################################################################## 364 365 #def setLotus(self, power): 366 def setBloom(self, power): 367 368 value = self.padValue( str(power) ) 369 370 command = 'S%s' % value 371 372 if self.DEBUG: 373 print "--> [Protocol:Orbit] Sending Bloom Command:", 374 print command 375 376 self.command_queue.append(command) 377 378 358 379 ################################################################## 359 380
Note: See TracChangeset
for help on using the changeset viewer.