xxx
This commit is contained in:
parent
24e8bf6496
commit
8be5c7e20e
@ -94,7 +94,7 @@ struct trial {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* extern */
|
/* extern */
|
||||||
void simulate(trial *t);
|
void simulate(trial *t, timestamp ts);
|
||||||
void godown(trial *t);
|
void godown(trial *t);
|
||||||
|
|
||||||
/* trial */
|
/* trial */
|
||||||
|
@ -27,7 +27,7 @@ static timestamp extract_ts(context *ctx, char *fpc) {
|
|||||||
return atoi(ctx->tmp->str);
|
return atoi(ctx->tmp->str);
|
||||||
}
|
}
|
||||||
|
|
||||||
#line 134 "control_parser.rl"
|
#line 138 "control_parser.rl"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -243,7 +243,7 @@ static const int control_parser_error = 0;
|
|||||||
|
|
||||||
static const int control_parser_en_main = 1;
|
static const int control_parser_en_main = 1;
|
||||||
|
|
||||||
#line 137 "control_parser.rl"
|
#line 141 "control_parser.rl"
|
||||||
|
|
||||||
static int control_parser_has_error(context *ctx) {
|
static int control_parser_has_error(context *ctx) {
|
||||||
return ctx->cs == control_parser_error;
|
return ctx->cs == control_parser_error;
|
||||||
@ -260,7 +260,7 @@ void control_parser_new(trial *t) {
|
|||||||
{
|
{
|
||||||
( ctx->cs) = control_parser_start;
|
( ctx->cs) = control_parser_start;
|
||||||
}
|
}
|
||||||
#line 149 "control_parser.rl"
|
#line 153 "control_parser.rl"
|
||||||
ctx->buffer = g_string_sized_new(0);
|
ctx->buffer = g_string_sized_new(0);
|
||||||
ctx->tmp = g_string_sized_new(0);
|
ctx->tmp = g_string_sized_new(0);
|
||||||
ctx->mark = -1;
|
ctx->mark = -1;
|
||||||
@ -274,7 +274,7 @@ void control_parser_reset(trial *t) {
|
|||||||
{
|
{
|
||||||
( ctx->cs) = control_parser_start;
|
( ctx->cs) = control_parser_start;
|
||||||
}
|
}
|
||||||
#line 158 "control_parser.rl"
|
#line 162 "control_parser.rl"
|
||||||
g_string_truncate(ctx->tmp, 0);
|
g_string_truncate(ctx->tmp, 0);
|
||||||
ctx->mark = -1;
|
ctx->mark = -1;
|
||||||
/* fprintf(stderr, "Parser reset\n"); */
|
/* fprintf(stderr, "Parser reset\n"); */
|
||||||
@ -398,6 +398,10 @@ _match:
|
|||||||
/* fprintf(stderr, "New run\n"); */
|
/* fprintf(stderr, "New run\n"); */
|
||||||
} else {
|
} else {
|
||||||
/* fprintf(stderr, "time difference [ms]: %i\n", getcurts(t) - ctx->tm->ts); */
|
/* fprintf(stderr, "time difference [ms]: %i\n", getcurts(t) - ctx->tm->ts); */
|
||||||
|
fprintf(stderr, "Miss predict: dx=%f, dy=%f, ddir=%f\n",
|
||||||
|
t->sim.vehicle.x - t->vehicle.x,
|
||||||
|
t->sim.vehicle.y - t->vehicle.y,
|
||||||
|
t->sim.vehicle.dir - t->vehicle.dir);
|
||||||
}
|
}
|
||||||
/* Reset simulation */
|
/* Reset simulation */
|
||||||
t->sim.ts = ctx->tm->ts;
|
t->sim.ts = ctx->tm->ts;
|
||||||
@ -409,7 +413,7 @@ _match:
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
#line 59 "control_parser.rl"
|
#line 63 "control_parser.rl"
|
||||||
{
|
{
|
||||||
ctx->tm->ts = ctx->ts;
|
ctx->tm->ts = ctx->ts;
|
||||||
ctx->tm->vehicle.x = ctx->x;
|
ctx->tm->vehicle.x = ctx->x;
|
||||||
@ -424,115 +428,115 @@ _match:
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
#line 76 "control_parser.rl"
|
#line 80 "control_parser.rl"
|
||||||
{ t->map.dx = extract_double(ctx, p); }
|
{ t->map.dx = extract_double(ctx, p); }
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
#line 77 "control_parser.rl"
|
#line 81 "control_parser.rl"
|
||||||
{ t->map.dy = extract_double(ctx, p); }
|
{ t->map.dy = extract_double(ctx, p); }
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
#line 78 "control_parser.rl"
|
#line 82 "control_parser.rl"
|
||||||
{ t->map.min_sensor = extract_double(ctx, p); }
|
{ t->map.min_sensor = extract_double(ctx, p); }
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
#line 79 "control_parser.rl"
|
#line 83 "control_parser.rl"
|
||||||
{ t->map.max_sensor = extract_double(ctx, p); }
|
{ t->map.max_sensor = extract_double(ctx, p); }
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
#line 80 "control_parser.rl"
|
#line 84 "control_parser.rl"
|
||||||
{ t->map.max_speed = extract_double(ctx, p); }
|
{ t->map.max_speed = extract_double(ctx, p); }
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 10:
|
||||||
#line 81 "control_parser.rl"
|
#line 85 "control_parser.rl"
|
||||||
{ t->map.max_turn = extract_double(ctx, p); }
|
{ t->map.max_turn = extract_double(ctx, p); }
|
||||||
break;
|
break;
|
||||||
case 11:
|
case 11:
|
||||||
#line 82 "control_parser.rl"
|
#line 86 "control_parser.rl"
|
||||||
{ t->map.max_hard_turn = extract_double(ctx, p); }
|
{ t->map.max_hard_turn = extract_double(ctx, p); }
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 12:
|
||||||
#line 86 "control_parser.rl"
|
#line 90 "control_parser.rl"
|
||||||
{ ctx->x = extract_double(ctx, p); }
|
{ ctx->x = extract_double(ctx, p); }
|
||||||
break;
|
break;
|
||||||
case 13:
|
case 13:
|
||||||
#line 87 "control_parser.rl"
|
#line 91 "control_parser.rl"
|
||||||
{ ctx->y = extract_double(ctx, p); }
|
{ ctx->y = extract_double(ctx, p); }
|
||||||
break;
|
break;
|
||||||
case 14:
|
case 14:
|
||||||
#line 88 "control_parser.rl"
|
#line 92 "control_parser.rl"
|
||||||
{ ctx->r = extract_double(ctx, p); }
|
{ ctx->r = extract_double(ctx, p); }
|
||||||
break;
|
break;
|
||||||
case 15:
|
case 15:
|
||||||
#line 89 "control_parser.rl"
|
#line 93 "control_parser.rl"
|
||||||
{ ctx->dir = extract_double(ctx, p); }
|
{ ctx->dir = extract_double(ctx, p); }
|
||||||
break;
|
break;
|
||||||
case 16:
|
case 16:
|
||||||
#line 90 "control_parser.rl"
|
#line 94 "control_parser.rl"
|
||||||
{ ctx->speed = extract_double(ctx, p); }
|
{ ctx->speed = extract_double(ctx, p); }
|
||||||
break;
|
break;
|
||||||
case 17:
|
case 17:
|
||||||
#line 92 "control_parser.rl"
|
#line 96 "control_parser.rl"
|
||||||
{ ctx->tm->vehicle.accel = ACCEL; }
|
{ ctx->tm->vehicle.accel = ACCEL; }
|
||||||
break;
|
break;
|
||||||
case 18:
|
case 18:
|
||||||
#line 93 "control_parser.rl"
|
#line 97 "control_parser.rl"
|
||||||
{ ctx->tm->vehicle.accel = ROLL; }
|
{ ctx->tm->vehicle.accel = ROLL; }
|
||||||
break;
|
break;
|
||||||
case 19:
|
case 19:
|
||||||
#line 94 "control_parser.rl"
|
#line 98 "control_parser.rl"
|
||||||
{ ctx->tm->vehicle.accel = BRAKE; }
|
{ ctx->tm->vehicle.accel = BRAKE; }
|
||||||
break;
|
break;
|
||||||
case 20:
|
case 20:
|
||||||
#line 96 "control_parser.rl"
|
#line 100 "control_parser.rl"
|
||||||
{ ctx->tm->vehicle.turn = TURN_HARD_LEFT; }
|
{ ctx->tm->vehicle.turn = TURN_HARD_LEFT; }
|
||||||
break;
|
break;
|
||||||
case 21:
|
case 21:
|
||||||
#line 97 "control_parser.rl"
|
#line 101 "control_parser.rl"
|
||||||
{ ctx->tm->vehicle.turn = TURN_LEFT; }
|
{ ctx->tm->vehicle.turn = TURN_LEFT; }
|
||||||
break;
|
break;
|
||||||
case 22:
|
case 22:
|
||||||
#line 98 "control_parser.rl"
|
#line 102 "control_parser.rl"
|
||||||
{ ctx->tm->vehicle.turn = TURN_STRAIGHT; }
|
{ ctx->tm->vehicle.turn = TURN_STRAIGHT; }
|
||||||
break;
|
break;
|
||||||
case 23:
|
case 23:
|
||||||
#line 99 "control_parser.rl"
|
#line 103 "control_parser.rl"
|
||||||
{ ctx->tm->vehicle.turn = TURN_RIGHT; }
|
{ ctx->tm->vehicle.turn = TURN_RIGHT; }
|
||||||
break;
|
break;
|
||||||
case 24:
|
case 24:
|
||||||
#line 100 "control_parser.rl"
|
#line 104 "control_parser.rl"
|
||||||
{ ctx->tm->vehicle.turn = TURN_HARD_RIGHT; }
|
{ ctx->tm->vehicle.turn = TURN_HARD_RIGHT; }
|
||||||
break;
|
break;
|
||||||
case 25:
|
case 25:
|
||||||
#line 102 "control_parser.rl"
|
#line 106 "control_parser.rl"
|
||||||
{ ctx->ts = extract_ts(ctx, p); }
|
{ ctx->ts = extract_ts(ctx, p); }
|
||||||
break;
|
break;
|
||||||
case 26:
|
case 26:
|
||||||
#line 103 "control_parser.rl"
|
#line 107 "control_parser.rl"
|
||||||
{ printf("Score %u\n", extract_ts(ctx, p)); }
|
{ printf("Score %u\n", extract_ts(ctx, p)); }
|
||||||
break;
|
break;
|
||||||
case 27:
|
case 27:
|
||||||
#line 105 "control_parser.rl"
|
#line 109 "control_parser.rl"
|
||||||
{
|
{
|
||||||
object o = { BOLDER, ctx->x, ctx->y, ctx->r, 0, 0 };
|
object o = { BOLDER, ctx->x, ctx->y, ctx->r, 0, 0 };
|
||||||
g_array_append_val(ctx->tm->objects, o);
|
g_array_append_val(ctx->tm->objects, o);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 28:
|
case 28:
|
||||||
#line 109 "control_parser.rl"
|
#line 113 "control_parser.rl"
|
||||||
{
|
{
|
||||||
object o = { CRATER, ctx->x, ctx->y, ctx->r, 0, 0 };
|
object o = { CRATER, ctx->x, ctx->y, ctx->r, 0, 0 };
|
||||||
g_array_append_val(ctx->tm->objects, o);
|
g_array_append_val(ctx->tm->objects, o);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 29:
|
case 29:
|
||||||
#line 114 "control_parser.rl"
|
#line 118 "control_parser.rl"
|
||||||
{
|
{
|
||||||
object o = { MARTIAN, ctx->x, ctx->y, MARTIAN_RADIUS, ctx->dir, ctx->speed };
|
object o = { MARTIAN, ctx->x, ctx->y, MARTIAN_RADIUS, ctx->dir, ctx->speed };
|
||||||
g_array_append_val(ctx->tm->objects, o);
|
g_array_append_val(ctx->tm->objects, o);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#line 536 "control_parser.c"
|
#line 540 "control_parser.c"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -544,7 +548,7 @@ _again:
|
|||||||
_test_eof: {}
|
_test_eof: {}
|
||||||
_out: {}
|
_out: {}
|
||||||
}
|
}
|
||||||
#line 181 "control_parser.rl"
|
#line 185 "control_parser.rl"
|
||||||
|
|
||||||
ctx->pos = p - ctx->buffer->str;
|
ctx->pos = p - ctx->buffer->str;
|
||||||
if (ctx->mark == -1) {
|
if (ctx->mark == -1) {
|
||||||
|
@ -47,6 +47,10 @@ static timestamp extract_ts(context *ctx, char *fpc) {
|
|||||||
/* fprintf(stderr, "New run\n"); */
|
/* fprintf(stderr, "New run\n"); */
|
||||||
} else {
|
} else {
|
||||||
/* fprintf(stderr, "time difference [ms]: %i\n", getcurts(t) - ctx->tm->ts); */
|
/* fprintf(stderr, "time difference [ms]: %i\n", getcurts(t) - ctx->tm->ts); */
|
||||||
|
fprintf(stderr, "Miss predict: dx=%f, dy=%f, ddir=%f\n",
|
||||||
|
t->sim.vehicle.x - t->vehicle.x,
|
||||||
|
t->sim.vehicle.y - t->vehicle.y,
|
||||||
|
t->sim.vehicle.dir - t->vehicle.dir);
|
||||||
}
|
}
|
||||||
/* Reset simulation */
|
/* Reset simulation */
|
||||||
t->sim.ts = ctx->tm->ts;
|
t->sim.ts = ctx->tm->ts;
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define LATENCY 20
|
||||||
|
|
||||||
void trial_loop(trial *t) {
|
void trial_loop(trial *t) {
|
||||||
// path *p;
|
// path *p;
|
||||||
// int offset;
|
// int offset;
|
||||||
@ -16,7 +18,7 @@ void trial_loop(trial *t) {
|
|||||||
// offset = path_app_target(p,t,offset,0,0);
|
// offset = path_app_target(p,t,offset,0,0);
|
||||||
while (t->alive) {
|
while (t->alive) {
|
||||||
// path_execute(t,p);
|
// path_execute(t,p);
|
||||||
simulate(t);
|
simulate(t, getcurts(t) + LATENCY);
|
||||||
godown(t);
|
godown(t);
|
||||||
if (-1 == trial_check_input(t)) return;
|
if (-1 == trial_check_input(t)) return;
|
||||||
}
|
}
|
||||||
|
@ -17,17 +17,20 @@ void godown(trial *t) {
|
|||||||
vehicle v;
|
vehicle v;
|
||||||
telemetry *tm;
|
telemetry *tm;
|
||||||
|
|
||||||
double xpot, ypot, r, angle;
|
double xpot, ypot, r, vr, angle, vdirx, vdiry;
|
||||||
|
|
||||||
/* todo: simulate movement */
|
/* todo: simulate movement */
|
||||||
v = t->sim.vehicle;
|
v = t->sim.vehicle;
|
||||||
|
|
||||||
tm = (telemetry*) g_queue_peek_tail(&t->telemetry);
|
tm = (telemetry*) g_queue_peek_tail(&t->telemetry);
|
||||||
|
|
||||||
r = sqrt(v.x*v.x + v.y*v.y);
|
vr = sqrt(v.x*v.x + v.y*v.y);
|
||||||
if (r < 4) return; /* done */
|
if (vr < 4) return; /* done */
|
||||||
xpot = 0.2 * v.x/r;
|
xpot = 0.1 * v.x/vr;
|
||||||
ypot = 0.2 * v.y/r;
|
ypot = 0.1 * v.y/vr;
|
||||||
|
vr = vr*vr;
|
||||||
|
vdirx = cos(v.dir);
|
||||||
|
vdiry = sin(v.dir);
|
||||||
|
|
||||||
for (guint i = 0; i < tm->objects->len; i++) {
|
for (guint i = 0; i < tm->objects->len; i++) {
|
||||||
object *o = &g_array_index(tm->objects, object, i);
|
object *o = &g_array_index(tm->objects, object, i);
|
||||||
@ -36,20 +39,25 @@ void godown(trial *t) {
|
|||||||
|
|
||||||
switch (o->type) {
|
switch (o->type) {
|
||||||
case BOLDER:
|
case BOLDER:
|
||||||
sigma = 2;
|
r = (o->x * o->x + o->y + o->y);
|
||||||
|
if ((vdirx*(o->x-v.x) + vdiry*(o->y-v.y)) < 0) continue;
|
||||||
|
sigma = 2 * o->rad + 1;
|
||||||
h = 1;
|
h = 1;
|
||||||
break;
|
break;
|
||||||
case CRATER:
|
case CRATER:
|
||||||
sigma = 4;
|
r = (o->x * o->x + o->y + o->y);
|
||||||
|
if ((vdirx*(o->x-v.x) + vdiry*(o->y-v.y)) < 0) continue;
|
||||||
|
sigma = 2 * o->rad + 3;
|
||||||
h = 1;
|
h = 1;
|
||||||
break;
|
break;
|
||||||
case MARTIAN:
|
case MARTIAN:
|
||||||
sigma = 8;
|
sigma = 6;
|
||||||
h = 1;
|
h = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = sqrt( (o->x - v.x) * (o->x - v.x) + (o->y - v.y) * (o->y - v.y) ) - o->rad;
|
r = sqrt((o->x - v.x) * (o->x - v.x) + (o->y - v.y) * (o->y - v.y)) - o->rad;
|
||||||
|
r = r*r;
|
||||||
// r = r*r*r * 10;
|
// r = r*r*r * 10;
|
||||||
r = C1 * h / (sigma*sigma) / exp (r / (2*sigma) );
|
r = C1 * h / (sigma*sigma) / exp (r / (2*sigma) );
|
||||||
xpot += (o->x - v.x) * r;
|
xpot += (o->x - v.x) * r;
|
||||||
@ -71,7 +79,7 @@ void godown(trial *t) {
|
|||||||
vehicle_left(t);
|
vehicle_left(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fprintf(stderr, "Angle: %f, objects: %u\n", angle, tm->objects->len);
|
// fprintf(stderr, "Angle: %f, objects: %u\n", angle, tm->objects->len);
|
||||||
angle = abs(angle);
|
angle = abs(angle);
|
||||||
if (angle > 60) {
|
if (angle > 60) {
|
||||||
vehicle_break(t);
|
vehicle_break(t);
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
#define LATENCY 20
|
|
||||||
|
|
||||||
static double fixdir(double a) {
|
static double fixdir(double a) {
|
||||||
if (a < 0) a += 360;
|
if (a < 0) a += 360;
|
||||||
@ -11,23 +10,24 @@ static double fixdir(double a) {
|
|||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
void simulate(trial *t) {
|
void simulate(trial *t, timestamp ts) {
|
||||||
double move, angle;
|
double move, angle;
|
||||||
|
|
||||||
timestamp now = getcurts(t) + LATENCY, diff = now - t->sim.ts;
|
timestamp diff = ts - t->sim.ts;
|
||||||
if (diff < 20) return;
|
if (diff == 0) return;
|
||||||
|
t->sim.ts = ts;
|
||||||
|
|
||||||
/* move = t->sim.vehicle.speed / 1000 * diff;
|
move = t->sim.vehicle.speed / 1000 * diff;
|
||||||
angle = t->sim.vehicle.dir*M_PI/180;
|
angle = t->sim.vehicle.dir*M_PI/180;
|
||||||
t->sim.vehicle.x += cos(angle)*move;
|
t->sim.vehicle.x += cos(angle)*move;
|
||||||
t->sim.vehicle.y += sin(angle)*move;*/
|
t->sim.vehicle.y += sin(angle)*move;
|
||||||
|
|
||||||
/* switch (t->sim.vehicle.turn) {
|
/* switch (t->sim.vehicle.turn) {
|
||||||
case TURN_HARD_LEFT : t->sim.vehicle.dir = fixdir(t->sim.vehicle.dir + t->map.max_hard_turn); break;
|
case TURN_HARD_LEFT : t->sim.vehicle.dir = fixdir(t->sim.vehicle.dir + t->map.max_hard_turn/1000*diff); break;
|
||||||
case TURN_LEFT : t->sim.vehicle.dir = fixdir(t->sim.vehicle.dir + t->map.max_turn); break;
|
case TURN_LEFT : t->sim.vehicle.dir = fixdir(t->sim.vehicle.dir + t->map.max_turn/1000*diff); break;
|
||||||
case TURN_STRAIGHT : break;
|
case TURN_STRAIGHT : break;
|
||||||
case TURN_RIGHT : t->sim.vehicle.dir = fixdir(t->sim.vehicle.dir - t->map.max_turn); break;
|
case TURN_RIGHT : t->sim.vehicle.dir = fixdir(t->sim.vehicle.dir - t->map.max_turn/1000*diff); break;
|
||||||
case TURN_HARD_RIGHT: t->sim.vehicle.dir = fixdir(t->sim.vehicle.dir - t->map.max_hard_turn); break;
|
case TURN_HARD_RIGHT: t->sim.vehicle.dir = fixdir(t->sim.vehicle.dir - t->map.max_hard_turn/1000*diff); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
t->sim.vehicle.accel = t->vehicle.accel;
|
t->sim.vehicle.accel = t->vehicle.accel;
|
||||||
|
Loading…
Reference in New Issue
Block a user