Beispiel #1
0
order_result_t trash_water_treatment(void){
  ROME_LOG(&rome_paddock,INFO,"Trashing water in treatment area");
  order_result_t or;
  set_speed(RS_FAST);

  _wait_meca_ready();
  ROME_SENDWAIT_MECA_CMD(&rome_meca,ROME_ENUM_MECA_COMMAND_PREPARE_TRASH_TREATMENT);
  _wait_meca_ground_clear();

  //store nb balls for scoring purpose
  uint8_t balls_loaded = robot_state.cylinder_nb_bad;

  //push away the cubes in front of treatment area
  //the angle is changed to avoid pushing cubes towards recyling area
  float angle = arfast(TEAM_SIDE_VALUE(ROBOT_SIDE_BACK, ROBOT_SIDE_BALLEATER), TABLE_SIDE_MAIN);

  or = goto_pathfinding_node(PATHFINDING_GRAPH_NODE_MIDDLE_BOT, angle);
  if (or != ORDER_SUCCESS)
    return or;

  //go in position to trash the bad water
  or = goto_xya(KX(-250),250+130, arfast(ROBOT_SIDE_TURBINE,TABLE_SIDE_DOWN));
  if (or != ORDER_SUCCESS)
    return or;
  _wait_meca_ready();
  ROME_SENDWAIT_MECA_CMD(&rome_meca,ROME_ENUM_MECA_COMMAND_TRASH_TREATMENT);
  _wait_meca_ground_clear();
  update_score(10*balls_loaded);

  or = goto_xya(KX(-250), 400, arfast(ROBOT_SIDE_TURBINE, TABLE_SIDE_DOWN));

  set_speed(RS_NORMAL);
  return or;
}
/*void follow_wall()
{
    set_speed(0);
    while (true)
    {
        take_picture();
        bool seen_wall = false;
        for (int i = -100; i < 100; i++) { for (int j = -50; j <= 50; j++) {
            int pixel = get_pixel(IMAGE_SIZE_X / 2 + i, IMAGE_SIZE_Y / 2 + j, COLOR_WHITE);
            if (pixel >= WHITE_THRESHOLD) {
                seen_wall = true;
                goto found_wall;
            }
        }}
        found_wall:

        if (seen_wall) {
            set_speed(20);//20
            turn(75);//-80
        } else {
            set_speed(30);//30
            turn(-75);//80
        }
    }
    halt();
}
*/
void follow_wall(){
	set_speed(50);
	turn(0);
	while(true){
		frontVal = read_analog(FRONT_PIN);
		leftVal = read_analog(LEFT_PIN);
		rightVal = read_analog(RIGHT_PIN);
		while(leftVal < (rightVal+40) && leftVal > (rightVal-40)){
			set_speed(50);
		}
		while(leftVal > (rightVal+40)){
			set_speed(40);			
			turn(10);
			Sleep(0, 500);
		}
		while(leftVal < (rightVal+40)){
			set_speed(40);			
			turn(-10);
			Sleep(0, 500);
		}
		if(frontVal > 550){
			if(rightVal < 300){
				turn(1 * SHARP_TURN);
				Sleep(0, TURN_WAIT);
			}
			if(leftVal < 300){
				turn(-1 * SHARP_TURN);
				Sleep(0, TURN_WAIT);
			}
		}
	}
}
Beispiel #3
0
void Material::move(Map *map)
{
    if (!m_ref_done) {
        int dx;
        if (m_from_chest) {
            dx = get_attribute("chest_speed");
        }
        else {
            dx = get_attribute("move_speed");
        }
        if (get_reference() == Right) {
            set_speed(dx, -get_attribute("rise_speed"));
        }
        else {
            set_speed(-dx, -get_attribute("rise_speed"));
        }
        set_accelration(0, get_attribute("weight"));
        m_ref_done = true;
    }

    Body::move(map);
    if (get_moving()) {
        animate_move();
    }
    else {
        m_frame = get_attribute("move_still");
    }

    if (get_fall()) {
        m_reachable = true;
    }
}
Beispiel #4
0
bool Player::set_hit(Object *object)
{
    bool result = false;

    if (!m_invisible) {
        // TODO: Check if player hp is above zero instead
        result = Actor::set_hit(object);
        if (result) {

            set_lock_direction(true);

            // Move backwards and upwards
            if (m_dir == Right) {
                set_speed(-get_attribute("move_speed"),
                          -get_attribute("jump_speed"));
            }
            else {
                set_speed(get_attribute("move_speed"),
                          -get_attribute("jump_speed"));
            }

            // Make player invisible for a certain time
            set_invisible(true);
        }
    }

    return result;
}
Beispiel #5
0
bool Monster::set_hit(Object *object)
{
    bool result = false;

    if (!m_invinsible && m_hit == HitNone) {
        result = Actor::set_hit(object);

        if (result) {

            set_lock_direction(true);

            // Move backwards and upwards
            if (get_reference() == Right) {
                set_speed(-get_attribute("move_speed"), 0);
            }
            else {
                set_speed(get_attribute("move_speed"), 0);
            }

            // Reduce hp
            // TODO: Get attackers attack power
            m_curr_hp--;
            if (m_curr_hp <= 0) {
                set_perish();
            }
        }
    }

    return result;
}
Beispiel #6
0
bool Monster::set_hit(Object *object, Status *status)
{
    bool result = false;

    if (!m_invinsible) {
        result = Actor::set_hit(object);
        if (result) {

            set_lock_direction(true);

            // Move backwards
            if (get_reference() == Right) {
                set_speed(-get_attribute("move_speed"), 0);
            }
            else {
                set_speed(get_attribute("move_speed"), 0);
            }

            // Reduce hp
            m_curr_hp -= status->get_ap();
            if (m_curr_hp <= 0) {
                set_perish();
            }
        }
    }

    return result;
}
/*
 * i2c_set_bus_speed - Set the i2c speed
 * @speed:	required i2c speed
 *
 * Set the i2c speed.
 */
