Пример #1
0
int main(){
	
	int turned_left = 0;
	while(1){
	    unsigned char state;
        state = 0;
		for (int i = 0 ; i <3 ; i++)
		   state |= (avg_analog(i) < THRESHOLD ) << i;
        
        switch (state){
		    case  OOO: s_left(100); sleep (30); myforward(30); break;
			case  OOX: s_right(100);break;
			case  OXO: myforward(50);sound(500, 10); break;
			case  OXX: s_right(50);break;
			case  XOO: s_left(100); break;
			case  XOX: myforward(50); break;
			case  XXO: s_left(50); break;
			case  XXX: s_right(100); sleep(30); myforward(30);sound(100, 200); break;
			default : break;
			}		
	}
	return 0;
}
 void SubdivPatch1Intersector1::subdivide_intersect1_bspline(const Precalculations& pre,
                                                             Ray& ray,
                                                             const BSplinePatch &patch,
                                                             const unsigned int geomID,
                                                             const unsigned int primID,
                                                             const Vec2f &s,
                                                             const Vec2f &t,
                                                             const unsigned int subdiv_level)
 {
   if (subdiv_level == 0)
   {
     Vec3fa vtx[4];
     vtx[0] = patch.eval(s[0],t[0]);
     
     vtx[1] = patch.eval(s[1],t[0]);
     vtx[2] = patch.eval(s[1],t[1]);
     vtx[3] = patch.eval(s[0],t[1]);
     intersectTri(vtx[0],
                  vtx[1],
                  vtx[2],
                  ray,
                  geomID,
                  primID,NULL); 
     
     intersectTri(vtx[2],
                  vtx[3],
                  vtx[0],
                  ray,
                  geomID,
                  primID,NULL); 
   }
   else
   {
     const float mid_s = 0.5f * (s[0]+s[1]);
     const float mid_t = 0.5f * (t[0]+t[1]);
     Vec2f s_left(s[0],mid_s);
     Vec2f s_right(mid_s,s[1]);
     Vec2f t_left(t[0],mid_t);
     Vec2f t_right(mid_t,t[1]);
     subdivide_intersect1_bspline(pre,ray,patch,geomID,primID,s_left ,t_left,subdiv_level - 1);
     subdivide_intersect1_bspline(pre,ray,patch,geomID,primID,s_right,t_left,subdiv_level - 1);
     subdivide_intersect1_bspline(pre,ray,patch,geomID,primID,s_right,t_right,subdiv_level - 1);
     subdivide_intersect1_bspline(pre,ray,patch,geomID,primID,s_left ,t_right,subdiv_level - 1);
   }
 }
Пример #3
0
int main(){
	
	int turned_left = 0;
	while(1){
        unsigned int sensor_r = avg_analog(0);
		unsigned int sensor_l = avg_analog(1);
		
		if (sensor_r < THRESHOLD && sensor_l <THRESHOLD)
		  forward(50);
		  
		  
        else if (sensor_r > THRESHOLD && sensor_l <= THRESHOLD ){
		    s_left(50);
			
			turned_left = 1;
			}
        else if (sensor_l > THRESHOLD && sensor_r <= THRESHOLD ){
		    s_right(50);
			turned_left = 0;
			}
        else 
		    wtf(turned_left);

        //forward(50);
		//sleep(100);

		if (sensor_l > THRESHOLD)
		   sound(sensor_l* 2 + 100, 10);
		   
        if (sensor_r > THRESHOLD)
		   sound(sensor_r* 2 + 100, 10);
		//sleep();



	}
	return 0;
}
Пример #4
0
int wtf(int turned_left){
if(turned_left==0) s_right(50);
else s_left(50);
forward(50);
sleep(10);
}
Пример #5
0
void main()
{	unsigned char dec[4],dec2[4];
	int distance_left = 0;
	int distance_right = 0; 
	sleep(400);
	soft_serout_init(0,9600);											
	
	while(1)										// Infinite Loop
	{ 
		// получаем расстояние с сенсора
		
		utoa(666,dec,10);                         
	    distance_left = get_distance_left();
		distance_right = get_distance_right();
		utoa(distance_left,dec2,10);
		
		// выводим на экран
	serout_byte(0,0xFE);serout_byte(0,0x00);		//	Clear Screen SLCD
		serout_byte(0,0xFE);serout_byte(0,0x80);		//  Show Text on First Line
		serout_text(0,"RAW Data= ");
		serout_text(0,dec);
		serout_byte(0,0xFE);serout_byte(0,0xC0);
		serout_text(0,"Dist= ");
		serout_text(0,dec2);
		serout_byte(0,0xFE);serout_byte(0,0xCE);

		serout_text(0,"CM");
		sleep(500);	
     
       
	 // (distance_left<40) (distance_right<40)	
	
 ABC:if ((distance_left<40)||(distance_right<40))
	{
	 if (distance_right<40) 
	  {
	    if (distance_left<40)
	     {
		
		 forward (100);
		 sleep (20);
		 
		 }
	
        else 
	   {
	    int i;
	    for (i=0;i<25;i++)
		  { if ((distance_left<40)&&(distance_right<40))
		    {
		    forward (100);
		    sleep (50);
		    }
		    else
		    {
		    s_right (40);
		    sleep (20);
		    }
			//goto ABC;
		  }
	    }	 
	  }
	else
	{
	int i1;
	for (i1=0;i1<25;i1++)
	{ if ((distance_left<40)&&(distance_right<40))
		  {
		  forward (100);
		  sleep (50);
		  }
		   else
		   {
		   s_left (40);
		  sleep (20);
		   }
		   }
	}
    //goto ABC;	
    }
	
			
 }

}