Archive for the ‘How To’ Category

Programming Cozmo

Anki has been kind enough to let me play with their new Cozmo unit and explore their SDK. Cozmo is a wonderful device, developed by people who understand a lot of core principles about human interaction and engagement.

Cozmo is adorable. When it recognizes your face, it wriggles with happiness. It explores its environment. When it’s bored, it sets up a game to play with you. It can get “upset” and demand attention. It’s one of the most personable and delightful robots I’ve played with.

At its heart is a well-chosen collection of minimal elements. The unit can move around the room, with a 4-wheel/2-tread system. It includes an onboard forklift that can rise and fall, an OLED “face” that expresses emotion, and a camera system that ties into a computer vision system, which I believe is based on PIL, the Python Image Library. (Anki tells me that Cozmo’s vision system “does not use PIL or Python in any way, though the Python SDK interface uses PIL for decoding jpegs, drawing animations, etc.”)

Three lightweight blocks with easily-identified markings complete the Cozmo package, which Cozmo can tap, lift, stack, and roll.

Between its remarkable cuteness and its vision-based API, it’s a perfect system for introducing kids to programming. I was really excited to jump into the SDK and see how far I could push it.

Here is Anki’s “Hello World” code (more or less, I’ve tweaked it a little) from their first developer tutorial:

import sys
import cozmo

'''
Hello Human
Make Cozmo say 'Hello Human' in this simple
Cozmo SDK example program.
'''

def run(sdk_conn):
    robot = sdk_conn.wait_for_robot()
    robot.say_text("Hello Human").wait_for_completed()
    print("Success")

if __name__ == '__main__':
    cozmo.setup_basic_logging()    
    try:
        cozmo.connect(run)
    except cozmo.ConnectionError as err:
        sys.exit("Connection error 😬: %s" % err)

Although simple, this “Hello World” includes quite a lot of implementation details that can scare off young learners. For comparison, here’s the start of Apple’s tutorial on Swift “Learn to Code”:

screen-shot-2016-12-12-at-11-45-24-am

There’s such a huge difference here. In Apple’s case, everything that Byte (the main character) does is limited to easy-to-understand, simple calls. The entire implementation is abstracted away, and all that’s left are instructions and very directed calls, which the student can put together, re-order, and explore with immediate feedback.

In Anki’s code, you’re presented with material that’s dealing with set-up, exceptions, asynchronous calls, and more. That is a huge amount of information to put in front of a learner, and to then say “ignore all of this”. Cozmo is underserved by this approach. Real life robots are always going to be a lot more fun to work with than on-screen animations. Cozmo deserved as simple a vocabulary as Byte. That difference set me on the road to create a proof of concept.

In this effort, I’ve tried to develop a more engaging system of interaction that better mirrors the way kids learn. By creating high level abstractions, I wanted to support the same kind of learning as “Learn to Code”. Learn to Code begins with procedural calls, and then conditional ones, and moving on to iteration and functional abstraction, and so forth.

My yardstick of success has been, “can my son use these building blocks to express goals and master basic procedural and conditional code?” (I haven’t gotten him up to iteration yet.) So far, so good, actually.  Here is what my updated “Hello World” looks like for Cozmo, after creating a more structured entry into robot control functionality:

from Cozmo import *

# run, cozmo, run
def actions(cozmoLink):
    '''Specify actions for cozmo to run.'''
    
    # Fetch robot
    coz = Cozmo.robot(cozmoLink)

    # Say something
    coz.say("Hello Human")

Cozmo.startUp(actions)

Not quite as clean as “Learn to Code” but I think it’s a vast improvement on the original. Calls now go through a central Cozmo class. I’ve chunked together common behavior and I’ve abstracted away most implementation details, which are not of immediate interest to a student learner.

Although I haven’t had the time to really take this as far as I want, my Cozmo system can now talk, drive, turn, and engage (a little) with light cubes. What follows is a slightly more involved example. Cozmo runs several actions in sequence, and then conditionally responds to an interaction:

from Cozmo import *
from Colors import *