void i2c_set_bus_speed(int speed)
{
	if (speed >= I2C_MAX_SPEED)
		set_speed(IC_SPEED_MODE_MAX);
	else if (speed >= I2C_FAST_SPEED)
		set_speed(IC_SPEED_MODE_FAST);
	else
		set_speed(IC_SPEED_MODE_STANDARD);
}
Beispiel #8
0
void TpFanDriver::ping_watchdog_and_depulse(const Level *level)
{
	if (depulse_ > std::chrono::milliseconds(0)) {
		FanDriver::set_speed("level disengaged");
		std::this_thread::sleep_for(depulse_);
		set_speed(level);
	}
	else if (last_watchdog_ping_ + watchdog_ + sleeptime >= std::chrono::system_clock::now())
		set_speed(level);
}
Beispiel #9
0
static int demo_play_click(int b, int d)
{
    if (d)
    {
        if (b == SDL_BUTTON_WHEELUP)   set_speed(+1);
        if (b == SDL_BUTTON_WHEELDOWN) set_speed(-1);
    }

    return 1;
}
Beispiel #10
0
static void demo_play_stick(int id, int a, float v, int bump)
{
    if (!bump)
        return;

    if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y0, a))
    {
        if (v < 0) set_speed(+1);
        if (v > 0) set_speed(-1);
    }
}
Beispiel #11
0
/*
 * card_uart_setup - specail setup for card reader UART
 *  @fd : card reader fd 
 *  @return : status 
 */
