   }
 }
 
-void doLogoCommand(String c)
+
+static void handleCollisions() {
+  byte nowColliding = 0;
+  if (!digitalRead(switchFL)) nowColliding = 1;
+  if (!digitalRead(switchFR)) nowColliding += 2;
+  
+  if (nowColliding != state.colliding) {
+    // collision state has changed, do something sensible
+    
+    if (nowColliding == 1) {
+      // abort current command
+      abort();
+      buzz(500);
+      
+      // insert some recovery steps
+      insertCmd("RT 45"); 
+      insertCmd("BK 20"); 
+    } else if (nowColliding == 2) {
+      // abort current command
+      abort();
+      buzz(500);
+      
+      // insert some recovery steps
+      insertCmd("LT 45"); 
+      insertCmd("BK 20"); 
+    } else if (nowColliding == 3) {
+      // abort current command
+      abort();
+      buzz(500);
+      
+      // insert some recovery steps
+      insertCmd("RT 120"); 
+      insertCmd("BK 20"); 
+    }
+    
+    state.colliding = nowColliding; 
+  } 
+}
+
+
+static void doLogoCommand(String c)
 {
   /* Official Logo Commands
        Implemented


static void writeF()
{
  float x = position.x;
  float y = position.y;
  float w = fontSize * 0.5;

  pushCmd("PD");


static void writeD()
{
  float x = state.x;
  float y = state.y;
  float w = fontSize * 0.5;

  pushCmd("PD");