# Run, Cozmo, run
def actions(cozmoLink):
    '''Specify actions for cozmo to run.'''
    
    # Fetch robot
    coz = Cozmo.robot(cozmoLink)

    # Say something
    coz.say("Hello")

    # Drive a little
    coz.drive(time = 3, direction = Direction.forward)
    
    # Turn
    coz.turn(degrees = 180)
    
    # Drive a little more
    coz.drive(time = 3, direction = Direction.forward)

    # Light up a cube
    cube = coz.cube(0)
    cube.setColor(colorLime)
    
    # Tap it!
    coz.say("Tap it")    
    if cube.waitForTap():
        coz.say("You tapped it")
    else:
        coz.say("Why no tap?")
    cube.switchOff()

Cozmo.startUp(actions)

And here is a video showing Cozmo executing this code:

If you’d like to explore this a little further:

  • Here is a video showing the SDK feedback during that execution. You can see how the commands translate to base Cozmo directives.
  • I’ve left a bit of source code over at GitHub if you have a Cozmo or are just interested in my approach.

As you might expect, creating a usable student-focused learning system is time consuming and exhausting. On top of providing controlled functionality, what’s missing here is a lesson plan and a list of skills to master framed into “Let’s learn Python with Cozmo”. What’s here is just a sense of how that functionality might look when directed into more manageable chunks.

Given my time frame, I’ve focused more on “can this device be made student friendly” than producing an actual product. I believe my proof of concept shows that the right kind of engagement can support this kind of learning with this real-world robot.

The thing that appeals most to me about Cozmo from the start has been its rich computer vision capabilities. What I haven’t had a chance to really touch on yet is its high level features like “search for a cube”, “lift it and place it on another cube”, all of which are provided as building blocks in its existing API, and all of which are terrific touch points for a lesson plan.

I can easily see where I’d want to develop some new games with the robot, like lowering reaction time (it gets really hard under about three quarters of a second to tap that darn cube) and creating cube-to-cube sequences of light. I’d also love to discover whether I can extend detection to some leftovers my son brought home from our library’s 3D printer reject bin.

Cozmo does not offer a voice input SDK. It’s only real way to interact is through its cameras (and vision system) and through taps on its cubes. Even so, there’s a pretty rich basis to craft new ways to interact.

As for Anki’s built-ins, they’re quite rich. Cozmo can flip cubes, pull wheelies, and interact in a respectably rich range of physical and (via its face screen) emotional ways.

Even if you’re not programming the system, it’s a delightful toy. Add in the SDK though, and there’s a fantastic basis for learning.

Kid-fu: Pay for play

Screen Shot 2016-08-19 at 7.24.19 PMHow do you get your kid to try on all his shirts and pants before school starts? So you can sort them into trash, donate, wear, and “for playtime use only”? Answer: Playgrounds. Thank you playground team!

We used the “deal or no deal” rule. Two spins. You can “stick” or you can re-try, but no peeking at the next roll. Payment for each garment  after trying it on, taking it off and folding it. Coins placed into a cauldron (thank you Harry Potter camp) to be counted after we’re done. Any stained items treated with Oxyclean and thrown into the hamper.

For less than a couple of dollars, we got through his entire wardrobe with no complaints except “Don’t I have anything else that needs trying on?”

Source code follows:

Updating OSX beta: Lessons Learned

I wasted a lot of time yesterday and today until Mark Knopper pointed me to a solution for updating my beta by hand. Like others, my download had stalled at 151MB (of a 1+GB update) and I needed to just get the update done.

That solution thread linked to another developer forums post here. This thread contains links to manual downloads. Once you download the component pieces directly, you can move them into the stalled download in /Library/Updates, and then reboot and click Update in App Store.

I decided to complete all downloads, although some report you only have to install three of the four links. App Store sees the completed downloads, and installs and updates. I am now running Beta 2.

Some in that discussion thread have reported unstable systems after performing a manual upgrade. “I may have jinxed myself by asking, but after attempting to apply the packages willy nilly, it seems that my environment (16A201w on pro 3,1) is very unstable.  Safari is now crashing all the time.”

My A/C is broken and the repair person is about to arrive so I won’t have time to test my upgrade until later today or maybe early next week. If you do go this route, do so with extreme caution.

Bouncing AirDrop contents to my desktop