int card_uart_setup(int fd) 
{
#if 1
    struct termios option;

    memset(&option, 0, sizeof(option));
    option.c_cflag = B9600|CS8|CLOCAL|CREAD;
    option.c_iflag = IGNPAR;
    option.c_oflag = 0;
    option.c_lflag = 0;
    option.c_cc[VMIN] = 0;
    option.c_cc[VTIME] = 30;

    tcflush(fd, TCIFLUSH);

    if(tcsetattr(fd, TCSANOW, &option) < 0){
        return FAIL;
    }

#else
    int ret;
    set_speed(fd, 9600);
    ret = set_parity(fd, 8, 1, 'N');
    if (ret < 0)
        return FAIL;
#endif 

    return SUCCESS; 
}
Beispiel #12
0
void EightDirections::update(float dt)
{
    if (max_speed == 0)
        return;

    bool on = false;
    int dir = get_joystick_direction(1);
    if (dir == 8)
        dir = instance->direction;
    else {
        on = true;
        dir *= 4;
        instance->set_direction(dir, false);
    }
    double mul = instance->frame->timer_mul;

    double change;
    if (on)
        change = get_accelerator(acceleration);
    else
        change = -get_accelerator(deceleration);

    set_speed(int_max(0, int_min(speed + change * mul, max_speed)));

    if (speed == 0)
        return;

    double add_x, add_y;
    get_dir(instance->direction, add_x, add_y);
    double m = get_pixels(speed) * mul;
    move(add_x * m, add_y * m);
    last_move = m;
}
Beispiel #13
0
int xmos_dev_open()
{
	int fd_xmos = open_serial(SERIAL_DEV);
	if (fd_xmos == -1) {
		printf("Cannot open device\n");
        return ROKID_XMOS_ERROR_DEVICE_OPEN_FAILED;
	}
	int ret;
	ret = set_speed(fd_xmos, 115200);
	if (ret == -1) {
		printf("Set speed failed : %d\n", ret);
		return ROKID_XMOS_ERROR_INIT_FAILED;
	}
	ret = set_parity(fd_xmos, 8, 1, 0);
	if (ret == -1) {
		printf("Set parity failed : %d\n", ret);
		return ROKID_XMOS_ERROR_INIT_FAILED;
	}

	back_led_fd = open("/dev/dm163", O_RDWR | O_NONBLOCK);
	if (back_led_fd < 0) {
		perror("open dm163 error");
	}

	return fd_xmos;
}
Beispiel #14
0
int main(void)
{
	struct client *cl = (struct client *)malloc(sizeof(struct client));
	cl->state = initial;
	cl->inbuf = 0;
	cl->fd =  open("/dev/ttyUSB0", O_RDWR);
	if (cl->fd < 0) {
		fprintf(stderr, "Can't open the uart\n");
		exit(1);
	}

	set_speed(cl->fd, 115200);
	if (set_parity(cl->fd, 8, 1, 'N') == FALSE) {
		fprintf(stderr, "Set Parity Error\n");
		exit(0);
	}
	/* Infinite while loop -- server must be killed */
	while (1) {
		processclient(cl);
	}
	printf("-------------------\n");
	free(cl);
	close(cl->fd);
	return 1;
}
Beispiel #15
0
static int brf_set_serial_params(struct bts_action_serial *serial_action,
						int fd, int *speed, struct termios *ti)
{
	fprintf(stderr, "texas: changing baud rate to %u, flow control to %u\n",
				serial_action->baud, serial_action->flow_control );
	tcflush(fd, TCIOFLUSH);

	if (serial_action->flow_control)
		ti->c_cflag |= CRTSCTS;
	else
		ti->c_cflag &= ~CRTSCTS;

	if (tcsetattr(fd, TCSANOW, ti) < 0) {
		perror("Can't set port settings");
		return -1;
	}

	tcflush(fd, TCIOFLUSH);

	if (set_speed(fd, ti, serial_action->baud) < 0) {
		perror("Can't set baud rate");
		return -1;
	}

	if (speed)
		*speed = serial_action->baud;

	return 0;
}
int main(int argc, char **argv) {
    int fd;
    int nread;
    char *ptr = argv[2];
    char *dev = argv[1]; //maybe "/dev/ttyS0";

    if (argc < 3) {
        printf("pls usage %s /dev/ttyS[n] your_message.\n", argv[1]);
        exit(EXIT_FAILURE);
    }

    if ((fd = open(dev, O_RDWR)) == -1) {
        perror("open");
        exit(EXIT_FAILURE);
    }

    set_speed(fd, 19200);

    if (set_Parity(fd, 8, 1, 'N') == FALSE) {
        printf("Set Parity Error\n");
        exit(EXIT_FAILURE);
    }

    if (write(fd, ptr, strlen(ptr)) < 0) {
        perror("write");
        exit(EXIT_FAILURE);
    }

    printf("pls check the tty data\n");
    close(fd);
    exit(EXIT_SUCCESS);
}
Beispiel #17
0
void dt_circle_note_on::set_beats(int beat_num){
	seq->setup(beat_num);
	data.rev_speed = (float)360.0 / (float)seq->total_steps;
	change_rshape(ofRandom(-1000, 1000));
	
	set_speed(data.speed);
}
Beispiel #18
0
 /** 
 *@breif     main() 
 */  
 int main(int argc, char **argv)  
 {  
     int fd;  
     int nread;  
     char buff[512];  
     char *dev ="/dev/ttty0";  
     fd = OpenDev(dev);  
     if (fd>0)  
     set_speed(fd,19200);  
     else  
         {  
         printf("Can't Open Serial Port!\n");  
         exit(0);  
         }  
   if (set_Parity(fd,8,1,'N')== FALSE)  
   {  
     printf("Set Parity Error\n");  
     exit(1);  
   }  
   while(1)  
     {  
         while((nread = read(fd,buff,512))>0)  
         {  
             printf("\nLen %d\n",nread);  
             buff[nread+1]='\0';  
             printf("\n%s",buff);  
         }  
     }  
     //close(fd);  
     //exit(0);  
 }  
