예제 #1
0
/**
 * Determinates IR light interference prior to aoa detection and sets
 * threshold for additional noise suppression.
 * Before LED light is turned on all photodetector values which represent
 * ambient light are read and stored so they can be subtracted later.
 * After that all photodetector values are read again and previously stored
 * values are substracted. Largest value that deviate from 0 is stored as
 * threshold.
 */
void AoAPlug::set_threshold() {
  int noise = 0;
  threshold = AOA_NOISE_THRESHOLD;

  read_inputs(interf);
  read_inputs(interf2);

  for (uint8_t i=0; i < AOA_INPUTS_NUM; i++) {
    noise = interf2[i] - interf[i];
    if (abs(noise) > threshold) {
      threshold = abs(noise) + AOA_NOISE_THRESHOLD;
    }
  }
}
예제 #2
0
파일: debug.c 프로젝트: AceXIE/xenomai-lab
void loop(void *arg){

        char buf[CHAR_BUFFER_SIZE];
	int count = 0;

        sprintf(buf,"%s%s",getenv("HOME"),"/.xenomailab/workspace/debug.log");

	if((log=fopen(buf, "w")) == NULL)
		ERROR("Failed open %s to write!\n",buf);

	while (running) {
		read_inputs();
		
		if(count < MAX_TICKS){
			LOG("\n********* TICK #%d\n",(int)io.input_result[0].matrix[0][0]);
		
			periodic_function(io.input_result,io.input_num);
			settings_unlock(&gs_mtx);
			count++;
		} else {
			settings_unlock(&gs_mtx);
			break;
		}

	}

	fclose(log);
}
예제 #3
0
int initialize(int* argc, char*** argv) {
	int j,k;
	double theta;
	double r;

	MPI_Init(argc,argv);
	MPI_Comm_size(MPI_COMM_WORLD, &comm_size);
	MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank);
	MPI_Info_create(&info);

	read_inputs(argc,argv);

	N = (int)((data_size*1024*1024)/((double) sizeof(double)));
	pc = comm_size;
	zc = (pc*zpp)/ppz;
	Nl = N/comm_size/zpp;

	zones = malloc(zc*sizeof(int));
	subzones = malloc(zpp*sizeof(int));
	for(k=0;k<zpp;k++) {
		zones[k] = comm_rank/ppz*zpp+k;
		subzones[k] = comm_rank%ppz;
		}

	/* Initialize Arrays */
	x = malloc(Nl*sizeof(double));
	y = malloc(Nl*sizeof(double));
	z = malloc(Nl*sizeof(double));

	e = malloc(Nl*sizeof(cgsize_t));

	u = malloc(Nl*sizeof(double));
	v = malloc(Nl*sizeof(double));
	w = malloc(Nl*sizeof(double));

	h = malloc(Nl*sizeof(double));

	for(k=0;k<Nl;k++) {
		j = Nl*subzones[0]+k;
		theta = ((double) j)/((double) Nl*zpp);
		r = theta;
		x[k] = r*cos(theta);
		y[k] = r*sin(theta);
		z[k] = r;
		e[k] = j+1;
		u[k] = x[k];
		v[k] = y[k];
		w[k] = z[k];
		h[k] = r;
		}

#if 0
	printf("%d: Nl %d\n",comm_rank,Nl);
	for(k=0;k<zpp;k++) printf("%d: Z%d.%d\n",comm_rank,zones[k],subzones[k]);
#endif

	return 0;
	}
예제 #4
0
파일: main.cpp 프로젝트: guillep19/frob
void run_vm() {
  graph = create_graph();
  ip = (WORD*) code;
  run_thread();
  while (1) {
    read_inputs();
    update_signals();
    write_outputs();
  }
}
예제 #5
0
/**
 * Sets values to be used in get_aoa methods
 */
