From 2cd7a175aa34c0950514a0603f176796d217a83a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BChler?= Date: Sun, 13 Jul 2008 19:28:32 +0200 Subject: [PATCH] Call simulation to sync before telemetry update --- src/control_parser.c | 66 ++++++++++++++++++++++--------------------- src/control_parser.rl | 2 ++ 2 files changed, 36 insertions(+), 32 deletions(-) diff --git a/src/control_parser.c b/src/control_parser.c index f6c179d..2be9621 100644 --- a/src/control_parser.c +++ b/src/control_parser.c @@ -27,7 +27,7 @@ static timestamp extract_ts(context *ctx, char *fpc) { return atoi(ctx->tmp->str); } -#line 144 "control_parser.rl" +#line 146 "control_parser.rl" @@ -243,7 +243,7 @@ static const int control_parser_error = 0; static const int control_parser_en_main = 1; -#line 147 "control_parser.rl" +#line 149 "control_parser.rl" static int control_parser_has_error(context *ctx) { return ctx->cs == control_parser_error; @@ -260,7 +260,7 @@ void control_parser_new(trial *t) { { ( ctx->cs) = control_parser_start; } -#line 159 "control_parser.rl" +#line 161 "control_parser.rl" ctx->buffer = g_string_sized_new(0); ctx->tmp = g_string_sized_new(0); ctx->mark = -1; @@ -274,7 +274,7 @@ void control_parser_reset(trial *t) { { ( ctx->cs) = control_parser_start; } -#line 168 "control_parser.rl" +#line 170 "control_parser.rl" g_string_truncate(ctx->tmp, 0); ctx->mark = -1; /* fprintf(stderr, "Parser reset\n"); */ @@ -397,6 +397,8 @@ _match: gettimeofday(&t->started, NULL); /* fprintf(stderr, "New run\n"); */ } else { + dgl(t, &t->sim.tm.vehicle, &t->sim.tm.vehicle, ctx->tm->ts - t->sim.tm.ts); + ctx->tm->vehicle.w = t->sim.tm.vehicle.w; /* fprintf(stderr, "time difference [ms]: %i\n", getcurts(t) - ctx->tm->ts); */ fprintf(stderr, "Miss predict: dx=%f, dy=%f, ddir=%f, steps=%u\n", t->sim.tm.vehicle.x - t->vehicle.x, @@ -417,7 +419,7 @@ _match: } break; case 4: -#line 67 "control_parser.rl" +#line 69 "control_parser.rl" { ctx->tm->ts = ctx->ts; ctx->tm->vehicle.x = ctx->x; @@ -432,95 +434,95 @@ _match: } break; case 5: -#line 84 "control_parser.rl" +#line 86 "control_parser.rl" { t->map.dx = extract_double(ctx, p); } break; case 6: -#line 85 "control_parser.rl" +#line 87 "control_parser.rl" { t->map.dy = extract_double(ctx, p); } break; case 7: -#line 86 "control_parser.rl" +#line 88 "control_parser.rl" { t->map.min_sensor = extract_double(ctx, p); } break; case 8: -#line 87 "control_parser.rl" +#line 89 "control_parser.rl" { t->map.max_sensor = extract_double(ctx, p); } break; case 9: -#line 88 "control_parser.rl" +#line 90 "control_parser.rl" { t->map.max_speed = extract_double(ctx, p); } break; case 10: -#line 89 "control_parser.rl" +#line 91 "control_parser.rl" { t->map.max_turn = extract_double(ctx, p); } break; case 11: -#line 90 "control_parser.rl" +#line 92 "control_parser.rl" { t->map.max_hard_turn = extract_double(ctx, p); } break; case 12: -#line 94 "control_parser.rl" +#line 96 "control_parser.rl" { ctx->x = extract_double(ctx, p); } break; case 13: -#line 95 "control_parser.rl" +#line 97 "control_parser.rl" { ctx->y = extract_double(ctx, p); } break; case 14: -#line 96 "control_parser.rl" +#line 98 "control_parser.rl" { ctx->r = extract_double(ctx, p); } break; case 15: -#line 97 "control_parser.rl" +#line 99 "control_parser.rl" { ctx->dir = extract_double(ctx, p); } break; case 16: -#line 98 "control_parser.rl" +#line 100 "control_parser.rl" { ctx->speed = extract_double(ctx, p); } break; case 17: -#line 100 "control_parser.rl" +#line 102 "control_parser.rl" { ctx->tm->vehicle.accel = ACCEL; } break; case 18: -#line 101 "control_parser.rl" +#line 103 "control_parser.rl" { ctx->tm->vehicle.accel = ROLL; } break; case 19: -#line 102 "control_parser.rl" +#line 104 "control_parser.rl" { ctx->tm->vehicle.accel = BRAKE; } break; case 20: -#line 104 "control_parser.rl" +#line 106 "control_parser.rl" { ctx->tm->vehicle.turn = TURN_HARD_LEFT; } break; case 21: -#line 105 "control_parser.rl" +#line 107 "control_parser.rl" { ctx->tm->vehicle.turn = TURN_LEFT; } break; case 22: -#line 106 "control_parser.rl" +#line 108 "control_parser.rl" { ctx->tm->vehicle.turn = TURN_STRAIGHT; } break; case 23: -#line 107 "control_parser.rl" +#line 109 "control_parser.rl" { ctx->tm->vehicle.turn = TURN_RIGHT; } break; case 24: -#line 108 "control_parser.rl" +#line 110 "control_parser.rl" { ctx->tm->vehicle.turn = TURN_HARD_RIGHT; } break; case 25: -#line 110 "control_parser.rl" +#line 112 "control_parser.rl" { ctx->ts = extract_ts(ctx, p); } break; case 26: -#line 111 "control_parser.rl" +#line 113 "control_parser.rl" { printf("Score %u\n", extract_ts(ctx, p)); } break; case 27: -#line 113 "control_parser.rl" +#line 115 "control_parser.rl" { object *o = object_new(BOLDER, ctx->x, ctx->y, ctx->r, 0, 0); /* g_array_append_vals(ctx->tm->objects, o, 1); */ @@ -528,7 +530,7 @@ _match: } break; case 28: -#line 118 "control_parser.rl" +#line 120 "control_parser.rl" { object *o = object_new(CRATER, ctx->x, ctx->y, ctx->r, 0, 0); /* g_array_append_vals(ctx->tm->objects, o, 1); */ @@ -536,13 +538,13 @@ _match: } break; case 29: -#line 124 "control_parser.rl" +#line 126 "control_parser.rl" { object o = { MARTIAN, ctx->x, ctx->y, MARTIAN_RADIUS, ctx->dir, ctx->speed }; g_array_append_val(ctx->tm->objects, o); } break; -#line 546 "control_parser.c" +#line 548 "control_parser.c" } } @@ -554,7 +556,7 @@ _again: _test_eof: {} _out: {} } -#line 191 "control_parser.rl" +#line 193 "control_parser.rl" ctx->pos = p - ctx->buffer->str; if (ctx->mark == -1) { diff --git a/src/control_parser.rl b/src/control_parser.rl index f175226..5f0138f 100644 --- a/src/control_parser.rl +++ b/src/control_parser.rl @@ -46,6 +46,8 @@ static timestamp extract_ts(context *ctx, char *fpc) { gettimeofday(&t->started, NULL); /* fprintf(stderr, "New run\n"); */ } else { + dgl(t, &t->sim.tm.vehicle, &t->sim.tm.vehicle, ctx->tm->ts - t->sim.tm.ts); + ctx->tm->vehicle.w = t->sim.tm.vehicle.w; /* fprintf(stderr, "time difference [ms]: %i\n", getcurts(t) - ctx->tm->ts); */ fprintf(stderr, "Miss predict: dx=%f, dy=%f, ddir=%f, steps=%u\n", t->sim.tm.vehicle.x - t->vehicle.x,