Beispiel #19
0
void create_planet()
{
  Uint32 x, y;
  Uint32 i;
  char *image = NULL;

  /* Get random coordinates. */
  x = ( rand() % screen_width() );
  y = -( rand() % 1000) + 100;

  /* Get random image name. */
  i = ( rand() % PLANET_IMAGE_NUM ) + 1; 
  switch( i ) {
  case 1: image = get_data( MOON_1_IMAGE, DATA_IMAGES ); break;
  default: image = NULL;
  }

  /* Make the planet sprite. */
  planet = new_sprite( x, y, 1, image, 0 );
  set_speed( planet, PLANET_SPEED ); 
  if( planet == NULL ) {
    fprintf( stderr, "Error creating new sprite: %s.\n",
              SDL_GetError() );
    exit(-1);
  }
}
Beispiel #20
0
void load_config(char * path)
{
	int i;
	char *p;

	//__android_log_print(ANDROID_LOG_DEBUG, "org.rin", "path in load_config: %s",path);

	jfile fd = jfopen(env_game_thread, path, JF_MODE_READ, NULL, 0);

	if(!fd)
	{
		init_config();
		return;
	}
	
	memset(&setting, 0, sizeof(setting));
	jfread(env_game_thread, fd, &setting, sizeof(setting));
	jfclose(env_game_thread, fd);

	tmpsetting = setting;
	memcpy(m_pal16[PAL_CUSTOM_LOCAL],setting.custom_palette, sizeof(short)*4*3);
	check_config();
	set_gb_type();
	set_speed(setting.speed);
	
}
Beispiel #21
0
/**
 * @brief Calculates the direction and the speed of the movement
 * depending on the target.
 */
