Swiffie

Swiffie is a device to clean hardwood or tile floors. Since our flat has an abundance of those and we have a permanent dust problem, Lutz has complained alot until finally on Xmas 2000 he was given a Lego Mindstorms Robotics Invention Kit. From this several, vastly different versions of Swiffie have evolved. Like the name may suggest one of the main components of the robot is a standard dust attracting Swiffer cloth including the cloth holder.



30.12.2000

Swiffie1: The first version. Quite big, not too agile, but already with sophisticated sensors in the front and in the back. The swifffer cloth can rotate 360 degrees.



15.1.2001

Swiffie2: After some deep thoughts the robot got completely rebuilt and reduced to essential parts. The robot is now low enough to drive under shelves and clean there as well. Better sensors, better software, but this damn thing still keeps getting locked in difficult terrain and at frontal approaches.



2002 (Bild folgt)

Further reductions. The front sensors are now crossed (the base of the left sensor is on the right side etc.) to handle frontal approaches better. The third wheel got eliminated to get more weight onto the cloth. The robot is now Smaller than the cloth and can now also clean edges. Swiffie doesn't get stuck any more thanks to random turning decisions. Here is the code (in NQC notation):

#define LeftMotor OUT_A
#define RightMotor OUT_C
#define LeftSensor SENSOR_1
#define LightSensor SENSOR_2
#define RightSensor SENSOR_3
#pragma reserve 0
#pragma reserve 1
#pragma reserve 2

int rand=0;         // random left/right turn counter
int maxtime=150;    // idle timeout in 1/10 s
int maxbumps=20;     // max number of bumps without timer expiring
int smooth= 50;     // turning smoothness in 1/100 s
int longsmooth=125; // time it takes to do a 180 degree circle around one wheel in 1/100 s
int pullbacksmooth=75;  // time for pulling back

#define GoStraight()  OnFwd(LeftMotor+RightMotor);
#define PullBack()    OnRev(LeftMotor+RightMotor); Wait(pullbacksmooth);
#define FloatAll()    Float(LeftMotor+RightMotor); Wait(smooth);
#define FloatLeft()   Float(LeftMotor); Wait(smooth);
#define FloatRight()  Float(RightMotor); Wait(smooth);
#define TurnRight()   OnRev(RightMotor); Wait(smooth); ClearTimer(0);
#define TurnLeft()    OnRev(LeftMotor); Wait(smooth); ClearTimer(0);
#define LeftRight()   PlaySound(0); rand=Random(1); \
                      if (rand>0) { TurnLeft(); } else {  TurnRight(); } \
                      Wait(longsmooth);

task main ()
{
  SetSensor(LeftSensor, SENSOR_TOUCH);
  SetSensor(RightSensor, SENSOR_TOUCH);
  SetUserDisplay(BatteryLevel(),3);
  ClearTimer(0);
  while(1) {

    // SetUserDisplay(Timer(0), 1);
    GoStraight();    // default action - both engines forward

    if(Timer(0) > maxtime) TimerExpired();
    if(Counter(2) > maxbumps) TimerExpired();

    if(LeftSensor) {
      IncCounter(2);
      if (RightSensor) {
        LeftRight();
      } else {
        TurnRight();
      }
    }

    if(RightSensor) {
     IncCounter(2);
      if (LeftSensor) {
        LeftRight();
      } else {
        TurnLeft();
      }
    }
   }
}

sub TimerExpired()  //circle left or right
{
  PlaySound(5);
  FloatAll();
  PullBack();
  IncCounter(1);
  if (Counter(1)>1) {
    ClearCounter(1); FloatLeft(); OnFwd(LeftMotor);
  } else {
    FloatRight(); OnFwd(RightMotor);
  }
  PlaySound(4);
  Wait(longsmooth);           // keep turning
  ClearTimer(0);
  ClearCounter(2);
  FloatAll();
  GoStraight();    // default action - both engines forward
}