示例#1
0
/*! \brief The "main" function of the avoider demo */
void run_breitenberg_shocker(void)
{	
	e_init_port();
	e_init_motors();
	e_init_ad_scan(ALL_ADC);
	
	e_calibrate_ir();

	e_activate_agenda(flow_led, 900);
	e_activate_agenda(shock_neuron, 650);
	e_start_agendas_processing();
	while(1);
}
示例#2
0
/*! \brief The "main" function of the follower demo */
void run_breitenberg_follower(void)
{
	e_init_port();
	e_init_motors();
	e_init_ad_scan(ALL_ADC);
	
	e_calibrate_ir();

	e_activate_agenda(k2000_led, 2500);
	e_activate_agenda(follow_neuron, 650);
	e_start_agendas_processing();
	while(1);
}
示例#3
0
文件: main.c 项目: noether/tinysp
int main() {

    e_init_port();
    e_init_uart1();
    e_led_clear();

    e_activate_agenda(e_blink_led0, 2500);
    e_activate_agenda(radio, 100);
    e_start_agendas_processing();

    while(1){
        for ( delay = 0 ; delay < 15000; delay++){
            __asm__("nop");
        }
    }

    return 0;
}
示例#4
0
void e_init_randb ( unsigned char mode )
{
	if ( mode == I2C )
	{
		/* Init I2C */
		e_i2cp_init();
		e_i2cp_enable();
	}
	else
	{
		/* Init UART2 */
		e_init_uart2();
		
		/* Clean UART buffer */
		char msg;
		while(e_getchar_uart2(&msg));

		/* Start Agendas */
		e_start_agendas_processing();

		/* Locate e-randb task */
		e_activate_agenda(e_randb_get_uart2, 2);
		
		/* Tell the board we work on UART mode */
		e_randb_set_uart_communication(UART);
	}

	/* Calculations are made on the BOARD*/
	calcOnBoard = TRUE;

	/* Init Global variables */
	erandbFinished = FALSE;
	erandbState = WAITING;
	erandbCounter = 0;

}
示例#5
0
int main()
{
    // init robot
    e_init_port();
    e_init_ad_scan();
    e_init_uart1();
    e_led_clear();	
    e_init_motors();
    e_start_agendas_processing();

    // wait for s to start
    btcomWaitForCommand('s');
    btcomSendString("==== READY - IR TESTING ====\n\n");

    e_calibrate_ir(); 

    // initialize ircom and start reading
    ircomStart();
    ircomEnableContinuousListening();
    ircomListen();

    // rely on selector to define the role
    int selector = getselector();

    // show selector choosen
    int i;
    long int j;
    for (i = 0; i < selector; i++)
    {
	e_led_clear();
	
	for(j = 0; j < 200000; j++)
	    asm("nop");
	
	e_set_led(i%8, 1);
	
	for(j = 0; j < 300000; j++)
	    asm("nop");

	e_led_clear();

	for(j = 0; j < 300000; j++)
	    asm("nop");
    }

    // activate obstacle avoidance
    e_activate_agenda(obstacleAvoidance, 10000);

    // acting as sender
    if (selector == 1)
    {    	
	btcomSendString("==== EMITTER ====\n\n");

	int i;
	for (i = 0; i < 10000; i++)
	{
	    // takes ~15knops for a 32window, avoid putting messages too close...
	    for(j = 0; j < 200000; j++)	asm("nop");

	    ircomSend(i % 256);	    
	    while (ircomSendDone() == 0);

	    btcomSendString(".");
	}
    }
    
    // acting as receiver
    else if (selector == 2)
    {
	btcomSendString("==== RECEIVER ====\n\n");

	int i = 0;
	while (i < 200)
	{
	    // ircomListen();
	    IrcomMessage imsg;
	    ircomPopMessage(&imsg);
	    if (imsg.error == 0)
	    {
		int val = (int) imsg.value;
	    
		/* Send Value*/		
		char tmp[128];
		sprintf(tmp, "Receive successful : %d  - distance=%f \t direction=%f \n", val, (double)imsg.distance, (double)imsg.direction);
		btcomSendString(tmp);
	    }
	    else if (imsg.error > 0)
	    {
		btcomSendString("Receive failed \n");		
	    }
	    // else imsg.error == -1 -> no message available in the queue

	    if (imsg.error != -1) i++;
	}
    }
    // no proper role defined...
    else 
    {
	int i = 0;
	long int j;
	while(1)
	{
	    e_led_clear();
	    
	    for(j = 0; j < 200000; j++)
		asm("nop");
	    
	    e_set_led(i, 1);
	    
	    for(j = 0; j < 300000; j++)
		asm("nop");
	    
	    i++;
	    i = i%8;
	}	
    }    
    
    ircomStop();
    return 0;
}
示例#6
0
int main(void)
{

    int cam_mode,cam_x1,cam_y1,cam_width,cam_heigth,cam_zx,cam_zy;

    if(getSelector() == 0)
        return;

    char c;
    int i;//buff_length;
    //int wait_cam;

    //defining the position of the several inputs and outputs (motors are outputs) in the respective SFR
    //the SFR are programed as structures, so accessing to an input/output implies only acessing to the field of the structure corresponding to the SFR that was
    //assigned to that input/output (see epuck_ports.h and p30f6014.h to understand the SFR assignment)
    e_init_port();

    e_init_motors();

    //important to enable uart interface
    e_init_uart1();
    e_init_ad_scan(ALL_ADC);
    e_calibrate_ir();

    //initial configuration of the camera
    cam_x1=(ARRAY_WIDTH/Z_WIDTH-WIDTH)/2;
    cam_y1=(ARRAY_HEIGHT/Z_HEIGHT-HEIGHT)/2;
    cam_width=WIDTH;
    cam_heigth=HEIGHT;
    cam_zx=Z_WIDTH;
    cam_zy=Z_HEIGHT;
    cam_mode=MODE;

    if(cam_mode==GREY_SCALE_MODE)
            cam_size=cam_width*cam_heigth;
    else
            cam_size=cam_width*cam_heigth*2;

    //not waiting for camera
    wait_cam=0;

    e_activate_agenda(updateFlag, 500);//500//1000
    e_activate_agenda(readValues, 10);

    e_start_agendas_processing();
    keepFinding = 0;

    e_set_led(4,1);

    keepFinding = 1;

    int s = getSelector();
    while(s==getSelector());

    /*while(1){
        sprintf(b1,"%i\n",e_get_calibrated_prox(S_FRONT_LEFT));
        e_send_uart1_char(b1,10);
        while(e_uart1_sending());
    }*/

    while(1){
        while(keepFinding) {

            if(!cameraOn) {
                startCamera();
                correctRobot();
            }
            while(!captura());
            //e_send_uart1_char(buffer,buff_length);
            //while(e_uart1_sending());
            if(cameraOn > 5)
                processaImagem();
            cameraOn++;
        }

        if(cameraOn)
            stopCamera();

        while(!flag);
        flag = 0;
        sendInputs();

        readOrder();
        readOrder();

        e_set_speed_left(speedLeft);
        e_set_speed_right(speedRight);
        e_set_led(4,0);
    }

    return 0;
}
示例#7
0
/*! \brief Start blinking all LED
 *
 * \param cycle	   the number of cycle we wait before launching \ref e_blink_led(void)
 * \sa e_blink_led, e_activate_agenda
 */
