Пример #1
0
interrupt [TWI] void TWI_interface(void) {
	recieveData();
	switch(index_in) {
	case 'K' :
		i2ckilled = 1;
		index_in = 0;
		break;
	case 'S' :
	        if(Data_in > 10)
	        Data_in = 10;
	        else if(Data_in < 0)
	        Data_in = 0;  
	        maxspeed = Data_in;   
	        index_in = 0;
		break;
	case 'V' :
		getSpeedIndex();	
		index_in = 0;
		break;   
	case 'P' : 
	
		//sendData('P', keypad, TWI_SENSOR_ADDR); 
		 
		//keypad = keypad_oneKey();    //polling
		//sendData('P', keypad, TWI_SENSOR_ADDR);
		index_in = 0;
		break;
	default:
		break;
	}
}
Пример #2
0
Vertex *updateNeighborhood(Graph *g,Vertex *u)
{
   int i,j;
   Vertex *v;
   Pilot *np, *p;
   Vect *nextAcc;
   int boost=((Vect4D *)u->e)->b;
   int l=boost>0?2:1;

   p=createPilotFromVertex(u);

   for(i=-l;i<=l;i++)
      {
	 for(j=-l;j<=l;j++)
	    {  
	       np=createEmptyPilot();
	       nextAcc=createVect(i,j); 
	       np->speed=vectSum(p->speed,nextAcc); 
	       np->pos=vectSum(p->pos,np->speed);
		     
	       if(isValidMove(p,np,g->field))
		  {
		     boost=(i==-2||i==2||j==-2||j==2)?((Vect4D *)u->e)->b-1:((Vect4D *)u->e)->b;
		     
		     v=g->vertices[np->pos->x][np->pos->y][getSpeedIndex(np->speed)][boost];
		     
		     if(v->distance>u->distance+1)
			{
			   v->previous=u;
			   v->distance=u->distance+1;
			   fh_insertkey(g->heap,v->distance,v);
			}

		     if(g->field->cell[np->pos->x][np->pos->y]=='=')
			{
			   return v;
			}
		  }
	       else 
		  {
		     destroyPilot(np);
		     destroyVect(nextAcc);
		     continue;
		  }

	       destroyVect(nextAcc);
	    }
      }

   return NULL;
}
Пример #3
0
Vertex *getVertexFromPilot(Graph *g,Pilot *p)
{
   return g->vertices[p->pos->x][p->pos->y][getSpeedIndex(p->speed)][2]; 
}
Пример #4
0
void main(void)
{    
        unsigned int UBR = XTAL/(16*BAUD) -1; 
        // USART0 initialization
	UBRR0H=(unsigned char)(UBR >>8);                
	UBRR0L=(unsigned char)(UBR &0xFF); 
    	UCSR0A=0x00;              
	UCSR0B=0xD8;
	UCSR0C=0x06;            // 0000 0110 character size reserved, asynchronous operation
	
	// USART1 initialization
	UBRR1H=(unsigned char)(UBR >>8);                    
  	UBRR1L=(unsigned char)(UBR & 0xFF);             
    	UCSR1A = 0x00;          //normal data rate for asynchronous operation
	UCSR1B=0xD8;            // 1101 1000 enable transmitter, reciever, interupts on transmit and recieve complete
	UCSR1C=0x06;            // 0000 0110 character size reserved, asynchronous operation     

	// SPEED PWM - HBRIDGE CONTROL
	//B 5,6 output compare
	//B 1 SPI clk
	DDRB = 0x60; // 0110 0000
	
	// TIMER INTERRUPT
	//-11- --00
	//outputcompare/timer overflow 
	TIMSK = 0x01; // 0000 0001 
	
	// TIMER 0
	//TCCR
	//interrupt to update pwm
	//---- -xxx
	//0: stopped, 1: no scaling, 2: 8, 3: 32, 4: 64, 5:128, 6: 256, 7: 1024
	//-000 0---
	//no output compare, overflow on max
	TCCR0 = 0x07; // 0000 0111    
	
 	// TIMER 1
	// SPEED PWM - HBRIDGE CONTROL
	//TCCRA: AABB CC--
	//Overflow at top
	//Clear OCR1 on compare match
	
	//TCCRA: ---- --xx TCCRB: ---xx---
	//Fast PWM
	//Top = ICR1
	//Update OCR1 at top

    	//TCCRB: ---- -xxx 
	//0:stopped 1:no prescaling 2: 8 3:64 4:256 5:1024 6,7: external clock
	TCCR1A = 0xF2; // 111100 10
	TCCR1B = 0x19; // 00011 001
	ICR1H = TOP >> 8;
	ICR1L = TOP & 0xFF;
	
    	// TIMER 3
	// ENCODER TICKS COUNTER
	//---- -xxx
	//6: clock on Tn pin rising 7: Clock on Tn pin falling
	TCCR3A = 0x00;
	TCCR3B = 0x07;
    
    //EIMSK = 0b11000000;
    //EICRA = 0b00001000;
    
	//TWI_init(TWI_ADDR);
	initcamera();
	//keypad_init();    
	
	get_calibrated_settings(speed_range, speed_slope, speed_height, speed_max_mem);

	#asm("sei");
	while(1) 
	{
        getstuff();
        getSpeedIndex();
        updatespeed();
        
		if(testvar ==30)
  		{       
  			//printf("\rstate: %d maxspeed: %d ticks: %d topspeed: %d\r", state,maxspeed, ticks, topspeed);    
  			printf("keypad: %d",keypad);
                       	printf("index_in: %d Data_in: %d\r", index_in,Data_in);
                       	testvar =0;
     		}          
	};
}