I never use my Downloads folder. It’s a fusion drive, so it’s precious, fast, and expensive. I don’t need a thousand downloaded copies of Xcode and firmware updates littering its limited space. Instead, I point all my browsers and other apps to download to my secondary data disk.

Screen Shot 2016-06-27 at 12.57.18 PM

And before you ask, I use numerical and alphabetic prefixes so everything shows up in the right place and the right order for quick reference and single-letter typing access. Whatever data I can offload from my main drive, I do offload:

Screen Shot 2016-06-27 at 12.59.42 PM

However, when it comes to airdropping, it’s generally true that whatever I’m sending back and forth is of immediate interest. In such case, I don’t want it heading into my Downloads folder. I want it on my desktop as soon as it lands. As  I’m updating my Playgrounds Book right now, I’m doing a lot more airdropping than I normally would.

I’m not a big user of smart folders and Automator actions. I have a smallish bunch that I occasionally use. Still, they have their place and today was a perfect occasion to bring a new one into the mix.

I just had had it with the Downloads folder and decided to build a bouncer that would automatically throw any item added to ~/Downloads up to the desktop. I thought I’d share how to do this.

Step 1. Create a new Folder Action

Screen Shot 2016-06-27 at 1.03.48 PM

Step 2. Choose the Downloads folder.

Screen Shot 2016-06-27 at 1.05.50 PM

Step 3. Drag “Move Finder Items” onto “Drag actions or files here to build your workflow”

Screen Shot 2016-06-27 at 1.06.37 PM

Screen Shot 2016-06-27 at 1.06.48 PM

This creates the following action, with Desktop selected by default. (If it’s not, choose Desktop for the destination.)

Screen Shot 2016-06-27 at 1.07.24 PM

Step 4. Then save:

Screen Shot 2016-06-27 at 1.09.12 PM

Your new automator action is stored in ~/Library/Workflows/Applications/Folder\ Actions:

Screen Shot 2016-06-27 at 1.11.43 PM

Step 5. Test. Drop a file into Downloads and confirm that it moves to the desktop. You should now be ready to airdrop to your desktop.

Note: I’m sure there’s a better way to do this, but I actually wrote an app that quickly opens AirDrop windows on the Mac side of things. I found an appropriate AppleScript online, compiled it to an app, and use Spotlight to launch it. Very handy when I’m more focused on iOS than OS X at the moment.

Sing out your Mac

Use tcsh (just enter /bin/tcsh) and then:

  • repeat 22 echo "da" | say -v good
  • repeat 26 echo "da" | say -v cello
  • repeat 22 echo "da" | say -v "bad news"

and of course

  • say -v cello droid

Was reminded of this today by:

Pinning tabs in Safari

Because sometimes people forget: Right-click the tab and choose Pin Tab from the pop-up. To remove a pinned tab, right-click again and either un-pin or close it.

Pinned tabs appear in all new tabbed browser windows as well.

Screen Shot 2016-04-13 at 4.04.55 PM Screen Shot 2016-04-13 at 4.05.02 PM

Xcode Upgrades: Lessons learned

Yesterday was remarkably instructive when it comes to how badly App Store can completely mess up a download: particularly for a popular app like Xcode that’s being requested by gazoodles of people at once.

CeGpK4VXEAA4jja

My download got stuck over and over. I had to clear out my app store caches, restart my app store daemons, and reboot my computer several times.

I ended up with a partial install that thought it was done, that installed all the “extra” components on launch, and then turned out to be a 7.2.1 install that was convinced it was 7.3. It was not.

I even cleaned up the whole install process, tossed my mangled 7.2.1, restored a copy from Time Machine (not a quick process), and tried to update again from the store.

I couldn’t use Xcode during this time to get any work done.

Screen Shot 2016-03-21 at 5.13.19 PM

I spent roughly 8 hours all told downloading, installing, and updating Xcode, much of which could have been bypassed by following two simple rules:

  1. Never update Xcode from the Mac App Store
  2. Wait until Apple posts the upload on developer.apple.com/downloads and  then update from there.

