Beispiel #1
0
void portb_isr(void){
  if(SDA_CTRL & ISF){
    SDA_CTRL |= ISF;
    if (!(I2C0_S & I2C_S_BUSY)){
      SDA_CTRL = (~IRQC_MASK & SDA_CTRL) | IRQC_NONE;
      // We're done right here
    } else {
      if (++irqcount >= 2) {
	SDA_CTRL = (~IRQC_MASK & SDA_CTRL) | IRQC_NONE;
      }
    }
  }
  

  if(MIN_LIMIT_CTRL & ISF){
    if(parameters.homing &  ENABLE_MIN){
      stop_motion();
      st.state = STATE_ERROR;
      parameters.error_low = IMC_ERR_MECHANICAL;
    }
    MIN_LIMIT_CTRL |= ISF;
  }
  if(MAX_LIMIT_CTRL & ISF){
    if(parameters.homing &  ENABLE_MAX){
      stop_motion();
      st.state = STATE_ERROR;
      parameters.error_low = IMC_ERR_MECHANICAL;
    }
    MAX_LIMIT_CTRL |= ISF;
  }
  if(SYNC_CTRL & ISF){
    switch(st.state){
    case STATE_SYNC:
      {
	uint32_t timer_value;
	timer_value = SYNC_TIMEOUT - PIT_CVAL2; // Figure out how far we've gotten
	PIT_TCTRL2 &= ~TEN; // Stop counting down
	parameters.sync_error = timer_value;
      }
      execute_move();
      break;
    case STATE_IDLE:
      if(queue_length() > 0){
	execute_move();
	break;
      }
      // Otherwise fall through and set an error condition
    case STATE_EXECUTE:
      // This should never happen - if we're in execute, we should hold the line low and not enable this interrupt...
      st.state = STATE_ERROR;
      parameters.error_low = IMC_ERR_TIMEOUT; // Maybe not best error code, but...
    default:
      ; // Just handle this...
    }
    SYNC_CTRL = (SYNC_CTRL & ~IRQC_MASK) | IRQC_NONE;
    SYNC_CTRL |= ISF;
  }
}
Beispiel #2
0
void execute_pinch(int fd, uint32_t device_flags, int touch1_x1,
                   int touch1_y1, int touch1_x2, int touch1_y2, int touch2_x1,
                   int touch2_y1, int touch2_x2, int touch2_y2, int num_steps,
                   int duration_msec)
{
  int delta1[] = {(touch1_x2-touch1_x1)/num_steps, (touch1_y2-touch1_y1)/num_steps};
  int delta2[] = {(touch2_x2-touch2_x1)/num_steps, (touch2_y2-touch2_y1)/num_steps};
  int sleeptime = duration_msec / num_steps;
  int i;

  print_action(ACTION_START, "pinch",
               "\"touch1_x1\": %d, \"touch1_y1\": %d, \"touch1_x2\": %d, "
               "\"touch1_y2\": %d, \"touch2_x1\": %d, \"touch2_y1\": %d, "
               "\"touch2_x2\": %d, \"touch2_y2\": %d, \"num_steps\": %d, "
               "\"duration_msec\": %d",
               touch1_x1, touch1_y1, touch1_x2, touch1_y2,
               touch2_x1, touch2_y1, touch2_x2, touch2_y2,
               num_steps, duration_msec);

  // press
  change_mt_slot(fd, device_flags, 0);
  add_mt_tracking_id(fd, device_flags, global_tracking_id++);
  execute_press(fd, device_flags, touch1_x1, touch1_y1);

  change_mt_slot(fd, device_flags, 1);
  add_mt_tracking_id(fd, device_flags, global_tracking_id++);
  execute_press(fd, device_flags, touch2_x1, touch2_y1);

  // drag
  for (i=0; i<num_steps; i++) {
    execute_sleep(sleeptime);

    change_mt_slot(fd, device_flags, 0);
    execute_move(fd, device_flags, touch1_x1+delta1[0]*i, touch1_y1+delta1[1]*i);

    change_mt_slot(fd, device_flags, 1);
    execute_move(fd, device_flags, touch2_x1+delta2[0]*i, touch2_y1+delta2[1]*i);

    //write_event(fd, EV_SYN, SYN_REPORT, 0);
  }

  // release
  change_mt_slot(fd, device_flags, 0);
  execute_release(fd, device_flags);

  change_mt_slot(fd, device_flags, 1);
  execute_release(fd, device_flags);

  remove_mt_tracking_id(fd, device_flags, 0);
  remove_mt_tracking_id(fd, device_flags, 1);

  // wait
  execute_sleep(100);

  print_action(ACTION_END, "pinch", NULL);
}
Beispiel #3
0
int ask_for_move(board_t board) {
    int move;
    char validstr[5];
    char *validpos = validstr;

    print_board(board);

    for(move=0; move<4; move++) {
        if(execute_move(move, board) != board)
            *validpos++ = "UDLR"[move];
    }
    *validpos = 0;
    if(validpos == validstr)
        return -1;

    while(1) {
        char movestr[64];
        const char *allmoves = "UDLR";

        printf("Move [%s]? ", validstr);

        if(!fgets(movestr, sizeof(movestr)-1, stdin))
            return -1;

        if(!strchr(validstr, toupper(movestr[0]))) {
            printf("Invalid move.\n");
            continue;
        }

        return strchr(allmoves, toupper(movestr[0])) - allmoves;
    }
}
Beispiel #4
0
void execute_drag(int fd, uint32_t device_flags, int start_x,
                  int start_y, int end_x, int end_y, int num_steps,
                  int duration_msec)
{
  int delta[] = {(end_x-start_x)/num_steps, (end_y-start_y)/num_steps};
  int sleeptime = duration_msec / num_steps;
  int i;

  print_action(ACTION_START, "drag", "\"start_x\": %d, \"start_y\": %d, "
               "\"end_x\": %d, \"end_y\": %d, \"num_steps\": %d, "
               "\"duration_msec\": %d", start_x, start_y, end_x, end_y,
               num_steps, duration_msec);

  // press
  execute_press(fd, device_flags, start_x, start_y);

  // drag
  for (i=0; i<num_steps; i++) {
    execute_sleep(sleeptime);
    execute_move(fd, device_flags, start_x+delta[0]*i, start_y+delta[1]*i);
  }

  // release
  execute_release(fd, device_flags);

  // wait
  execute_sleep(100);

  print_action(ACTION_END, "drag", NULL);
}
Beispiel #5
0
void execute_pinch(int fd, int version, unsigned int device_flags, int touch1_x1,
                   int touch1_y1, int touch1_x2, int touch1_y2, int touch2_x1,
                   int touch2_y1, int touch2_x2, int touch2_y2, int num_steps,
                   int duration_msec)
{
    int delta1[] = {(touch1_x2-touch1_x1)/num_steps, (touch1_y2-touch1_y1)/num_steps};
    int delta2[] = {(touch2_x2-touch2_x1)/num_steps, (touch2_y2-touch2_y1)/num_steps};
    int sleeptime = duration_msec / num_steps;
    int i;

    // press
    change_mt_slot(fd, version, device_flags, 0);
    add_mt_tracking_id(fd, version, device_flags, global_tracking_id++);
    execute_press(fd, version, device_flags, touch1_x1, touch1_y1);

    change_mt_slot(fd, version, device_flags, 1);
    add_mt_tracking_id(fd, version, device_flags, global_tracking_id++);
    execute_press(fd, version, device_flags, touch2_x1, touch2_y1);

    // drag
    for (i=0; i<num_steps; i++) {
      execute_sleep(sleeptime);

      change_mt_slot(fd, version, device_flags, 0);
      execute_move(fd, version, device_flags, touch1_x1+delta1[0]*i, touch1_y1+delta1[1]*i);

      change_mt_slot(fd, version, device_flags, 1);
      execute_move(fd, version, device_flags, touch2_x1+delta2[0]*i, touch2_y1+delta2[1]*i);

      //write_event(fd, EV_SYN, SYN_REPORT, 0);
    }

    // release
    change_mt_slot(fd, version, device_flags, 0);
    execute_release(fd, version, device_flags);

    change_mt_slot(fd, version, device_flags, 1);
    execute_release(fd, version, device_flags);

    remove_mt_tracking_id(fd, version, device_flags, 0);
    remove_mt_tracking_id(fd, version, device_flags, 1);

    // wait
    execute_sleep(100);

}
Beispiel #6
0
int main(void)
{
	struct chessboard *c = get_new_board();
	int tmp, sx, sy, dx, dy;

	while (1) {
		print_chessboard(c);
		/* Calcluate white's suggested move */
		tmp = calculate_move(c, 0, MOVE_DEPTH);
		sx = tmp & 0xff;
		sy = (tmp & 0xff00) >> 8;
		dx = (tmp & 0xff0000) >> 16;
		dy = (tmp & 0xff000000) >> 24;
		printf("Computer suggests (%d,%d) -> (%d,%d)\n", sx, sy, dx, dy);

no_clear:
		printf("Enter move: ");
		tmp = scanf("%d %d %d %d", &sx, &sy, &dx, &dy);
		if (tmp != 4)
			goto no_clear;

		if (sx == -1)
			return 0;

		tmp = execute_move(c, sx, sy, dx, dy);
		if (tmp) {
			printf("Error: %s\n", get_error_string(tmp));
			goto no_clear;
		} else {
			printf("Move succeeded!\n");
		}

		/* Calcluate black's move */
		tmp = calculate_move(c, 1, MOVE_DEPTH);
		sx = tmp & 0xff;
		sy = (tmp & 0xff00) >> 8;
		dx = (tmp & 0xff0000) >> 16;
		dy = (tmp & 0xff000000) >> 24;
		printf("Black moves (%d,%d) -> (%d,%d)\n", sx, sy, dx, dy);
		tmp = execute_move(c, sx, sy, dx, dy);
		if (tmp)
			fatal("Computer tried to make an illegal move: %s\n", get_error_string(tmp));
	}

	return 0;
}
Beispiel #7
0
Datei: move.c Projekt: cxd4/chess
void execute_legal_move_by_ID(move_storage * list, size_t index)
{
    assert(list != NULL);
    execute_move(
        list[index].origin.file, list[index].origin.rank,
        list[index].target.file, list[index].target.rank
    );
    return;
}
Beispiel #8
0
static float _score_toplevel_move(eval_state &state, board_t board, int move) {
    //int maxrank = get_max_rank(board);
    board_t newboard = execute_move(move, board);

    if(board == newboard)
        return 0;

    state.cprob_thresh = CPROB_THRESH_BASE;

    return score_tilechoose_node(state, newboard, 1.0f) + 1e-6;
}
Beispiel #9
0
void play_game(get_move_func_t get_move) {
    board_t board = initial_board();
    int moveno = 0;
    int scorepenalty = 0; // "penalty" for obtaining free 4 tiles

    while(1) {
        int move;
        board_t newboard;

        for(move = 0; move < 4; move++) {
            if(execute_move(move, board) != board)
                break;
        }
        if(move == 4)
            break; // no legal moves

        printf("\nMove #%d, current score=%.0f\n", ++moveno, score_board(board) - scorepenalty);

        move = get_move(board);
        if(move < 0)
            break;

        newboard = execute_move(move, board);
        if(newboard == board) {
            printf("Illegal move!\n");
            moveno--;
            continue;
        }

        int tile = draw_tile();
        if(tile == 2)
            scorepenalty += 4;
        board = insert_tile_rand(newboard, tile);
    }

    print_board(board);
    printf("\nGame over. Your score is %.0f. The highest rank you achieved was %d.\n", score_board(board) - scorepenalty, get_max_rank(board));
}
Beispiel #10
0
void execute_drag(int fd, uint32_t device_flags, int start_x,
                  int start_y, int end_x, int end_y, int num_steps,
                  int duration_msec)
{
  int delta[] = {(end_x-start_x)/num_steps, (end_y-start_y)/num_steps};
  double desired_interval_msec, avg_event_dispatch_time_msec;
  struct timespec start_time, current_time, time_before_last_move;
  int i;

  clock_gettime(CLOCK_MONOTONIC, &start_time);
  double start_nsecs = (double) (start_time.tv_sec * (1000*1000)) + start_time.tv_nsec;

  print_action(ACTION_START, "drag", "\"start_x\": %d, \"start_y\": %d, "
               "\"end_x\": %d, \"end_y\": %d, \"num_steps\": %d, "
               "\"duration_msec\": %d", start_x, start_y, end_x, end_y,
               num_steps, duration_msec);

  // press
  clock_gettime(CLOCK_MONOTONIC, &time_before_last_move);
  execute_press(fd, device_flags, start_x, start_y);

  // drag
  desired_interval_msec = duration_msec / num_steps;
  for (i=0; i<num_steps; i++) {
    clock_gettime(CLOCK_MONOTONIC, &current_time);
    avg_event_dispatch_time_msec = ((avg_event_dispatch_time_msec * i) +
                                    timediff_msec(&time_before_last_move,
                                                  &current_time)) / i;
    if (desired_interval_msec > 0 &&
        avg_event_dispatch_time_msec < desired_interval_msec) {
      execute_sleep(desired_interval_msec - avg_event_dispatch_time_msec);
    }

    memcpy(&time_before_last_move, &current_time, sizeof(struct timespec));
    execute_move(fd, device_flags, start_x+delta[0]*i, start_y+delta[1]*i);
  }

  // release
  execute_release(fd, device_flags);

  // wait
  execute_sleep(100);

  print_action(ACTION_END, "drag", NULL);
}
Beispiel #11
0
void execute_drag(int fd, int version, unsigned int device_flags, int start_x,
                  int start_y, int end_x, int end_y, int num_steps,
                  int duration_msec)
{
    int delta[] = {(end_x-start_x)/num_steps, (end_y-start_y)/num_steps};
    int sleeptime = duration_msec / num_steps;
    int i;

    // press
    execute_press(fd, version, device_flags, start_x, start_y);

    // drag
    for (i=0; i<num_steps; i++) {
      execute_sleep(sleeptime);
      execute_move(fd, version, device_flags, start_x+delta[0]*i, start_y+delta[1]*i);
    }

    // release
    execute_release(fd, version, device_flags);

    // wait
    execute_sleep(100);
}
Beispiel #12
0
static float score_move_node(eval_state &state, board_t board, float cprob) {
    if(cprob < state.cprob_thresh || state.curdepth >= SEARCH_DEPTH_LIMIT) {
        if(state.curdepth > state.maxdepth)
            state.maxdepth = state.curdepth;
        return score_heur_board(board);
    }

    if(state.curdepth < CACHE_DEPTH_LIMIT) {
        const eval_state::trans_table_t::iterator &i = state.trans_table.find(board);
        if(i != state.trans_table.end()) {
            state.cachehits++;
            return i->second;
        }
    }

    int move;
    float best = 0;

    state.curdepth++;
    for(move=0; move<4; move++) {
        board_t newboard = execute_move(move, board);
        state.moves_evaled++;
        if(board == newboard)
            continue;

        float res = score_tilechoose_node(state, newboard, cprob);
        if(res > best)
            best = res;
    }
    state.curdepth--;

    if(state.curdepth < CACHE_DEPTH_LIMIT) {
        state.trans_table[board] = best;
    }

    return best;
}
Beispiel #13
0
void portb_isr(void){
  if(SDA_CTRL & ISF){
    SDA_CTRL |= ISF;
    if (!(I2C0_S & I2C_S_BUSY)){
      SDA_CTRL = (~IRQC_MASK & SDA_CTRL) | IRQC_NONE;
      // We're done right here
    } else {
      if (++irqcount >= 2) {
	SDA_CTRL = (~IRQC_MASK & SDA_CTRL) | IRQC_NONE;
      }
    }
  }
  
  //||\\!! TODO: This safety feature disabled for now because I have a gentler handling in stepper_hook.
  if(MIN_LIMIT_CTRL & ISF){
    if(parameters.homing &  ENABLE_MIN){
      //stop_motion();
      //st.state = STATE_ERROR;
      //parameters.error_low = IMC_ERR_MECHANICAL;
    }
    MIN_LIMIT_CTRL |= ISF;
  }
  if(MAX_LIMIT_CTRL & ISF){
    if(parameters.homing &  ENABLE_MAX){
      //stop_motion();
      //st.state = STATE_ERROR;
      //parameters.error_low = IMC_ERR_MECHANICAL;
    }
    MAX_LIMIT_CTRL |= ISF;
  }
  if(SYNC_CTRL & ISF){
    //||\\!! temp
    //hid_printf("%u-%i sync pin isr. state = %i\n", get_systick_tenus(), (CONTROL_DDR & SYNC_BIT) ? -1 : CONTROL_PORT(DIR) & SYNC_BIT, st.state);
    switch(st.state){
    case STATE_SYNC:
      {
	uint32_t timer_value;
	timer_value = SYNC_TIMEOUT - PIT_CVAL2; // Figure out how far we've gotten
	PIT_TCTRL2 &= ~TEN; // Stop counting down
	parameters.sync_error = timer_value;
  
    //||\\!! temp
    //hid_printf("%u-%i  sync_error = %i\n", get_systick_tenus(), (CONTROL_DDR & SYNC_BIT) ? -1 : CONTROL_PORT(DIR) & SYNC_BIT, timer_value);
      }
      execute_move();
      break;
    case STATE_IDLE:
      if(queue_length() > 0){
	execute_move();
	break;
      }
      break;  //||\\!! FIXME - this break added to keep from erroring while debugging the control flow.
      // Otherwise fall through and set an error condition
    case STATE_EXECUTE:
      // This should never happen - if we're in execute, we should hold the line low and not enable this interrupt...
      st.state = STATE_ERROR;
      parameters.error_low = IMC_ERR_TIMEOUT; // Maybe not best error code, but...
    default:
      ; // Just handle this...
    }
    SYNC_CTRL = (SYNC_CTRL & ~IRQC_MASK) | IRQC_NONE;
    SYNC_CTRL |= ISF;
  }
}
Beispiel #14
0
//--------- Begin of function Unit::pre_process ---------//
//
void Unit::pre_process()
{
	//--- if the unit's hit point drops to 0, it dies now ---//

	if( hit_points <= 0 )
	{
		set_die();
		return;
	}

	//------- process fog of war ----------//

	visit_area();

	//------ process unit_mode -------//
#ifdef DEBUG
	long startTime;
#endif

	switch( unit_mode )
	{
		case UNIT_MODE_TOWN_DEFENDER:
#ifdef DEBUG
			startTime = m.get_time();
#endif
			process_mode_town_defender();
#ifdef DEBUG
			unit_process_town_defender_profile_time += m.get_time() - startTime;
#endif
			break;

		case UNIT_MODE_CAMP_DEFENDER:
#ifdef DEBUG
			startTime = m.get_time();
#endif
			process_mode_camp_defender();
#ifdef DEBUG
			unit_process_camp_defender_profile_time += m.get_time() - startTime;
#endif
			break;

		case UNIT_MODE_REBEL:
#ifdef DEBUG
			startTime = m.get_time();
#endif
			process_mode_rebel();
#ifdef DEBUG
			unit_process_rebel_profile_time += m.get_time() - startTime;
#endif
			break;
	}

	//--- if the current order has been reset and there is a pushed order, pop the order ---//

	if( cur_order.mode==0 && has_pushed_order() )
   	pop_order();

	//-------- process unit order now -------//

	switch( cur_order.mode )
	{
		case UNIT_MOVE:		// nothing to do with move mode, as UnitB already takes care of it
#ifdef DEBUG
			startTime = m.get_time();
#endif
			execute_move();
#ifdef DEBUG
			unit_execute_move_profile_time += m.get_time() - startTime;
#endif
			break;

		case UNIT_ATTACK:
#ifdef DEBUG
			startTime = m.get_time();
#endif
			execute_attack();
#ifdef DEBUG
			unit_execute_attack_profile_time += m.get_time() - startTime;
#endif
			break;

		case UNIT_BUILD_FIRM:
#ifdef DEBUG
			startTime = m.get_time();
#endif
			execute_build_firm();
#ifdef DEBUG
			unit_execute_build_firm_profile_time += m.get_time() - startTime;
#endif
			break;

		case UNIT_SETTLE_TOWN:
#ifdef DEBUG
			startTime = m.get_time();
#endif
			execute_settle_town();
#ifdef DEBUG
			unit_execute_settle_town_profile_time += m.get_time() - startTime;
#endif
			break;

		case UNIT_ASSIGN:
#ifdef DEBUG
			startTime = m.get_time();
#endif
			execute_assign();
#ifdef DEBUG
			unit_execute_assign_profile_time += m.get_time() - startTime;
#endif
			break;

		case UNIT_GO_CAST_POWER:
#ifdef DEBUG
			startTime = m.get_time();
#endif
			execute_go_cast_power();
#ifdef DEBUG
			unit_cast_power_profile_time += m.get_time() - startTime;
#endif
			break;

		case UNIT_TRANSFORM_FORTRESS:
#ifdef DEBUG
			startTime = m.get_time();
#endif
			execute_transform_fortress();
#ifdef DEBUG
			unit_transform_fortress_profile_time += m.get_time() - startTime;
#endif
			break;
	}
}
Beispiel #15
0
void loop() {

  recieve_commands();
  
  if (!docking && !auto_cover) {
    execute_move();
    interaction();
  }
  
  if (move_time == 0) {

    if (stream)   // @t
      stream_data();

    if (exp_auto) // @a
      feb_experiment_scanning();//katie_auto();

    if (auto_on )   // @u
      katie_auto();

    // if (auto_cover){ /// send state message at a regular interval during script
    //   int diff = millis() - picture_timer;
    //   if (diff > 3000) {
    //     send_state("picture timer");
    //     picture_timer = millis();
    //   }
    // }

    if (exp_stream )  // @e
      // arduino_hub_stream(); // experiment_dec_2013

    if (debug_stream )   // @g
      stream_debug_sensors();
  }

  BUTTONS_STATE = COIFetchSingleSensor(BUTTONS);
  if (PLAY_BUTTON(BUTTONS_STATE) == HIGH) {
      delay(200);
      COIChangeMode(CMD_MODE_PASSIVE);
      play_toggle = true;
      send_response("SAFE MODE ON", 1);
    }

  if ((CHARGING_SOURCE_STATE == 1  || CHARGING_SOURCE_STATE == 2) && play_toggle == true ) {
    charge_toggle = true;
    play_toggle = false;
    send_response("CHARGING SOURCE DETECTED", 1);
  }

  if ((CHARGING_SOURCE_STATE == 0) && (OI_MODE_STATE == OI_PASSIVE) && (charge_toggle == true) && (play_toggle == false)){
    COIChangeMode(CMD_MODE_FULL);
    charge_toggle = false;
    send_response("FULL MODE ON", 1);
  }

  update_battery_sensors();
  charger();

  if (!digitalRead(INPUT_20) && !auto_cover ) { // check to see if not in script so command does not interfere
    //update_create_fast_sensors(); // so that collision detection works
    BUMPS_WHEEL_DROPS_STATE         = COIFetchSingleSensor(BUMPS_WHEELS);
    //charger();  // detects charger (once this works move make nest it deeper in framework)
  }

   if ((BUMPS_WHEEL_DROPS_STATE > 0 && BUMPS_WHEEL_DROPS_STATE < 4) && bp == false) {
          bp = true;
          send_state("collision detected");
        }
   if ((BUMPS_WHEEL_DROPS_STATE == 0) && bp == true) {
          bp = false;
          send_state("bumper released");
        }

  //heading = update_header(heading, COIFetchSingleSensor(ANGLE_SINCE_LAST); // Mostly for testing, for now
  delay(20); // serial gets overrun if no delay

}
Beispiel #16
0
//move is in the format [x, y] as a 2 dim array
//returns the area owned by us
int do_move(int *move)
{
    return execute_move(move, 1, 1);
}
Beispiel #17
0
//move is in the format [x, y] as a 2 dim array
int undo_move(int *move)
{
    return execute_move(move, 0, 1);
}
Beispiel #18
0
int undo_move_coarse(int *move, int algo)
{
    return execute_move(move, 0, algo);
}