icfp11/src/radar_main.c

69 lines
1.5 KiB
C
Raw Normal View History

2008-07-13 13:19:43 +00:00
#include "control.h"
2008-07-13 20:05:06 +00:00
#include "lookahead.h"
2008-07-13 13:19:43 +00:00
#include <stdio.h>
#define LATENCY 20
void trial_loop(trial *t) {
do {
if (-1 == trial_wait_for_start(t)) return;
if (t->finished) break;
2008-07-13 16:42:05 +00:00
if (t->runcnt == 0) {
goradar(t);
vehicle_accel(t);
2008-07-13 16:56:28 +00:00
switch (t->vehicle.turn) {
2008-07-13 16:42:05 +00:00
case TURN_LEFT:
case TURN_STRAIGHT:
vehicle_hard_left(t); break;
case TURN_RIGHT:
vehicle_hard_right(t); break;
default: break;
}
2008-07-13 17:42:36 +00:00
while (t->telemetry.length < 5) {
2008-07-13 16:42:05 +00:00
if (-1 == trial_wait_for_input(t)) return;
}
2008-07-13 17:42:36 +00:00
fit_parameter( (telemetry*) g_queue_peek_nth(&t->telemetry,2),
2008-07-13 16:56:28 +00:00
(telemetry*) g_queue_peek_nth(&t->telemetry,3),
2008-07-13 17:42:36 +00:00
(telemetry*) g_queue_peek_nth(&t->telemetry,4),
2008-07-13 16:56:28 +00:00
&t->map);
2008-07-13 17:42:36 +00:00
fprintf(stderr,"Fitparameter: a: %f aw: %f k: %f\n",t->map.a,t->map.aw,t->map.k);
2008-07-13 16:56:28 +00:00
2008-07-13 16:42:05 +00:00
}
2008-07-13 13:19:43 +00:00
while (t->alive) {
2008-07-13 19:51:00 +00:00
timestamp step=getcurts(t) + LATENCY - t->sim.tm.ts;
2008-07-13 20:13:40 +00:00
if (step > 0) {
t->sim.tm.vehicle.w = turn2w(t, t->sim.tm.vehicle.turn);
dgl(t,&t->sim.tm.vehicle,&t->sim.tm.vehicle,step,step);
t->sim.tm.ts += step;
t->sim.steps++;
}
2008-07-13 17:42:36 +00:00
// simulate(t, getcurts(t) + LATENCY);
2008-07-13 13:19:43 +00:00
goradar(t);
if (-1 == trial_check_input(t)) return;
// if (-1 == trial_wait_for_input(t)) return;
}
trial_reset_run(t);
} while (!t->finished);
}
int main(int argc, char **argv) {
trial *t;
if (argc <= 2) {
fprintf(stderr, "Syntax: %s hostname port\n", argv[0]);
return 1;
}
if (NULL == (t = trial_new(argv[1], argv[2]))) {
return 2;
}
trial_loop(t);
trial_free(t);
return 0;
}