Esempio n. 1
0
int main(int argc, char **argv)
{
    int c_sock;/*client socket*/
    int rc;
    char buf[BUFFER_SIZE];
    motor_opts_t motor;
    agv2Buffer(argv, argc, buf);
/*Decode argv and init connection to server*/
    rc = start_app(buf, BUFFER_SIZE, &c_sock);
    if(rc < 0)
    {
	    perror("client: Failed to start c-app");
	    return -1;
    }
    else
	    printf("c-app: client app start-up complete\n");
    /*Prepare bt_packets to send with data from app_options_t
     * For now prepare only motor opts*/
    comm_handler(c_sock);
    return 0;
}
Esempio n. 2
0
/*### Mainloop ###*/
int main(void)
{
	WDT_TRIGGERED(); //Watchdogreset?

	init_sys();
	init_pwm();
	init_timer();
	dist_init();
	uart_init(UART_BAUD_SELECT(UART_MCU_BAUD_RATE,F_CPU)); //Bluetooth
	comm_init();
	init_adc();

	mot.off = 0;
	//The higher the task_i of the task is, the higher is the priority
	
	MAIN_LED_OFF();

	tasks[TASK_TIMER_ID].state = -1;
	tasks[TASK_TIMER_ID].period = TASK_PERIOD_TIMER;
	tasks[TASK_TIMER_ID].elapsedTime = 0;
	tasks[TASK_TIMER_ID].running = 0;
	tasks[TASK_TIMER_ID].task_fct = &task_timer;

	tasks[TASK_SPEEDREG_ID].state = -1;
	tasks[TASK_SPEEDREG_ID].period = TASK_PERIOD_SPEEDREG;
	tasks[TASK_SPEEDREG_ID].elapsedTime = 0;
	tasks[TASK_SPEEDREG_ID].running = 0;
	tasks[TASK_SPEEDREG_ID].task_fct = &task_speedreg;

	tasks[TASK_ANASENS_ID].state = -1;
	tasks[TASK_ANASENS_ID].period = TASK_PERIOD_ANASENS;
	tasks[TASK_ANASENS_ID].elapsedTime = 0;
	tasks[TASK_ANASENS_ID].running = 0;
	tasks[TASK_ANASENS_ID].task_fct = &task_anasens;

	if(get_incrOk())
		debug = 1;
	else
		debug = 0;

	sei(); //Enable global interrupts. The Operating System and every task in it is running now and the cam already can regulate its initial aparture

	bt_putStr_P(PSTR("\r\n\n\n\n\n\n\n\n"));
	bt_putStr_P(PSTR("–––––––––––––––––––––––\r\n"));
	bt_putStr_P(PSTR("| RIOS Scheduler v1.0 |\r\n"));
	bt_putStr_P(PSTR("–––––––––––––––––––––––\r\n"));
	bt_putStr_P(PSTR("rcj2015 v2.0\r\n"));
	bt_putStr_P(PSTR("Subcontroller ATmega2560\r\n"));
	bt_putStr_P(PSTR("Baud rate: "));bt_putLong(UART_COMM_BAUD_RATE); bt_putStr_P(PSTR(" Baud.\r\n"));
	bt_putStr_P(PSTR("\r\n")); bt_putLong(timer); bt_putStr_P(PSTR(": System initialized, ")); bt_putLong(TASKS_NUM); bt_putStr_P(PSTR(" running tasks.\n\n"));
	
	if(check_res)
	{
		motor_activate(0); //Shut down motor driver
		if(debug > 0){bt_putStr_P(PSTR("\r\n")); bt_putLong(timer); bt_putStr(PSTR(": WARNING: RECOVERED AFTER AN UNEXPECTED SHUTDOWN!!!\n\n"));}
		_delay_ms(5000);
	}

	wdt_enable(WDTO_1S); //activate watchdog

	timer_get_tast = 120;

	while(1)
    {
		wdt_reset();

		////////////////////////////////////////////////////////////////////////////
		comm_handler(); //Handle and respond to comm requests.
		comm_reg_gateway();

		////////////////////////////////////////////////////////////////////////////

		if((timer_get_tast == 0) && (setup == 0))
		{
			timer_get_tast = -1;
			mot.off = 0;
		}

		if(get_t1()) //Always reset...
		{
			mot.off = 1;
			timer_get_tast = 120;
		}

		////////////////////LED etc...//////////////////////////////////////

		if(timer_mainloop == 0)
		{
			if(check_res || fatal_err)	//Flashing of the Info LED when there is an error
				led_fault = 1;
			else if(timer_nocomm == 0)
				led_fault = 85; //Blink green if no communication/waiting for command
			else if(mot.off)
				led_fault = 30;
			else
				led_fault = 0;

			if(fatal_err)
				led_top = LED_TOP_FAT_ERR;
			else
				led_top = LED_TOP_NORMAL;

			if(check_res)
			{
				if(!(debug_err_sendOneTime & (1<<0)))
				{
					if(debug > 1){bt_putStr_P(PSTR("\n\r")); bt_putLong(timer); bt_putStr_P(PSTR(": ERROR: RESET"));}
					debug_err_sendOneTime |= (1<<0);
				}
			}
			else	debug_err_sendOneTime &= ~(1<<0);

			//Batterie/Akku
			if(batt_raw > 0)
			{
				batt_mV = (batt_raw*15)-300;

				if(batt_mV < batt_mV_old)
				{
					batt_mV_old = batt_mV;
					batt_percent = (0.037*batt_mV) - 363;
				}
				if(batt_percent < 20) //Batterie
					led_heartbeatColor = batt_percent;
			}

			////////////////////////////////////////////////////////////////////////////
			//LED heartbeat

			if(rgb_led_mode == 0)
				led_rgb(led_heartbeatColor, led_fault, led_top);
			else
				led_hsvToRgb(rgb_led_hue, rgb_led_sat, rgb_led_val);

			timer_mainloop = TIMER_MAINLOOP;
		}
	}
	return 0;
}