Exemplo n.º 1
0
int main(int argc, char* argv[]) {


    carattere[cv]=getchar();
    //printf("dsadas: %c\n", carattere[cv]);
    while(carattere[cv]!='\n') {
        cv++;
        carattere[cv]=getchar();
    }
    v_croc=atoi(carattere);
    fp_log=fopen(file_log, "w");

    //delay_ms(999);


    robot_init();

#ifdef CONSOLE
    pv=malloc(sizeof(char)*30);
    //console_init();
#endif
#ifdef	CONSOLE_XBEE
    console_fd=xbee_fd;
    pthread_attr_t attr;
    pthread_t thread;
    pthread_attr_init (&attr);
    pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
    pthread_create (&thread, &attr, &thread_function, NULL);
    pthread_attr_destroy (&attr);



#endif

    wait_flag=TRUE;
    v_sx=0;
    v_dx=0;
    for(i=0; i<LEN_PIC_BUFFER; i++) {
        set_vel_2_array(pic_buffer[i],v_croc,v_croc);
    }


    while (1) {


        if(wait_flag==FALSE) {
            analizza_pacchetto();
            //cartesian_controller(state, goal, LINEAR_GAIN,ANGULAR_GAIN, v_d, w_d);
            //decoupled_controller(state, goal, &p_norm_d, &p_norm_d);


            fflush(fp_log);
            wait_flag=TRUE;
        }
    }



    return 0;
}
Exemplo n.º 2
0
void server_accept (server_t * s)
{
  struct sockaddr_storage   remoteaddr; // client address
  socklen_t                 addrlen;
  int                       newfd;
  char                      remote_ip[INET6_ADDRSTRLEN];

  addrlen = sizeof(remoteaddr);
  newfd = accept(s->listener, (struct sockaddr *) &remoteaddr, &addrlen);

  if (newfd == -1) {
    // server_perror("accept");
  } else {
    FD_SET(newfd, &(s->master)); // add to master set

    // Keep track of the max fd
    if (newfd > s->fdmax) {
      s->fdmax = newfd;
    }

    printf("(%d) client: new connection from %s\n",
      newfd, inet_ntop(remoteaddr.ss_family, get_in_addr((struct sockaddr*) &remoteaddr), remote_ip, INET6_ADDRSTRLEN));

    robot_init(&(s->robots[newfd]), newfd);
    s->robots[newfd]->server = s;
    robot_greet(s->robots[newfd]);
  }
}
Exemplo n.º 3
0
static void init()
{
	int i;
	g_prog_starting_ms = get_current_ms();
	g_working = true;
	for(i = 0; i < g_config.robot_num; ++i)
	{
		robot_init(&g_robot[i], i);
		if(pthread_create(&g_robot[i].thread_id, NULL, robot_work, &g_robot[i]) != 0)
		{
			ERROR_PRINT("robot[%d] pthread_create errno %d, %s", i, errno, strerror(errno));
			exit(1);
		}
	}
	srand((unsigned int)time(NULL));
}
Exemplo n.º 4
0
int main (int argc, char **argv)
{
	int nneurons, nsynapses, maxfactor = 10;
	unsigned int seed;
	struct timeval tv;
	robot_t *r;

	progname = "robot-gen";
	gettimeofday (&tv, 0);
	seed = tv.tv_sec + tv.tv_usec;
	for (;;) {
		switch (getopt (argc, argv, "vtds:m:")) {
		case EOF:
			break;
		case 'v':
			++verbose;
			continue;
		case 't':
			++trace;
			continue;
		case 'd':
			++debug;
			continue;
		case 's':
			seed = strtol (optarg, 0, 0);
			continue;
		case 'm':
			maxfactor = strtol (optarg, 0, 0);
			continue;
		default:
			usage ();
		}
		break;
	}
	argc -= optind;
	argv += optind;

	if (argc != 2)
		usage ();

	nneurons = strtol (argv[0], 0, 0);
	nsynapses = strtol (argv[1], 0, 0);
	srandom (seed);
	r = robot_init (nneurons, nsynapses, maxfactor);
	robot_save (r, stdout, 0);
	return (0);
}
Exemplo n.º 5
0
//TOP200内的繁殖,同姓之间繁殖优先展开,如果同姓是奇数,余下的才随机匹配繁殖
void lab_robot_evolve(ROBOTS robots, RACIALS racials, PROBOT top_robots[], PROBOT odd_robots[])
{
	int oc = 0, index = gConfig.lab_more_robot_top_count;
	for(int ri=0;ri<gConfig.lab_more_robot_top_count;ri++) //种族循环
	{
		long key = racials[ri].father_id;
		if(key == 0) //没有了
		{
			break;
		}

		//从前20%取出该族的族人Top
		int tc = 0;
		for(int i=0;i<gConfig.lab_more_robot_top_count;i++)
		{
			if(robots[i].father_id == key)
			{
				top_robots[tc] = &robots[i];
				tc++;
			}
		}

		if(tc % 2 == 1) //奇数个,取出最后一个备用
		{
			tc--; //计数减去多余那个
			odd_robots[oc] = top_robots[tc];
			oc++;
		}

		//打乱Top机器人的指针
		for (int i=0; i<tc; i++)
		{
			int r = rand() % tc;

			PROBOT t = top_robots[i];
			top_robots[i] = top_robots[r];
			top_robots[r] = t;
		}

		//Top繁殖到中20%
		index = lab_robot_evolve(robots, index, top_robots, tc);
	}
	if(oc > 0)
	{
		//奇数Top繁殖到中20%
		index = lab_robot_evolve(robots, index, odd_robots, oc);
	}

	//前20%得分清零
	for(int i=0;i<gConfig.lab_more_robot_top_count;i++)
	{
		robots[i].score = 0;
	}

	//剩下的重新初始化基因
	for(int i=index;i<gConfig.lab_more_robot_count;i++)
	{
		//基因重新生成,但存储地址不变
		ROBOT &robot = robots[i];
		robot_init(robot, 0, 0, robot_gene_make(robot.gene), robot.steps);
	}
}
Exemplo n.º 6
0
Arquivo: main.c Projeto: eerimoq/romeo
static int test_automatic(struct harness_t *harness_p)
{
    int i;
    float omega;
    struct robot_t robot;
    const struct testdata_t FAR *testdata_p;

    parameter_charging_value = 1;

    robot_module_init();
    robot_init(&robot);
    robot_start(&robot);

    testdata_p = test_automatic_testdata;

    /* Tick the robot to enter cutting state. */
    robot_tick(&robot);
    robot_tick(&robot);
    robot_tick(&robot);

    /* The actual verification of robot behaviour is done in the
       stubs. */
    i = 0;

    while (testdata_p->input.energy_level != -1) {
        std_printf(FSTR("id: %d\r\n"), testdata_p->id);

        /* Prepare the stubs. */
        motor_stub_omega_next = 0;
        motor_stub_current_next = 0;
        perimeter_wire_rx_stub_signal_next = 0;
        battery_stub_energy_level_next = 0;

        motor_stub_current[0] = testdata_p->input.motor_current;
        perimeter_wire_rx_stub_signal[0] = testdata_p->input.perimeter_signal;
        battery_stub_energy_level[0] = testdata_p->input.energy_level;

        /* Tick the robot. */
        robot_tick(&robot);

        if (testdata_p->output.compare == 1) {
            /* Compare output to reference data. */
            BTASSERT(motor_stub_omega_next == 2, "next = %d", motor_stub_omega_next);
            omega = motor_stub_omega[0];
            BTASSERT(float_close_to_zero(omega - testdata_p->output.left_wheel_omega), 
                     "[%d]: from robot: %f, testdata: %f",
                     i,
                     omega,
                     testdata_p->output.left_wheel_omega);
            omega = motor_stub_omega[1];
            BTASSERT(float_close_to_zero(omega - testdata_p->output.right_wheel_omega), 
                     "[%d]: %f %f",
                     i,
                     omega,
                     testdata_p->output.right_wheel_omega);
        }

        i++;
        testdata_p++;
    }

    return (0);
}