Example #1
0
File: wmp.c Project: bobbens/LACE
void wmp_init (void)
{
   /* Initialize I2C at 400 kHz. */
   i2cm_init( I2C_FREQ_400K );

   /* Initializes the WM+ */
   i2cm_start( 0x53, I2C_WRITE );
   i2cm_transmitChar( 0xFE );
   i2cm_transmitChar( 0x04 );
   i2cm_end();

   /* Set event for when it's on. */
   event_setCallback( EVENT_TYPE_I2C, wmp_on );
}
Example #2
0
//////////////////////////////////////
// Main
/////////////////////////////////////
int main(void)
{
	//int a = 0;
	/////////////////////////////////////
	///TODO//////////////////////////////
	/////////////////////////////////////
	//
	//participer a la coupe
	/////////////////////////////////////




	/////////////////////////////////////
	//Initialisations////////////////////
	/////////////////////////////////////
	uart_init();
	time_init(128);
	printf("fdevopen \n");
	fdevopen(uart0_send,uart0_recv, 1);

	// Affichage uart: tip -s 9600 -l /dev/ttyS0
	// prog usb : 
	// avarice -j /dev/ttyUSB0 --erase --program -f ./main.hex

	adc_init();
	DDRE |= 0x00;
	PORTE |= 0x10;//active le pull up

	//initialisation du fpga
	sbi(XMCRA,SRW11);
	sbi(XMCRA,SRW00);
	sbi(MCUCR,SRE);
	wait_ms(1000);

	//on reset le fpga
	U_RESET = 0x42;
	sbi(PORTB,0);
	wait_ms(100);

	//on relache le reset
	cbi(PORTB,0);
	sbi(PORTE,3);
	wait_ms(100);
	
	//printf("stack begin :%d \n", &a);
	//init des interruptions
	printf("init i2c \n");
	scheduler_init();


	position_init(&pos);
	asserv_init(&asserv,&pos);
	trajectory_init(&traj,&pos,&asserv);
	i2cm_init();
	//autorise les interruptions
	sei(); 

	//infinite loop!!!
	//get_enc_value();

	//init communication
	#ifdef ENABLE_MECA
	printf("init com \n");
	initCom();
	printf("end init com \n");
	#endif

	//init A*
	initObstacle();

	//init méca
	#ifdef ENABLE_MECA
	mecaCom(TIROIR_FERMER);
	mecaCom(PEIGNE_FERMER);
	#endif
	
	team = getTeam();
	while(MAXIME);//boucle anti_maxime
	// while(1)
	// {
	// 	printf("gp2r = %d ,gp2l = %d ,gp2m = %d \n",adc_get_value(ADC_REF_AVCC | MUX_ADC0),adc_get_value(ADC_REF_AVCC | MUX_ADC1),adc_get_value(ADC_REF_AVCC | MUX_ADC2));
	// }

	//avoidance_init();
	//antipatinage_init();

	// homologation();
	// while(1);

	// test_evitement();
	// while(1);	

	if(team == RED)
	{




		disableSpinning();	

		findPosition(team);
		enableSpinning();


		trajectory_goto_d(&traj, END, 20);
		trajectory_goto_a(&traj, END, 55);
		while(!trajectory_is_ended(&traj));
	//
	// trajectory_goto_a(&traj, END, 90);
	// 
	// trajectory_goto_a(&traj, END, 0);	
	// while(!trajectory_is_ended(&traj));


		asserv_set_vitesse_normal(&asserv);
		initTaskManager(&tkm);



		//addTask(&tkm, &returnFire, LOW_PRIORITY, R1);
		addTask(&tkm, &throwSpears, LOW_PRIORITY, RED);
		addTask(&tkm, &putPaint, HIGH_PRIORITY, team);
		// addTask(&tkm, &returnFire, LOW_PRIORITY, R3);
		// addTask(&tkm, &returnFire, HIGH_PRIORITY, R2);
		addTask(&tkm, &takeFruitRed, HIGH_PRIORITY, team);
		// addTask(&tkm, &takeFruitYellow, HIGH_PRIORITY, team);
		// addTask(&tkm, &findPosition, HIGH_PRIORITY, REDPAINT);
		// addTask(&tkm, &returnFire, HIGH_PRIORITY, Y1);
		//addTask(&tkm, &throwSpears, HIGH_PRIORITY, YELLOW);
		addTask(&tkm, &putFruit, HIGH_PRIORITY, team);

		// addTask(&tkm, &returnFire, HIGH_PRIORITY, Y3);
		// addTask(&tkm, &takeFruitYellow, HIGH_PRIORITY, team);
		// addTask(&tkm, &putFruit, HIGH_PRIORITY, team);
		// addTask(&tkm, &returnFire, HIGH_PRIORITY, Y2);


		while (TIRETTE);
		printf("begin match \n");

		avoidance_init();

		while(doNextTask(&tkm));
		printf("finish \n");


	}
	else // Team jaune
	{

		disableSpinning();	

		findPosition(team);
		enableSpinning();


		trajectory_goto_d(&traj, END, 20);
		trajectory_goto_a(&traj, END, -55);
		while(!trajectory_is_ended(&traj));

		// addTask(&tkm, &returnFire, LOW_PRIORITY, R1);
		addTask(&tkm, &returnFire, LOW_PRIORITY, Y2);
		addTask(&tkm, &throwSpears, LOW_PRIORITY, YELLOW);
		addTask(&tkm, &putPaint, HIGH_PRIORITY, team);
		// addTask(&tkm, &returnFire, HIGH_PRIORITY, Y3);
		// addTask(&tkm, &takeFruitRed, HIGH_PRIORITY, team);
		addTask(&tkm, &takeFruitYellow, HIGH_PRIORITY, team);
		// addTask(&tkm, &returnFire, LOW_PRIORITY, R1);
		addTask(&tkm, &putFruit, HIGH_PRIORITY, team);
		

		// addTask(&tkm, &findPosition, HIGH_PRIORITY, YELLOWPAINT);
		//addTask(&tkm, &returnFire, HIGH_PRIORITY, R1);
		//addTask(&tkm, &throwSpears, HIGH_PRIORITY, RED);


		
		// addTask(&tkm, &returnFire, HIGH_PRIORITY, R3);
		
		// addTask(&tkm, &takeFruitRed, HIGH_PRIORITY, team);

		// addTask(&tkm, &putFruit, HIGH_PRIORITY, team);
		// addTask(&tkm, &returnFire, HIGH_PRIORITY, R2);
		

		while (TIRETTE);
		printf("begin match \n");


		avoidance_init();


		while(doNextTask(&tkm));
		printf("finish \n");
		// // attend que la tirette soit retirée

		// printf("begin match \n");
		// printf("start pos: x %lf pos y %lf \n",position_get_x_cm(&pos),position_get_y_cm(&pos));

	}

	printf("time: %ld \n",time_get_s());

	while(1);//attention boucle infinie
}