예제 #1
0
void run_SensDispl() {
	int cam_mode,cam_width,cam_heigth,cam_zoom,cam_size;
	int i;
	unsigned long cam_light;
	unsigned char *buf_ptr;
	/*Cam default parameter*/
	cam_mode=GREY_SCALE_MODE;
	cam_width=20;
	cam_heigth=20;
	cam_zoom=8;
	cam_size=cam_width*cam_heigth;
	e_poxxxx_init_cam();
	e_poxxxx_config_cam((ARRAY_WIDTH -cam_width*cam_zoom)/2,(ARRAY_HEIGHT-cam_heigth*cam_zoom)/2,cam_width*cam_zoom,cam_heigth*cam_zoom,cam_zoom,cam_zoom,cam_mode);
	e_poxxxx_set_mirror(1,1);
	e_poxxxx_write_cam_registers();

	e_acc_calibr();
	while (1) {
		e_poxxxx_launch_capture(&buffer[0]);	// start camera capture
		e_led_clear();
		e_set_body_led(0);
		e_set_front_led(0);
		if (e_get_micro_volume(0)>30 || e_get_micro_volume(1)>30 || e_get_micro_volume(2)>30)
			e_set_body_led(1);
		if (e_get_prox(0)>400) 
			e_set_led(0,1);
		if (e_get_prox(1)>400) 
			e_set_led(1,1);
		if (e_get_prox(2)>400) 
			e_set_led(2,1);
		if (e_get_prox(3)>400) 
			e_set_led(3,1);
		if (e_get_prox(4)>400) 
			e_set_led(4,1);
		if (e_get_prox(5)>400) 
			e_set_led(5,1);
		if (e_get_prox(6)>400) 
			e_set_led(6,1);
		if (e_get_prox(7)>400) 
			e_set_led(7,1);
		while(!e_poxxxx_is_img_ready());	// wait end of capture
		cam_light=0;
		buf_ptr=(unsigned char*)&buffer[0];
		for (i=0; i<cam_size; i++) {
			cam_light+=*buf_ptr;
			buf_ptr++;
		}
		sprintf(buffer, "Cam light %lu\r\n", cam_light);
		e_send_uart1_char(buffer, strlen(buffer));
		if (cam_light>48000)	// 20*20pixels*120grayValue
			e_set_front_led(1);
		wait(5000);
	}								
}
예제 #2
0
int captura() {

    if(!wait_cam) {

            //start timer
            timer_counter=0;					//reseting repetition counter
            T1CONbits.TON=0;					//deactivating timer 1
            T1CON=0;
            T1CONbits.TCKPS=3;            		//prescaler = 256 - devides the timer counter by this value
            TMR1=0;                     		//clear timer 1 - the timer counter diveded by the prescaler is putted here (this value is compaired with the period)
            PR1=(FCY/256);  					//interrupt every 1 second with 256 prescaler
            IFS0bits.T1IF=0;            		//clear interrupt flag
            IEC0bits.T1IE=1;            		//set interrupt enable bit
            T1CONbits.TON=1;            		//start timer 1

            //initialize capture
            e_poxxxx_launch_capture(&buffer[0]);

            buff_length=cam_size;
            wait_cam=1;

    } if(wait_cam) {

            //if image is ready
        if(e_poxxxx_is_img_ready())
        {
                //stop timer
                T1CONbits.TON=0;

                //reset timer
                TMR1=0;

                //turn on timer
                T1CONbits.TON=1;

                //send image to sender
                
                //turn on timer
                T1CONbits.TON=0;

                //de-activate camera capture
                wait_cam=0;
                return 1;
        }
    }
    return 0;
}
예제 #3
0
void run_CameraTurn() {
	int cam_mode,cam_width,cam_heigth,cam_zoom,cam_size;
	int i;
	unsigned char *buf_ptr, pixel, lightest;
	unsigned int left, right, lightPos;

	#include "DataEEPROM.h"
	/*read HW version from the eeprom (last word)*/
	int HWversion=0xFFFF;
	int temp = 0;
	temp = ReadEE(0x7F,0xFFFE,&HWversion, 1);
	temp = temp & 0x03;	// get the camera rotation from the HWversion byte

	/*Cam default parameter*/
	cam_mode=GREY_SCALE_MODE;
	if ((temp==3)||(temp==0)) { // 0' and 180' camera rotation
		cam_width=1;
		cam_heigth=60;
	} else {
		cam_width=60;
		cam_heigth=1;
	}
	cam_zoom=8;
	cam_size=cam_width*cam_heigth;
	e_poxxxx_init_cam();
	e_poxxxx_config_cam((ARRAY_WIDTH -cam_width*cam_zoom)/2,(ARRAY_HEIGHT-cam_heigth*cam_zoom)/2,cam_width*cam_zoom,cam_heigth*cam_zoom,cam_zoom,cam_zoom,cam_mode);
	e_poxxxx_set_mirror(1,1);
	e_poxxxx_write_cam_registers();

	while (1) {
		e_poxxxx_launch_capture(&buffer[0]);	// start camera capture
		e_led_clear();
		e_set_body_led(0);
		e_set_front_led(0);

		while(!e_poxxxx_is_img_ready());	// wait end of capture
		buf_ptr=(unsigned char*)&buffer[0];
		left=0; right=0; lightPos=0; lightest=0;
		for (i=0; i<30; i++) {	//left
			pixel=*buf_ptr;
			buf_ptr++;
			left+=pixel;
			if (pixel>lightest) {
				lightest=pixel;
				lightPos=i;
			}
		}
		for (; i<cam_heigth; i++) {	//right
			pixel=*buf_ptr;
			buf_ptr++;
			right+=pixel;
			if (pixel>lightest) {
				lightest=pixel;
				lightPos=i;
			}
		}
		if (lightPos<20) {	//led on at lightest position
			e_set_led(7,1); }
		else if (lightPos<40) {
			e_set_led(0,1); }
		else {
			e_set_led(1,1); }

		if ((temp==3)||(temp==2)) { // 0' and 90' camera rotation
			e_set_speed_left(10*(lightPos-30));  // motor speed in steps/s
			e_set_speed_right(-10*(lightPos-30));
		} else {
			e_set_speed_left(-10*(lightPos-30));  // motor speed in steps/s
			e_set_speed_right(10*(lightPos-30));
		}

		sprintf(buffer, "left %u, right %u, lightest %u, lightPos %u\r\n", left, right, lightest, lightPos);
		e_send_uart1_char(buffer, strlen(buffer));
		wait(5000);
	}								
}