When Apple’s servers are overwhelmed they begin delivering artisanal teaspoons of hand-curated data via authentically indigenous pack animals to your computer. Apple has taken its passion for the slow data delivery movement beyond its products and introduced it into its upgrade practices.

Screen Shot 2016-03-22 at 9.43.41 AM

As part of their continuing mission to leave the world a better place, Apple delivers beautiful products using the most impact-free transmission. This commitment assures that developers are forced to stop work and smell the roses, as Apple promotes appreciation for our beautiful planet and life outside of the IDE window.

Under such circumstances, you’ll always be better off  downloading the bossy full-figured 5GB dmg than upgrading a model-thin Chanel-wearing 2.6GB differential, especially when servers are mocking you with NananaNAN completion estimates.

This is why you should always wait for a DMG. No matter how long it takes to appear on the developer site. No matter how slow the download ends up being. The advantages of downloading a DMG are numerous:

  1. It does not block you from  using Xcode during the entire day or however long it takes for your download to complete.
  2. It does not hang App Store or produce a situation where it insists on taking over the download (“Apple’s App Store download servers have a cheerful and sunny disposition. It is their pleasure to download for you using the gentle rhythms of tectonic flow and their satisfaction to keep you from getting any work accomplished, with a knowledge of a job well done.”)
  3. You can see exactly how much data has downloaded in terms of real progress and not imaginary hidden-temporary-file weird pkgs that takes over your /Applications folder and refuse to surrender that spot once active.
  4. Simple downloads are better for your resting heart rate, your blood pressure, and world peace.

Update: Final lesson. If you have downloaded the dmg directly from Apple and not from a third party source, you can run the following to skip the verification checks:

sudo xattr -d com.apple.quarantine /Applications/Xcode.app

Proceed at your own risk. Make sure you know what you’re doing and accept those risks.

In which I learn to branch

Thanks, Joe Groff

  1. git clone your existing repo
  2. cd into the new clone
  3. git checkout -b NEWBRANCHNAME
  4. make your changes, edits, tweaks
  5. cd back to the primary clone folder top level (in the folder)
  6. git add .
  7. git commit -m "A meaningful commit statement"
  8. git push -u origin NEWBRANCHNAME
  9. Hop onto github and use the branch pop-up menu to select your branch
  10. Create your new pull request.

Optional step 11 is “hope you have not overwhelmed the team with your proposal backlog.”

Monetizing while staying the “Good Guys”: the Tao of Red Herring

Copyright Blue Ox. Do not reproduce without permission.

Copyright Blue Ox. Do not reproduce without permission.

Red Herring (Free with IAPs) is one of my favorite iOS games. It’s one of the few single-device iOS games out there that plays better with groups of people than solo. My kids and I regularly gather round an iPad, launch Red Herring, and share time puzzling out the latest daily challenge and game packs.

It couldn’t be simpler: sixteen words and three unknown categories. It’s up to you to figure out how to group those words together leaving four stray red herring “spoilers” that may include words that look like they should fit but don’t actually belong, like “spine”, “bone”, “skin”, and “heart” in the example at the top of this post. The puzzles are tricky, silly, funny, and demanding.

Each game typically takes a few minutes, although a really tough board may last as long as a quarter hour or more. Fan sites have sprung up that offer cheats and solutions, a testament to how loyal and rabid this game’s fanbase can be.

Red Herring is from the creator of 7 Little Words, Moxie, Monkey Wrench, and a few other apps, all aimed at a family-friendly audience. I first wrote about Red Herring a couple of years ago, finding it to be fun and engaging. Last week, I had the opportunity to sit down and talk with Joe Jordan of Blue Ox. We discussed what it takes to grow and retain this kind of loyal customer base and provide a constant stream of creative, one-of-a-kind puzzles.

Blue Ox’s offerings use a standardized model: they include a trial pack to get users hooked, daily free puzzles that acts as maintenance doses, and budget-friendly IAP puzzle packs. Unlike King’s Candy Crush series, Blue Ox’s free users never get to a point where puzzles become impassable or the game sets up the proposition: “Pay us or stop playing.”

