Permalink
Browse files

Hackathon version

  • Loading branch information...
ngs committed Jul 14, 2014
1 parent 6d83247 commit 35f535a186b37a7c638e23d92b25f48a329be9fa
@@ -167,6 +167,11 @@
attributes = {
LastUpgradeCheck = 0460;
ORGANIZATIONNAME = Romotive;
TargetAttributes = {
942AC67F16E81A520062CA8A = {
DevelopmentTeam = 3Y8APYUG2G;
};
};
};
buildConfigurationList = 942AC67B16E81A520062CA8A /* Build configuration list for PBXProject "HelloRomo" */;
compatibilityVersion = "Xcode 3.2";
@@ -286,6 +291,7 @@
942AC6A416E81A520062CA8A /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "iPhone Developer";
FRAMEWORK_SEARCH_PATHS = (
"$(SRCROOT)/../../frameworks/**",
"$(inherited)",
@@ -306,6 +312,7 @@
942AC6A516E81A520062CA8A /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "iPhone Developer";
FRAMEWORK_SEARCH_PATHS = (
"$(SRCROOT)/../../frameworks/**",
"$(inherited)",
View
@@ -11,39 +11,54 @@ @implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:nil bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[ViewController alloc] initWithNibName:nil bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
NSLog(@"%@", self);
[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert];
return YES;
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[self.viewController startLaughing];
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSLog(@"%@", deviceToken);
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
NSLog(@"%@", error);
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end
@@ -9,7 +9,7 @@
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.Romotive.${PRODUCT_NAME:rfc1034identifier}</string>
<string>io.ngs.Romotive.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
@@ -11,7 +11,12 @@
@property (nonatomic, strong) RMCoreRobotRomo3 *Romo3;
@property (nonatomic, strong) RMCharacter *Romo;
@property (nonatomic, assign) BOOL laughing;
@property (nonatomic, assign) BOOL tilting;
@property (nonatomic, assign) BOOL tiltFront;
@property (nonatomic, strong) NSTimer *laughTimer;
- (void)addGestureRecognizers;
- (void)startLaughing;
@end
View
@@ -10,99 +10,126 @@ @implementation ViewController
#pragma mark - View Management
- (void)viewDidLoad
{
[super viewDidLoad];
// To receive messages when Robots connect & disconnect, set RMCore's delegate to self
[RMCore setDelegate:self];
// Grab a shared instance of the Romo character
self.Romo = [RMCharacter Romo];
[RMCore setDelegate:self];
[self addGestureRecognizers];
[super viewDidLoad];
// To receive messages when Robots connect & disconnect, set RMCore's delegate to self
[RMCore setDelegate:self];
// Grab a shared instance of the Romo character
self.Romo = [RMCharacter Romo];
[RMCore setDelegate:self];
[self addGestureRecognizers];
}
- (void)viewWillAppear:(BOOL)animated
{
// Add Romo's face to self.view whenever the view will appear
[self.Romo addToSuperview:self.view];
// Add Romo's face to self.view whenever the view will appear
[self.Romo addToSuperview:self.view];
}
#pragma mark - RMCoreDelegate Methods
- (void)robotDidConnect:(RMCoreRobot *)robot
{
// Currently the only kind of robot is Romo3, so this is just future-proofing
if ([robot isKindOfClass:[RMCoreRobotRomo3 class]]) {
self.Romo3 = (RMCoreRobotRomo3 *)robot;
// Change Romo's LED to be solid at 80% power
[self.Romo3.LEDs setSolidWithBrightness:0.8];
// When we plug Romo in, he get's excited!
self.Romo.expression = RMCharacterExpressionExcited;
}
// Currently the only kind of robot is Romo3, so this is just future-proofing
if ([robot isKindOfClass:[RMCoreRobotRomo3 class]]) {
self.Romo3 = (RMCoreRobotRomo3 *)robot;
// Change Romo's LED to be solid at 80% power
[self.Romo3.LEDs setSolidWithBrightness:0.8];
// When we plug Romo in, he get's excited!
self.Romo.expression = RMCharacterExpressionExcited;
self.laughing = NO;
self.tiltFront = YES;
}
}
- (void)robotDidDisconnect:(RMCoreRobot *)robot
{
if (robot == self.Romo3) {
self.Romo3 = nil;
// When we plug Romo in, he get's excited!
self.Romo.expression = RMCharacterExpressionSad;
}
if (robot == self.Romo3) {
self.Romo3 = nil;
// When we plug Romo in, he get's excited!
self.Romo.expression = RMCharacterExpressionChuckle;
}
}
- (void)startLaughing {
self.laughing = YES;
self.Romo.expression = RMCharacterExpressionChuckle;
[self laugh];
self.laughTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(laugh) userInfo:nil repeats:YES];
[self.Romo3 driveWithLeftMotorPower:-1.0 rightMotorPower:1.0];
}
- (void)stopLaughing {
self.laughing = NO;
[self.laughTimer invalidate];
self.laughTimer = nil;
}
- (void)laugh {
[self.Romo setExpression:RMCharacterExpressionChuckle];
if(!self.tilting) {
self.tiltFront = !self.tiltFront;
self.tilting = YES;
[self.Romo3 tiltToAngle:self.tiltFront ? self.Romo3.maximumHeadTiltAngle : -self.Romo3.maximumHeadTiltAngle completion:^(BOOL success) {
self.tilting = NO;
}];
}
}
#pragma mark - Gesture recognizers
- (void)addGestureRecognizers
{
// Let's start by adding some gesture recognizers with which to interact with Romo
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipedLeft:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeft];
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipedRight:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeRight];
UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipedUp:)];
swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
[self.view addGestureRecognizer:swipeUp];
UITapGestureRecognizer *tapReceived = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tappedScreen:)];
[self.view addGestureRecognizer:tapReceived];
// Let's start by adding some gesture recognizers with which to interact with Romo
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipedLeft:)];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeft];
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipedRight:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:swipeRight];
UISwipeGestureRecognizer *swipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipedUp:)];
swipeUp.direction = UISwipeGestureRecognizerDirectionUp;
[self.view addGestureRecognizer:swipeUp];
UITapGestureRecognizer *tapReceived = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tappedScreen:)];
[self.view addGestureRecognizer:tapReceived];
}
- (void)swipedLeft:(UIGestureRecognizer *)sender
{
// When the user swipes left, Romo will turn in a circle to his left
[self.Romo3 driveWithRadius:-1.0 speed:1.0];
// When the user swipes left, Romo will turn in a circle to his left
[self.Romo3 driveWithRadius:-1.0 speed:1.0];
}
- (void)swipedRight:(UIGestureRecognizer *)sender
{
// When the user swipes right, Romo will turn in a circle to his right
[self.Romo3 driveWithRadius:1.0 speed:1.0];
// When the user swipes right, Romo will turn in a circle to his right
[self.Romo3 driveWithRadius:1.0 speed:1.0];
}
// Swipe up to change Romo's emotion to some random emotion
- (void)swipedUp:(UIGestureRecognizer *)sender
{
int numberOfEmotions = 7;
// Choose a random emotion from 1 to numberOfEmotions
// That's different from the current emotion
RMCharacterEmotion randomEmotion = 1 + (arc4random() % numberOfEmotions);
self.Romo.emotion = randomEmotion;
// int numberOfEmotions = 7;
// Choose a random emotion from 1 to numberOfEmotions
// That's different from the current emotion
// RMCharacterEmotion randomEmotion = 1 + (arc4random() % numberOfEmotions);
//
// self.Romo.emotion = randomEmotion;
}
// Simply tap the screen to stop Romo
- (void)tappedScreen:(UIGestureRecognizer *)sender
{
[self.Romo3 stopDriving];
[self.Romo3 stopDriving];
}
@end

0 comments on commit 35f535a

Please sign in to comment.