void TargetMovement::recompute_movement() { 

  if (target_entity != NULL) {
    // the target may be a moving entity
    target_x = target_entity->get_x();
    target_y = target_entity->get_y();
  }

  if (get_x() != target_x || get_y() != target_y) {
    finished = false;

    double angle = Geometry::get_angle(get_x(), get_y(), target_x, target_y);

    int dx = target_x - get_x();
    int dy = target_y - get_y();

    sign_x = (dx >= 0) ? 1 : -1;
    sign_y = (dy >= 0) ? 1 : -1;

    if (std::fabs(angle - get_angle()) > 1E-6 || get_speed() < 1E-6) {
      set_speed(speed);
      set_angle(angle);
      set_max_distance((int) Geometry::get_distance(
            get_x(), get_y(), target_x, target_y));
    }
  }
}
int thread_fn(void *data)
{
  short cpu_temp,gpu_temp,max_temp;
  set_current_state(TASK_INTERRUPTIBLE);
  while(!kthread_should_stop())
  {
    SLEEP_MILLI_SEC(30000);
    cpu_temp = 0;
    gpu_temp = 0;
    cpu_temp = read_ec(0xA8);
    gpu_temp = read_ec(0xAF);
    max_temp = get_max(cpu_temp, gpu_temp);
    if (max_temp < 60) {
      fanSpeed = minFanSpeed;
    }

    if (max_temp > 60) {
      fanSpeed = minFanSpeed+20;
    }

    if (max_temp > 70) {
      fanSpeed = minFanSpeed+40;
    }

    if (max_temp > 80) {
      fanSpeed = maxFanSpeed;
    }
    set_speed(fanSpeed);
    printk(KERN_INFO "cpu temp: %d, gpu temp: %d, fan speed: %d", cpu_temp, gpu_temp, fanSpeed);
    schedule();
    set_current_state(TASK_INTERRUPTIBLE);
  }
  set_current_state(TASK_RUNNING);
  return 0;
}
Beispiel #23
0
/**
*@breif  main()
*/
int main(int argc, char *argv[])
{
 int fd;
 int nread;
 char buff[512];
 char *dev ="/dev/ttyACM0";
 char recchr[512];
 int device, c;

 sleep(1);
 fd = OpenDev(dev);

 if (fd>0){
      set_speed(fd,9600);
 }
 else{
  printf("Can't Open Serial Port!\n");
  exit(0);
 }

 if (set_Parity(fd,8,1,'N')== FALSE)
  {
     printf("Set Parity Error\n");
      exit(1);
   }
//   while(1)
//   {
        scanf("%s",recchr) ;
   write(fd, "c", 1);
   write(fd, "\"\n", 2);
	printf("发完!\n");
//   }
     close(fd);
     exit(0);
}
Beispiel #24
0
void Character::move(float tdelta)
{
    if (the_state == gsINPROGRESS)
        // Перемещаемся только во время игры
        Unit::move(tdelta);
    if (way.path.size() == 0)
        return;
    if ((speed.x > F_EPSILON && position.x >= way.neigpos.x)
        || (speed.x < -F_EPSILON && position.x <= way.neigpos.x)
        || (speed.y > F_EPSILON && position.y >= way.neigpos.y)
        || (speed.y < -F_EPSILON && position.y <= way.neigpos.y))
    {
        // Этап завершен
        position = way.neigpos;
        if (way.stage >= way.path.size() - 1)
        {
            // Цель достигнута
            way.path.clear();
            way.stage = 0;
            way.target = position;
        }
        else
        {
            // Следующий этап
            ++way.stage;
            way.neighbour += way.path[way.path.size() - way.stage - 1];
            way.neigpos = way.neighbour;
        }
        set_speed();
    }
}
Beispiel #25
0
void init_wave(struct wave * const wave, enum waveform waveform, midi_value_t speed, midi_value_t amplitude, midi_value_t offset)
{
    wave->settings.amplitude = amplitude;
    wave->settings.offset = offset;
    set_speed(wave, speed);
    set_waveform(wave, waveform);
}
Beispiel #26
0
void BallMovement::init()
{
    if (flags & MOVE_AT_START)
        set_speed(max_speed);
    else
        stop_speed = max_speed;
}
Beispiel #27
0
void callback_set_speed(const std_msgs::Float64::ConstPtr& msg) {
  if(command_mode!=globe_epas::globe_epas_cmd::SPEED_CONTROL) {
    ROS_INFO("Ignoring Globe EPAS command due to incorrect command mode");
    return;
  }
  set_speed(msg->data);
}  
Beispiel #28
0
static void release_engine(
	struct dce_i2c_hw *dce_i2c_hw)
{
	bool safe_to_reset;