void e_start_led_blinking(int cycle)
{
  e_activate_agenda(e_blink_led, cycle);
}
/*! \brief The "main" function of the program */
void run_wallfollow() {
	int leftwheel, rightwheel;		// motor speed left and right
	int distances[NB_SENSORS];		// array keeping the distance sensor readings
	int i;							// FOR-loop counters
	int gostraight;
	int loopcount;
	unsigned char selector_change;
	 
	e_init_port();
	e_init_ad_scan(ALL_ADC);
	e_init_motors();
	e_start_agendas_processing();

	//follow_sensor_calibrate();	
	
	e_activate_agenda(left_led, 2500);
	e_activate_agenda(right_led, 2500);
	e_pause_agenda(left_led);
	e_pause_agenda(right_led);
	
	e_calibrate_ir();
	loopcount=0;
	int selectionValue;
//	selector_change = !(followgetSelectorValue() & 0x0001);
	e_set_steps_right(0);
	selectionValue = followgetSelectorValue();
	while (doesWallExist(selectionValue)) {
		followGetSensorValues(distances); // read sensor values

		gostraight=0;
		if (selectionValue == 1) {
		////	if(selector_change == LEFT_FOLLOW) {
		//		selector_change = RIGHT_FOLLOW;
				e_led_clear();
				e_pause_agenda(left_led);
				e_restart_agenda(right_led);
	//		}  
			for (i=0; i<8; i++) {
				if (distances[i]>50) {break;}
			}
			if (i==8) {
				gostraight=1;
			} else {
				follow_weightleft[0]=-10;
				follow_weightleft[7]=-10;
				follow_weightright[0]=10;
				follow_weightright[7]=10;
				if (distances[2]>300) {
					distances[1]-=200;
					distances[2]-=600;
					distances[3]-=100;
				}
			}
		} else {
		//	if(selector_change == RIGHT_FOLLOW) {
			//	selector_change = LEFT_FOLLOW;
				e_led_clear();
				e_pause_agenda(right_led);
				e_restart_agenda(left_led);
		//	}
			for (i=0; i<8; i++) {
				if (distances[i]>50) {break;}
			}
			if (i==8) {
				gostraight=1;
			} else {
				follow_weightleft[0]=10;
				follow_weightleft[7]=10;
				follow_weightright[0]=-10;
				follow_weightright[7]=-10;
				if (distances[5]>300) {
					distances[4]-=100;
					distances[5]-=600;
					distances[6]-=200;
				}
			}
		}

		leftwheel=BIAS_SPEED;
		rightwheel=BIAS_SPEED;
		if (gostraight==0) {
			for (i=0; i<8; i++) {
				leftwheel+=follow_weightleft[i]*(distances[i]>>4);
				rightwheel+=follow_weightright[i]*(distances[i]>>4);
			}
		}

		// set robot speed
		followsetSpeed(leftwheel, rightwheel);

		wait(15000);
		
		//doesWallExist(selectionValue);
	}	
}
示例#9
0
/*! \brief Initialize the motors's agendas
 *
 * This function initialize the agendas used by the motors. In fact
 * it call \ref e_activate_agenda(void (*func)(void), int cycle) function.
 * \sa e_activate_agenda
 */
void e_init_motors(void)
{
  e_activate_agenda(run_left_motor, 0);
  e_activate_agenda(run_right_motor, 0);
}