Home
Projects
Blog
My Resume
Project193
BRB or BBL
Robot
Guestbook
Old Stuff
Email



Hit Counter

 

<<

functions\marblecollection.c  


Click to enlarge

void marblecollection(float side)
{
int distance=0;
int x=0, a=0;
int fullspeed=50, side_to_align, front_sensor_to_check, rear_sensor_to_check, check=0;

if (side<0.)
{
side_to_align=4;
front_sensor_to_check=8;
rear_sensor_to_check=11;
}

if (side>0.)
{
side_to_align=8;
front_sensor_to_check=10;
rear_sensor_to_check=12;
}

right_motor(-60);
left_motor(-60);
sleep(1.);
while(mercury()==0);

distance=straight(-fullspeed,-fullspeed,4.,0);

turn(side*-15.,50);
if (side<0.)
{
left_motor(-30);
right_motor(-70);
}
if (side>0.)
{
left_motor(-70);
right_motor(-30);
}
sleep(2.);
while(check==0)
{
while(digital(rear_sensor_to_check)==0);
while(digital(rear_sensor_to_check)==1);
/*turn(-7.*side,30);*/

if (side<0.)
{
left_motor(-30);
right_motor(-70);
}
if (side>0.)
{
left_motor(-70);
right_motor(-30);
}
if(digital(rear_sensor_to_check)==0) check=1;
}

motors_off();
sleep(.1);
/*kevin's addition*/
if (side<0.)
{
straight(-40,-40,3.,0); /* white side */
encoder3_counts=0;
left_motor(-45);
right_motor(-40);
while (encoder3_counts<20);
while(right_back()==0&&left_back()==0)
{
turn(-side,50);
sleep(.01);
}
}
if (side>0.)
{
straight(-40,-40,3.,0); /* black side */
encoder1_counts=0;
right_motor(-55);
left_motor(-35);
while(encoder1_counts<17);

while(right_back()==0&&left_back()==0)
{
turn(-side,50);
sleep(.01);
}
straight(-fullspeed/2,-fullspeed/2,1.,0);

}

/*if (side<0.)
{
encoder3_counts=0;
right_motor(30);
while(encoder3_counts<1);
}

if (side>0.)
{
encoder1_counts=0;
left_motor(30);
while(encoder1_counts<1);
}*/

motors_off();
/*
distance=straight(-fullspeed/2,-fullspeed/2,4.,0);
sleep(1.);
if (side<0.)
{
encoder1_counts=0;
left_motor(-50);
while(encoder1_counts<1);
}

if (side>0.)
{
encoder3_counts=0;

right_motor(-50);
while(encoder3_counts<1);
}
distance=straight(-fullspeed/2,-fullspeed/2,10.5,0);
motors_off();
sleep(.5);
*/

x=0;
/* zu's marble collection */

for(x=24;x<=64;x+=2) /* brush vertical down */
{
brush_servo((float)x);
sleep(.025);
}
straight(25,25,6.5,0); /* sweeping... */

/*turn(-side,25);*/
arm_servo(19.); /* drops tray into bin */
sleep(.4);

/* a=0;
while(a<2)
{
turn(side,25); wiggles tray into bin 
turn(-side,25);
a=a+1;
} */
a=0; 

for(x=64;x<=100;x+=4) /* lifts brush */
{
brush_servo((float)x);
sleep(.05);
}
straight(fullspeed/2,fullspeed/2,.6,0);
while(a!=1) /* collection */
{
for(x=100;x>=10;x-=4) /* brush back into tray */
{
brush_servo((float)x);
sleep(.01);
}
for(x=20;x<=100;x+=2) /* moves brush out of the way */
{
brush_servo((float)x);
sleep(.01); 
}
a=a+1;
}
distance=straight(fullspeed/2,fullspeed/2,1.,0);
a=0;
while(a!=2) /* collection */
{

for(x=100;x>=10;x-=4) /* brush back into tray */
{
brush_servo((float)x);
sleep(.01);
}
for(x=20;x<=100;x+=2) /* moves brush out of the way */
{
brush_servo((float)x);
sleep(.01);
straight(fullspeed/2,fullspeed/2,.5,0);
}

a=a+1;


} brush_servo(100.);
sleep(.5);
for(x=19;x<=53;x+=2)
{
arm_servo((float)x); /* tray at holding position */
sleep(.05);
}
sleep(.5);

/* end zu's marble collection */

straight(fullspeed/2,fullspeed/2,3.,0); 
/* turn(side*3.,25); */
beep();
/* sleep(.5); */
}

© '02 James Beams

http://beams.oxonet.com