Jordan assured me that Blue Ox treasures its free users. “The potential marketing exposure is tremendous. The more they play, the more they’ll tell their friends about it and the more they feel a kinship with us and our games,” he said. That balance between free games and paid makes it easy to transition from free customer to revenue stream. For me, it’s when we’re out for Family Game Night and I want to grab a big set of puzzles to work on. The packs aren’t expensive and they offer a solid game “hang time”.

“We feel very strongly about the value proposition, giving people a good value,” Jordan said. “We’re always happy to have users continue to play, even when they’re just playing the free one.” It’s a philosophy that started with founder and owner Chris York. “Even in internal discussions, he’s always got the viewpoint that we love the customers who only play our daily games and never buy anything from us. They’re always a positive thing and not a drag.”

From a developer’s point of view, Blue Ox’s “virtuous circle” is aspirational. “Our way of approaching customers and potential customers is to give them enough benefit to support us and feel good about what they’re giving money to, the game that they’re a part of, and they like to talk to other people and they perpetuate that forward.”

The IAP becomes a rewarding gratification rather than a game-cheat to keep moving forward. Free daily games ensure that each IAP pack is a positive choice, not a shake-down.

Maintaining the quality of those packs is another business necessity. Each one is hand crafted, typically by professional crossword puzzle designers. Blue Ox has built a network of game authors over time. They started with a few crossword experts and branched out using word-of-mouth recommendations to create an extended team of contractors.

“Our first puzzle writer outside the company was a gentleman in Wisconsin named Ray Hamel. He’s a trivia guru and he brought that to bear on 7 Little Words and was one of the first creators working on Red Herring puzzles. We also have Sarah Hayes, who has written a ton of puzzles for us who is one of the top UK crossword puzzle writers.”

(Hayes also holds the world record for running a marathon while dressed as a beer bottle. The record applies across all bottle types, not just beer.)

Creating the right purchasable content for your game can make or break your application. “We contract with new writers for a small puzzle group to get a sense of what they can do and like to do. It gives a sense of the kind of puzzles they come up with.” When they find the right fit, they expand the contracts to larger batches. Red Herring puzzles are typically purchased in groups and they can take a long time to perfect. “It can be a painstaking process, going back and forth until it’s just right.”

A Red Herring puzzle has to be “unexpected, with relationships among all the different elements of the puzzles,” Jordan said. “We love misdirection: among the categories and between the categories and the red herrings. It has to be more than just, say, the position of a letter within a word or the number of letters that make up the word. There should be a deeper connection of the puzzle elements.”

I asked Jordan what makes a really good puzzle, and he provided several examples. About the puzzle at the top of this post, he wrote, “It is not complicated but it is elegant.”

And this next one? You might not expect to find Macaroni as a Penguin species or Fuseli as a red herring. “This puzzle has nice, discrete categories that require a certain amount of trivia knowledge (while avoiding esoterica). The fusilli/fuseli misdirection is somewhat rare – we’re not trying “gotcha” trickery – but it seems like it works here.”

Copyright Blue Ox. Do not reproduce without permission.

Copyright Blue Ox. Do not reproduce without permission.

Playing with sounds and word structure is another Red Herring trademark, as you see in the following example. “I’m a sucker for puzzles of this type, and I don’t see them enough,” Jordan says.

Copyright Blue Ox. Do not reproduce without permission.

Copyright Blue Ox. Do not reproduce without permission.

Here’s another of his favorites. Although the Jazz Greats may seem a little obvious, the Arthur Dent (Hitchhikers’s Guide to the Galaxy) and cat’s lives twists add a lovely resonance to the puzzle.

Copyright Blue Ox. Do not reproduce without permission.

Copyright Blue Ox. Do not reproduce without permission.

(There are just seven hills of Rome if you were wondering.)

From a programming point of view, there’s almost nothing in Red Herring that a competent coder couldn’t put out with a few weeks of effort and testing. The secret to its success isn’t its GUI or its graphics. Like the best of games, it’s a gateway to a larger experience. The solid puzzles behind the game are the basis of that experience.

Between its respectful balance of free-and-paid elements, and its commitment to ensuring high-quality puzzles, Blue Ox has evolved from a one-man effort to nearly a dozen employees servicing a core family of applications. If you’re starting your own games business, there are a lot worse business models you could follow and few that get it right more than this.