Home Contents Start Prev 1 2 Next

Software

The Dawning of Purpose

To date, Lawna and Sandbot have been concerned with randomly scuttling about and avoiding objects without getting stuck in a corner. A by-product with Lawna is that the grass gets mowed in the process. Taking Lawna as an example, I'd like to make her to take on more of a self-sufficient roll with limited intelligence.

In this respect, the aim is to make a robot have three modes of operation:

  • Work
  • Eat
  • Sleep

The robot will need to be able to switch between these modes depending on its environment and current energy levels. This gives Lawna a reason for being, namely she needs to work by mowing the lawn and avoiding objects in the process. Her 'energy' levels are battery charge and when this gets low, she must seek out a way to 'eat' in order to replenish lost energy. She must also sleep occasionally by monitoring the environment as we don't want to mow the lawn at 3am, or when it is covered in snow.

Cognitive Layers

In order to give Lawna the limited intelligence of an insect, I believe it is best to split the 'thinking' into software layers. This means splitting out some of the current functionality it autonomous and planned areas. For example, during the 'work' mode, Lawna needs to trudle forward and mow the grass. However, if she hits an obstacle, some form of evasive action is necessary. Evasive action can be pushed to the lowest level of thinking, it should be autonomous, pretty much like breathing, and called upon whilst performing the higher level functionality or work (mowing). There may well be other autonomous functionality that will be added going forward, but one step at a time.

States

I will implement the higher level 'thinking' as a finite state machine as this makes splitting up the states for testing simpler. Each of the high level modes an be broken down into several smaller states, each with predefined actions.

High Level States
  • sleep - off or standby
  • work - mowing
  • eat - find and recharge

The thing that determines a High Level State is the battery level. May possibly include weather.

work state:

This is mowing. Cut grass. Read bump sensors and take evasive action if necessary.

eat state:

This has several substates:

  • search for the beacon
  • home in on the beacon
  • docking
  • monitor charge
sleep state:

maybe monitor light and precipitation.

main() { // loop forever
 initialize();  
  switches = readSensors()  
  state = fsm(state, switches)
  
}


int fsm(int oldState, int switches) {

  int newState = state;
  switch(state) {

  case SLEEP:
    Serial.println("SLEEP");
    delay(3000);
    newState = MOW;
    break;

  case HUNGRY:
    Serial.println("HUNGRY");
    newState = hungry();
    break;

    case SEARCH:
    Serial.println("SEARCH");
    newState = search(switches);
    break;

    case HOMING:
    Serial.println("HOMING");
    newState = homing(switches);
    break;

    case DOCKING:
    Serial.println("DOCKING");
    newState = docking(switches);
    break;

    case MOW:
    default:
    Serial.println("MOW");
    newState = mow(switches);
    break;
  }
  return newState;			
}

// The mow or 'work' state. We aim to spend most of our time here, battery charge permitting.
int mow(int switches) {

  int newState = MOW;
  int bv = monitorNiMHBattery(); // make this global in main loop
  if (bv < BATTERY_THRESHOLD) {
    newState = HUNGRY;
  } 
  else {

    enableCutter();
    robot_forward();    // make this turn randomly occassionally
    takeEvasiveAction(switches);
    newState = MOW;
  }
  return( newState );
}

int hungry() {
  disableCutter();
  enableWidebeam();
  return( SEARCH );
}

// We are looking for the beacon using the widebeam receiver
int search(int switches) {
  int newState = SEARCH;
  int wb = readWidebeam();
  
  if (wb < IR_WB_THRESHOLD) {
    robot_skidRight(1000);                  // a slow turn
    takeEvasiveAction(switches);            // in case we have hit an obstacle
    newState = SEARCH;
  } 
  else {
    newState = HOMING;
  }
  return newState;
}

Home Contents Start Prev 1 2 Next