コード例 #1
0
ファイル: time.c プロジェクト: mru00/terracontrol
char* ttoa(const time_t time, char* buf) {
  itoat(time_get_h(time), buf+0);
  itoat(time_get_m(time), buf+3);
  itoat(time_get_s(time), buf+6);
  buf[2] = ':';
  buf[5] = ':';
  return buf;
}
コード例 #2
0
ファイル: main.c プロジェクト: teyssieuman/eurobot
int main(void)
{
  time_init(128);

  DDRB=0xFF;

  while(1)
    {
      PORTB=(uint8_t)time_get_s();
    }

  return 0;
}
コード例 #3
0
ファイル: main2.c プロジェクト: ohayak/tars_code
//////////////////////////////////////
// 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
}
コード例 #4
0
ファイル: commandline.c プロジェクト: mru00/terracontrol
// begin production parsers
static void parse_set_time(void) {
  checked(time_t t = parse_time());
  ds1307_settime(time_get_h(t), time_get_m(t), time_get_s(t));
}
コード例 #5
0
ファイル: cs.c プロジェクト: onitake/aversive
/* called every 5 ms */
static void do_cs(void *dummy) 
{
	static uint16_t cpt = 0;
	static int32_t old_a = 0, old_d = 0;

	wheel_update_value();

	/* robot system, conversion to angle,distance */
	if (mainboard.flags & DO_RS) {
		int16_t a,d;
		rs_update(&mainboard.rs); /* takes about 0.5 ms */
		/* process and store current speed */
		a = rs_get_angle(&mainboard.rs);
		d = rs_get_distance(&mainboard.rs);
		mainboard.speed_a = a - old_a;
		mainboard.speed_d = d - old_d;
		old_a = a;
		old_d = d;
	}

	/* control system */
	if (mainboard.flags & DO_CS) {
		if (mainboard.angle.on)
			cs_manage(&mainboard.angle.cs);
		if (mainboard.distance.on)
			cs_manage(&mainboard.distance.cs);
		if (mainboard.fessor.on) {
			cs_manage(&mainboard.fessor.cs);
			fessor_manage();
		}
		if (mainboard.wheel.on)
			cs_manage(&mainboard.wheel.cs);
		if (mainboard.elevator.on) {
			cs_manage(&mainboard.elevator.cs);
			elevator_manage();
		}
	}
	if ((cpt & 1) && (mainboard.flags & DO_POS)) {
		/* about 1.5ms (worst case without centrifugal force
		 * compensation) */
		position_manage(&mainboard.pos);
	}
	if (mainboard.flags & DO_BD) {
		bd_manage_from_cs(&mainboard.angle.bd, &mainboard.angle.cs);
		bd_manage_from_cs(&mainboard.distance.bd, &mainboard.distance.cs);
	}
	if (mainboard.flags & DO_TIMER) {
		uint8_t second;
		/* the robot should stop correctly in the strat, but
		 * in some cases, we must force the stop from an
		 * interrupt */
		second = time_get_s();
		if (second >= MATCH_TIME + 2) {
			pwm_ng_set(LEFT_PWM, 0);
			pwm_ng_set(RIGHT_PWM, 0);
			printf_P(PSTR("END OF TIME\r\n"));
			while(1);
		}
	}
	/* brakes */
	if (mainboard.flags & DO_POWER)
		BRAKE_OFF();
	else
		BRAKE_ON();
	cpt++;
}