Nick Niemann, Keith Szelagowski, Kevin Laster
For our Lab 5 , we were required to find and detect a line, then follow the line without jumping off of it. The goal is to complete the loop as quickly as possible without jumping off of the line. We also had to include wandering with obstacle avoidance just in case our robot would jump off the line, it would have to find the line again and complete the loop. This would then be tested in a competition amongst other CPE470 students at the University of Nevada, Reno.
Our design was simple, we mounted the two optosensors on each side of the robot as far away as possible. This allowed for less adjustment and helped with time. For our software, we would move forward until the robot encountered a reflection off of the black line. If the reflection came from the right sensor, then we would back up a bit and turn right slightly. The opposite would happen for our left sensor. The robot would back up and turn left slightly. We added the back up feature because the robot wouldn't turn sharp enough and just go off of the line. We also had another thread going at the same time to deal with going off the line. We simply just incorperated obsticle avoidance from a previous lab.
At first we had some problems with mounting the optosensors because they wouldnt stay in the right place. We then built something a little sturdier that would allow the sensor to be a bit more stable. Another problem we were facing was that our turning wasn't as sharp as we would like it to be. This was fixed by just adding the back up feature as mentioned before. The cause of the robot not turning sharp enough was because of our front wheels. The front wheels were creating friction against the robot when turning. For the next assignment we will more than likely incorperate the nubs in replace of the front wheels.
As the contest went on we felt really confident that our robot was going to perform substantially. While seeing other robots conquer at such fast speeds, we now realize we could have made great improvements to our robot to compete better. Next lab I feel that we need to modify our robots hardware and not focus so much on the software to make up for the hardware flaws. Although our robot was not the fastest, we felt as if it was really reliable for not jumping off of the line. We felt that this was the ultimate goal as other robots were jumping off of the line.
// Line Follower - Laster, Szelagoski, Niemann
// Global Variables
int MAX_LIGHT = 115;
int MIN_LIGHT = 80;
float _timer;
int RIGHT_EYE = 6;
int LEFT_EYE = 5;
int rVal = 0;
int lVal = 0;
int bumpCtr = 0;
int flag = 1;
int wFlag = 1;
int lock = 0;
int onLine = 0;
int leftMotor = 0;
int rightMotor = 1;
int Lsensor = 4;
int Rsensor = 3;
int line, lineThreshold;
// Main Function
void main()
{
// Initialize Variables
int time;
int lightLeft, lightRight;
// Loop For Start Waiting
while( !start_button());
reset_timer();
printf( "Line Followerv2\n" );
start_process(lineDetect());
//start_process(straight());
start_process(avoid());
start_process(stopper());
}
/*
void straight()
{
while(flag)
{
//loop till left sensor hits while
while(!lVal&&!rVal && !lock)
{
motor(leftMotor, 20);
motor(rightMotor, 20);
}
}
}
*/
void lineDetect()
{
while(flag)
{
lVal = analog( Lsensor );
lVal = normalize(lVal);
printf("lVal=%d \n", lVal);
// if Rsensor>Lsesnor
while(lVal)
{
//start lock
lock = 1;
// Turn left
if(onLine)
{
motor(rightMotor, -25);
motor(leftMotor, -100);
sleep(0.1);
}
motor(rightMotor, 50);
sleep(0.5);
lVal = analog( Lsensor );
lVal = normalize(lVal);
onLine = 1;
}
rVal = analog( Rsensor );
rVal = normalize(rVal);
printf("rVal=%d \n", rVal);
// If Rsensor>Lsensor
while (rVal)
{
//start lock
lock = 1;
// Turn right
if(onLine)
{
motor(leftMotor, -25);
motor(rightMotor, -100);
sleep(0.1);
}
motor(leftMotor, 50);
sleep(0.5);
rVal = analog( Rsensor );
rVal = normalize(rVal);
onLine = 1;
}
//end lock
lock = 0;
motor(leftMotor, 100);
motor(rightMotor, 100);
}
}
// Function Definitions
void avoid()
{
while( wFlag )
{
if( digital( 11 )) // Left Motor
{
if( timer() < 7. )
{
if( bumpCtr == 4 )
{
randomTurn();
bumpCtr=0;
}
else
{
avoidLeft();
bumpCtr++;
}
}
else
{
avoidLeft();
bumpCtr = 1;
reset_timer();
}
}
if( digital( 9 )) // Right Motor
{
if( timer() < 7. )
{
if( bumpCtr==4 )
{
randomTurn();
bumpCtr=0;
}
else
{
avoidRight();
bumpCtr++;
}
}
else
{
avoidRight();
bumpCtr=1;
reset_timer();
}
}
}
}
void randomTurn()
{
int i;
float randNum = (float)random(100)/100. + 1.5;
int randMotor = (int)random(2);
fd(0);
fd(1);
tone(940.0, 0.7);
motor(randMotor, 100);
motor((randMotor-1)*-1, -100);
sleep(randNum);
}
void avoidLeft()
{
bk(0);
bk(1);
sleep(0.5);
motor(0, 100);
motor(1, -100);
sleep(0.7);
}
void avoidRight()
{
bk(0);
bk(1);
sleep(0.5);
motor(1, 100);
motor(0, -100);
sleep(0.7);
}
void reset_timer()
{
_timer= seconds();
}
float timer()
{
return seconds() - _timer;
}
int normalize( int light )
{
if(light < 50)
{
return 0;
}
else //( light > 50)
{
return 1;
}
}
void stopper()
{
while (flag)
{
if (stop_button())
{
flag = 0;
}
}
}
No comments:
Post a Comment