void AoAPlug::set_values() {
  int diff = 0;

  read_inputs(values);
  for (uint8_t i=0; i<AOA_INPUTS_NUM; i++) {
    diff = values[i] - interf[i];
    // set to 0 all values that are above interf by less than threshold
    values[i] = (diff > threshold) ? (uint16_t)diff : 0;
  }
}
예제 #6
0
void loop(void *arg){
	Matrix outputMatrix;

	blackbox_init();

	while (running) {
		read_inputs();
		
		outputMatrix=periodic_function(io.input_result,io.input_num);

		write_outputs(outputMatrix);

	}

	blackbox_close();
}
예제 #7
0
void loop(void *arg)
{
	RT_HEAP sampling_heap;
	current_period=bind_shm(&sampling_heap,"tickPeriod",sizeof(long));
	
	Matrix outputMatrix=empty_matrix(1,1);
	DEBUG("Outputing a %s wave of amplitude %4.2f, freq %4.2f, duty %4.2f, dc %4.2f\n",gs->wave,gs->wave_amp,gs->wave_freq,gs->wave_duty,gs->wave_dc);

	while (running) {
		read_inputs();
		
		outputMatrix=periodic_function(io.input_result,io.input_num);

		write_outputs(outputMatrix);

	}

	unbind_shm(&sampling_heap);
}
예제 #8
0
int
main (int argc, char* argv[]) {
    
    // Read inputs
    Inputs* inputs = read_inputs();

    // Create image
    Image* image = new_image(
            inputs->box.xMax - inputs->box.xMin,
            inputs->box.yMax - inputs->box.xMin);

    // Generate random colors
    Color colors[inputs->numSites];
    for (int i = 0; i < inputs->numSites; i++) {
        colors[i] = random_color(); 
    }

    // Bruteforce voronoi
    for (int i = inputs->box.xMin; i < inputs->box.xMax; i++) {
        for (int j = inputs->box.yMin; j < inputs->box.yMax; j++) {
            Point curr = { .x = i, .y = j };
            int nearest = 0;
            for (int k = 0; k < inputs->numSites; k++) {
                double old_dist = distance_squared(&curr, &inputs->sites[nearest]);
                double new_dist = distance_squared(&curr, &inputs->sites[k]);
                if (new_dist < old_dist) {
                    nearest = k;
                }
            }
            set_pixel(i, j, colors[nearest], image); 
        }
    }

    // Do line sweep
    fortune(inputs, image);
    print_image(image);

    // Free memory
    free_image(image);
    free_inputs(inputs);

    return 0;
}
예제 #9
0
void loop(void *arg){
	Matrix outputMatrix=empty_matrix(1,1);
	RT_TASK pwm_task;

	lpt_init();

	rt_task_spawn(&pwm_task,NULL,0,gs->task_prio,0,&pwm,NULL);

	while (running) {
		read_inputs();
		
		//outputMatrix=periodic_function(io.input_result,io.input_num);

		write_outputs(outputMatrix);
	}

	rt_task_delete(&pwm_task);

	lpt_close();
}
예제 #10
0
파일: floorplan.c 프로젝트: 8l/insieme
void floorplan_init (char *filename)
{
	int i,j;

	inputFile = fopen(filename, "r");

	if(NULL == inputFile) {
		bots_message("Couldn't open %s file for reading\n", filename);
		exit(1);
	}

	/* read input file and initialize global minimum area */
	read_inputs();
	MIN_AREA = ROWS * COLS;

	/* initialize board is empty */
	for (i = 0; i < ROWS; i++)
		for (j = 0; j < COLS; j++) board[i][j] = 0;

}
예제 #11
0
파일: sum.c 프로젝트: AceXIE/xenomai-lab
void loop(void *arg){
	Matrix outputMatrix;

	/*
	 * Insert initialization code here.
	 * e.g. open a file.
	 */

	while (running) {
		read_inputs();
		
		outputMatrix=periodic_function(io.input_result,io.input_num);

		write_outputs(outputMatrix);

	}

	/*
	 * Insert finalization code here
	 * e.g. close a file.
	 */
}
예제 #12
0
int main(int argc, char **argv) {
    int i;
    for (i = 1; i < argc; i++) {
        if (!strcmp(argv[i], "-rom")) {
            if (++i == argc) usage();
            if (++i == argc) usage();
            FILE *rom = fopen(argv[i], "r");
            if (!rom) {
                fprintf(stderr, "Could not open ROM file: '%s'\n", argv[i]);
                return 1;
            }
            add_rom(argv[i-1], rom);
            fclose(rom);
        } else if (!strcmp(argv[i], "-n")) {
            if (++i == argc) usage();
            steps = atoi(argv[i]);
        } else if (!strcmp(argv[i], "-in")) {
            if (++i == argc) usage();
            infile = argv[i];
        } else if (!strcmp(argv[i], "-out")) {
            if (++i == argc) usage();
            outfile = argv[i];
        } else {
            filename = argv[i];
        }
    }

    if (filename == NULL) usage();

    // Load program
    FILE *p_in;
    p_in = fopen(filename, "r");
    if (!p_in) {
        fprintf(stderr, "Error: could not open file %s for input.\n", filename);
        return 1;
    }
    t_program* program = load_dumb_netlist(p_in);
    fclose(p_in);

    // Setup input and outputs
    FILE *input = stdin, *output = stdout;
    if (infile != NULL) {
        input = fopen(infile, "r");
        if (!infile) {
            fprintf(stderr, "Error: could not open file %s for input.\n", infile);
            return 1;
        }
    }
    if (outfile != NULL) {
        output = fopen(outfile, "w");
        if (!output) {
            fprintf(stderr, "Error: could not open file %s for output.\n", outfile);
            return 1;
        }
    }

    // Run
    t_machine *machine = init_machine(program);
    machine_banner(machine, output);
    i = 0;
    while (i < steps || steps == 0) {
        read_inputs(machine, input);
        machine_step(machine);
        write_outputs(machine, output);
        i++;
    }

    // Cleanup
    if (input != stdin) fclose(input);
    if (output != stdout) fclose(output);

    // No need to free memory, the OS deletes everything anyways when the process ends.

    return 0;
}
예제 #13
0
파일: main.c 프로젝트: Miguel-1992/PICnc-V2
int main(void)
{
	int i, spi_timeout;
	unsigned long counter;

	/* Disable JTAG port so we get our I/O pins back */
	DDPCONbits.JTAGEN = 0;
	/* Enable optimal performance */
	SYSTEMConfigPerformance(GetSystemClock());
	/* Use 1:1 CPU Core:Peripheral clocks */
	OSCSetPBDIV(OSC_PB_DIV_1);

	/* configure the core timer roll-over rate */
	OpenCoreTimer(CORE_TICK_RATE);

	/* set up the core timer interrupt */
	mConfigIntCoreTimer((CT_INT_ON | CT_INT_PRIOR_6 | CT_INT_SUB_PRIOR_0));

	/* enable multi vector interrupts */
	INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
	INTEnableInterrupts();

	map_peripherals();
	init_io_ports();
	configure_pwm();
	init_spi();
	init_dma();

	/* wait until tx buffer is filled up */
	while (!SPI2STATbits.SPITBF);

	reset_board();
	spi_data_ready = 0;
	spi_timeout = 0;
	counter = 0;

	/* enable watchdog */
	WDTCONSET = 0x8000;

	/* main loop */
	while (1) {
		if (spi_data_ready) {
			spi_data_ready = 0;

			/* the first element received is a command string */
			switch (rxBuf[0]) {
			case 0x5453523E:	/* >RST */
				reset_board();
				break;
			case 0x314D433E:	/* >CM1 */
				stepgen_update_input((const void *)&rxBuf[1]);
				stepgen_get_position((void *)&txBuf[1]);
				break;
			case 0x324D433E:	/* >CM2 */
				update_outputs(rxBuf[1]);
				update_pwm_duty((uint32_t *)&rxBuf[2]);
				txBuf[1] = read_inputs();
				break;
			case 0x4746433E:	/* >CFG */
				stepgen_update_stepwidth(rxBuf[1]);
				update_pwm_period(rxBuf[2]);
				stepgen_reset();
				break;
			case 0x5453543E:	/* >TST */
				for (i=0; i<BUFSIZE; i++)
					txBuf[i] = rxBuf[i] ^ ~0;
				break;
			}
		}

		/* if rx buffer is half-full, update the integrity check.
		   There isn't enough time if we wait for complete transfer */
		if (DCH0INTbits.CHDHIF) {
			DCH0INTCLR = 1<<4;		/* clear flag */
			txBuf[0] = rxBuf[0] ^ ~0;
		}

		/* if rx buffer is full, data from spi bus is ready */
		if (DCH0INTbits.CHBCIF) {
			DCH0INTCLR = 1<<3;		/* clear flag */
			spi_data_ready = 1;
			spi_timeout = SPI_TIMEOUT;
		}

		/* reset the board if there is no SPI activity */
		if (spi_timeout)
			spi_timeout--;

		if (spi_timeout == 1) {				
			DCH0ECONSET=BIT_6;	/* abort DMA transfers */
			DCH1ECONSET=BIT_6;
		
			init_spi();
			init_dma();
			reset_board();

			/* wait until tx buffer is filled up */
			while (!SPI2STATbits.SPITBF);
		}

		/* blink onboard led */
		if (!(counter++ % (spi_timeout ? 0x10000 : 0x40000))) {
			LED_TOGGLE;
		}

		/* keep alive */
		WDTCONSET = 0x01;
	}
	return 0;
}
예제 #14
0
int main(int argc, char *argv[]) {
    std::string ip_address = "";
    int parse_ret = parse_command_line_options(argc, argv, ip_address);
    if(parse_ret != 1)
        return parse_ret;

    if(ip_address.empty()) {
        ip_address = DEFAULT_IP_ADDR;
    }

    print_intro();

    modbus_t *mb;

    mb = modbus_new_tcp(DEFAULT_IP_ADDR, 502);
    if (mb == NULL) {
        fprintf(stderr, "Unable to allocate libmodbus context\n");
        return -1;
    }
    if (modbus_connect(mb) == -1) {
        fprintf(stderr, "Connection failed: %s\n", modbus_strerror(errno));
        modbus_free(mb);
        return -1;
    }

    setup_interupt();

    bool write_bool = true;
    int  write_num  = 0;
    unsigned int count = 0;
    uint8_t outputs[16] = {0};

    //variables for calculations
    bool button_pressed = false;

    try {
        while (true) {
            uint16_t input = 0;
            if(read_inputs(mb, &input) == -1)
                break;
            button_pressed = get_input_bit(input, 9);

            //solenoid = button xor photoeyen
            bool sol_out = button_pressed ^ get_input_bit(input, 2);

            outputs[0] = sol_out;

            if(write_outputs(mb, outputs) == -1)
                break;


            print_io(input, outputs);

            /* code for incrmenting IO
            count++;
            if(count%50==0){
                outputs[write_num] = write_bool;
                write_num++;
            }
            if(write_num==16){
                write_bool = !write_bool;
                write_num = 0;
            }*/
            usleep(1*1000); //Sleep 1ms
        }
    } catch(InterruptException& e) {
        modbus_close(mb);
        modbus_free(mb);
    }
}
예제 #15
0
파일: main.c 프로젝트: shivanth/C_CODE
//int count =0;
int main()
{
    read_inputs();
    return 0;
}