	/* Restore original HW engine speed */

	set_speed(dce_i2c_hw, dce_i2c_hw->original_speed);

	/* Release I2C */
	REG_UPDATE(DC_I2C_ARBITRATION, DC_I2C_SW_DONE_USING_I2C_REG, 1);

	/* Reset HW engine */
	{
		uint32_t i2c_sw_status = 0;

		REG_GET(DC_I2C_SW_STATUS, DC_I2C_SW_STATUS, &i2c_sw_status);
		/* if used by SW, safe to reset */
		safe_to_reset = (i2c_sw_status == 1);
	}

	if (safe_to_reset)
		REG_UPDATE_2(DC_I2C_CONTROL,
			     DC_I2C_SOFT_RESET, 1,
			     DC_I2C_SW_STATUS_RESET, 1);
	else
		REG_UPDATE(DC_I2C_CONTROL, DC_I2C_SW_STATUS_RESET, 1);
	/* HW I2c engine - clock gating feature */
	if (!dce_i2c_hw->engine_keep_power_up_count)
		REG_UPDATE_N(SETUP, 1, FN(SETUP, DC_I2C_DDC1_ENABLE), 0);

}
Beispiel #29
0
/**
 * @brief Constructor.
 * @param speed speed of the movement in pixels per seconds
 * @param max_distance if the object goes further than this distance, it will come back
 */
RandomMovement::RandomMovement(int speed, int max_distance):
    RectilinearMovement(true),
    max_distance(max_distance) {

    set_speed(speed);
    set_next_direction();
}
static int acpuclk_cortex_set_rate(int cpu, unsigned long rate,
				 enum setrate_reason reason)
{
	struct clkctl_acpu_speed *tgt_s, *strt_s;
	int rc = 0;

	if (reason == SETRATE_CPUFREQ)
		mutex_lock(&acpuclk_init_data->lock);

	strt_s = acpuclk_init_data->current_speed;

	/* Return early if rate didn't change */
	if (rate == strt_s->khz)
		goto out;

	/* Find target frequency */
	for (tgt_s = acpuclk_init_data->freq_tbl; tgt_s->khz != 0; tgt_s++)
		if (tgt_s->khz == rate)
			break;
	if (tgt_s->khz == 0) {
		rc = -EINVAL;
		goto out;
	}

	/* Increase VDD levels if needed */
	if ((reason == SETRATE_CPUFREQ || reason == SETRATE_INIT)
			&& (tgt_s->khz > strt_s->khz)) {
		rc = increase_vdd(tgt_s->vdd_cpu, tgt_s->vdd_mem);
		if (rc)
			goto out;
	}

	pr_debug("Switching from CPU rate %u KHz -> %u KHz\n",
		strt_s->khz, tgt_s->khz);

	/* Switch CPU speed. */
	rc = set_speed(tgt_s);
	if (rc)
		goto out;

	acpuclk_init_data->current_speed = tgt_s;
	pr_debug("CPU speed change complete\n");

	/* Nothing else to do for SWFI or power-collapse. */
	if (reason == SETRATE_SWFI || reason == SETRATE_PC)
		goto out;

	/* Update bus bandwith request */
	set_bus_bw(tgt_s->bw_level);

	/* Drop VDD levels if we can. */
	if (tgt_s->khz < strt_s->khz)
		decrease_vdd(tgt_s->vdd_cpu, tgt_s->vdd_mem);

out:
	if (reason == SETRATE_CPUFREQ)
		mutex_unlock(&acpuclk_init_data->lock);
	return rc;
}