void ask (char foo[]) { printf("%s\n", foo); while (!start_button()) { } while (start_button()) { } } void checklist () { ask("Is the rear gate centered?"); } void wait_start () { while (!start_button()) { } while (start_button()) { } } void main () { /* * Don't false start. :) */ ir_transmit_off(); block_spot = UNKNOWN; /* * Calibration and setup */ setup_actuators(); setup_ramp(); setup_sensors(); raise_ramp(); sleep(0.2); lower_ramp(); calibrate_light_sensors(); calibrate_ball_sensor(); /* * Checklist... :) */ checklist(); /* * Start! */ start_machine(START_SENSOR); ir_transmit_on(); /* * Setup again... */ setup_actuators(); setup_ramp(); fd(THUMPER_MOTOR); start_process(ramp_watcher()); find_orientation(); orient(); /* * Get the first ball, by pushing it into the trough. * We get an extra accounted here, because we can just push it in. Tee hee. */ drive_into_wall(0, 5.0); shimmy_onto_line(0); if (team == WHITE) { white_accounted++; } else { black_accounted++; } /* * Drive forward to the outside of the table and get the second ball. * Also, sense where the block is! */ drive_ticks(1, 150); if (team == WHITE) { if (get_analog(LEFT_DISTANCE, 3) > 65) { block_spot = SOUTH_EAST; } } else { if (get_analog(RIGHT_DISTANCE, 3) > 65) { block_spot = SOUTH_EAST; } } drive_ticks(1, 150); if (team == WHITE) { if (get_analog(LEFT_DISTANCE, 3) > 65) { block_spot = SOUTH_WEST; } } else { if (get_analog(RIGHT_DISTANCE, 3) > 65) { block_spot = SOUTH_WEST; } } drive_into_wall(1, 5.0); /* * Reverse to the inside. */ if (team == WHITE) { start_process(open_gate_after(WHITE, 1.8)); } else { start_process(open_gate_after(BLACK, 1.8)); } drive_into_wall(0, 5.0); /* * Dump it. */ sleep(2.0); if (team == WHITE) { close_white_gate(); } else { close_black_gate(); } shimmy_onto_line(0); printf("Block is: %d\n", block_spot); if (block_spot == SOUTH_EAST) { drive_ticks(1, 500); if (team == WHITE) { backup_left(90); } else { backup_right(90); } drive_into_wall(0, 5.0); drive_ticks(1, 200); while (!GRABBING_BALL) { } while (GRABBING_BALL) { } inch_to_ball(); while (GRABBING_BALL) { } drive_into_line(1, 5.0); drive_ticks(0, 70); if (team == WHITE) { backup_right(90); } else { backup_left(90); } if (team == WHITE) { start_process(open_gate_after(WHITE, 0.5)); } else { start_process(open_gate_after(BLACK, 0.5)); } drive_into_wall(0, 5.0); sleep(2.0); if (team == WHITE) { close_white_gate(); } else { close_black_gate(); } } else if (block_spot == SOUTH_WEST) { drive_ticks(1, 290); if (team == WHITE) { backup_left(90); } else { backup_right(90); } drive_into_wall(0, 5.0); drive_ticks(1, 200); while (!GRABBING_BALL) { } while (GRABBING_BALL) { } inch_to_ball(); while (GRABBING_BALL) { } drive_into_line(1, 5.0); drive_ticks(0, 70); if (team == WHITE) { backup_right(90); } else { backup_left(90); } if (team == WHITE) { start_process(open_gate_after(WHITE, 0.6)); } else { start_process(open_gate_after(BLACK, 0.6)); } drive_into_wall(0, 5.0); sleep(2.0); if (team == WHITE) { close_white_gate(); } else { close_black_gate(); } drive_into_wall(1, 5.0); if (team == WHITE) { start_process(open_gate_after(WHITE, 1.6)); } else { start_process(open_gate_after(BLACK, 1.6)); } drive_into_wall(0, 5.0); sleep(2.0); if (team == WHITE) { close_white_gate(); } else { close_black_gate(); } } else { drive_ticks(1, 300); if (team == WHITE) { turn_180(0); } else { turn_180(1); } drive_into_wall(0, 5.0); if (team == WHITE) { turn_right(90); } else { turn_left(90); } drive_into_wall(0, 5.0); shimmy_onto_line(0); drive_into_line(1, 5.0); if (team == WHITE) { start_process(open_gate_after(BLACK, 1.8)); } else { start_process(open_gate_after(WHITE, 1.8)); } drive_into_wall(0, 5.0); } } void balls () { while (1) { printf("White: %d (%d) Black: %d (%d)\n", white_accounted, white_balls, black_accounted, black_balls); sleep(0.1); } }