Wednesday, February 9, 2011

Lab 3 - Crazy Corner Conundrum

For our Lab 3, we were required to construct a vehicle capable of maneuvering a maze, avoiding obstacles, and are able to get itself out of corner if stuck. The entire code was assembled within a week’s time and the final project was then tested in a competition amongst other CPE470 students at the University of Nevada, Reno.

            The robot, which was built using Legos, was coded using an interactive-C compiler. The code was developed and tested by Keith Szelagowski, Kevin Laster, and Nick Niemann. A simple algorithm was created for the robot to easily maneuver around obstacles using sensors that can detect if the robot were to bump into an object. The code we developed also took in account if the robot bumped into an object four times within seven seconds, then at which point it would back up, turn a great amount, and then continue on with its normal program until the stop button is pressed.
           
            The hardware on our robot was more conventional.  We did not add anything that enhanced our robot in any way.  The only additions we added to the physical robot were longer bumpers.  This was needed because when the original bumpers were applied they would catch the front wheels of the robot, which caused more friction and slowed the robot down.  Another feature we added was to push the ends of the bumpers in a centimeter.  This allowed the robot to essentially ride a wall.  If the bumpers were on the ends, then it would trigger the sensor and turn when it would not need to.  We tried to enhance our robot to go faster by changing the gear ration to a one to one.  This was a problem for us. It made our robot go faster, but when the bumper was hit at such a fast speed it caused our bumper to fall off.  We went with the safe approach and thought we could win with “slow and steady wins the race.”
           
            There were two major problems that we faced when developing this lab. The first was the issue of the robot not being able to turn in the direction that we wanted. It seemed that it would only turn one direction, but not the other. We quickly found out this was a sensor wiring issue, so a replacement of the sensor quickly fixed the problem. The other problem that we encountered was setting up a reasonable time period for the robot to sense that it was in a corner. Although the typical algorithm called for a time period of four seconds, we debated how this was calculated. It could have always been running continuous four-second intervals, to where if the robot encounters four bumps within that four-second period, it would enact the corner algorithm. The alternative, which we chose, was that if a bump is encountered, it is then compared to how long it was since the last bump. If the time period between four consecutive bumps is less then four seconds, then the corner algorithm is run. Due to the constraints on our motors, we set the time limit to seven seconds, as it yielded the best results.

            Our robot was put to the test in the corner maze and successfully finished the maze.  Although it wasn’t at the fastest time, we did complete the task.  Our robot finished at a total of 46 seconds, which wasn’t as good as some of the others that were in the 20’s.  We felt that if we had spent more time to make our robot faster and more durable we could have finished among the leaders.








//corner program
// Global Variables
 float _timer;
void main()
{
    int bumpCtr = 0, time;
    printf("Corner Contest\n");
   
    while(!start_button());
    reset_timer();
   
    while(!stop_button())
      { 
       
        fd(0);
        fd(1);
       
        if (digital(11))//left
          {
            if (timer()<7.)
              {
                if (bumpCtr==4)
                  {
                    randomTurn();
                    bumpCtr=0;
                }
                else
                  {  
                    avoidLeft();
                    bumpCtr++;
                }
            }
            else
              {
                avoidLeft();
                bumpCtr=1;
                reset_timer();
            }
        }
       
        if (digital(9))//right
          {
            if (timer()<7.)
              {
                if (bumpCtr==4)
                  {
                    randomTurn();
                    bumpCtr=0;
                }
                else
                  {  
                    avoidRight();
                    bumpCtr++;
                }
            }
            else
              {
                avoidRight();
                bumpCtr=1;
                reset_timer();
            }
        }      
       
        off(0);
        off(1);
    }
}
void randomTurn()
{
    float randNum = (float)random(100)/100. + 1.5;
    int randMotor = (int)random(2);
  
   
    bk(0);
    bk(1);
    tone(940.0, 0.7);
    motor(randMotor, 50);
    motor((randMotor-1)*-1, -50);
    sleep(randNum);   
}

void avoidLeft()
{
    bk(0);
    bk(1);
    sleep(0.5);
    motor(0, 50);
    motor(1, -50);
    sleep(0.7);
}
void avoidRight()
{
    bk(0);
    bk(1);
    sleep(0.5);
    motor(1, 50);
    motor(0, -50);
    sleep(0.7);
}
void reset_timer()
{
    _timer= seconds();  
}
float timer()
{
    return seconds() - _timer;
}

No comments:

Post a Comment