Program design

Motor Control:

    The below C code was used to operate the stepper motors. A simple state machine was implemented to implement the stepping sequence.  

char forward(char x){ 
switch(x){
   case (1+2):
     x = 2+4;
     break;
   case (2+4):
     x = 4+8;
     break;
   case (4+8):
     x = 8+1;
     break;
   case (8+1):
     x = 1+2;
     break;
   default:
     x = 1+2;
     break;
   }
   return x;
}

FORWARD STEP

  char backward(char x){
switch(x){
   case (1+2):
     x = 8+1;
     break;
   case (2+4):
     x = 1+2;
     break;
   case (4+8):
     x = 2+4;
     break;
   case (8+1):
     x = 4+8;
     break;
   default:
     x = 1+2;
     break;
   }
   return x;
}

BACKWARD STEP

    To run the motor in the opposite direction the mot was stepped in the opposite sequence. Using this code we could move the bot in each of the four directions. To turn right the left motor was made to move forward whereas the right motor moved backwards thereby allowing the bot to turn in its position.

Direction Sensing:

    Navigating the bot relied on 2 AI's one for obstacle avoidance and the other for direction finding. The Sharp sensor was used for obstacle detection whereas 4 Vishay 38 Khz IR sensors were used for direction sensing. A standard TV remote Control was used to hone the bot into its target location. When detected by the Vishay sensor the output of the sensor would go low. We programmed the AI so that each of the sensors were polled once every 100 micro seconds.

    Programming direction finding proved to be harder than expected. We experienced issues with more than one sensor picking up a signal. Consequently we had to come up with an AI scheme that would prioritize the input signals from the sensor and only use relevant information. The bot was programmed so that it would reset and begin to rotate in its position, scanning the vicinity for the target in the left direction once about every 3 seconds. This was done so that we could correct the bot direction every once in a while. This also helped us deal with the issue of 2 or more sensors picking up an IR signal. The directional AI was programmed in the following manner:

Obstacle Avoidance:

    A state machine was implemented for the purpose of obstacle avoidance. In the case that no obstacle was detected the bot would continue to move in the direction determined by the Vishay sensors as documented above. In the event that an obstacle was detected the bot would immediately turn in position so as to avoid the obstacle. The bot was programmed so that it would continue turning as long as there was an obstacle.

    When implementing obstacle avoidance there were cases when the bot would turn and avoid the obstacle but have one of its edges collide with the obstacle. This would happen since the distance ranging sensor was located in the center of the bot and could not detect stuff not directly in front of it. To resolve this problem we programmed the AI so that the bot would conservatively continue avoiding the obstacle for a small amount of time even once the no obstacle flag was set. By doing so we ensure that the bot would collide into anything in had just avoided.

    Once an obstacle was avoided the bot would then continue moving forward in that direction for a while ignoring all sensor inputs. This was done in order to steer past some longer obstacles. Once this was done the bot AI was reset so that it would again begin to scan for the IR transmiiter.

   

Bot avoiding obstacles