Revision 1047
Draws polygons in the environment.
branches/simulator/projects/simulator/libsim/libsim.c | ||
---|---|---|
13 | 13 |
|
14 | 14 |
void *tick(int sig) |
15 | 15 |
{ |
16 |
printf("robot paused. suspending\n"); |
|
17 |
|
|
18 | 16 |
if(raise(SIGTSTP)<0) |
19 | 17 |
printf("could not kill self!\n"); |
20 | 18 |
|
21 |
printf("robot resumed\n"); |
|
22 |
|
|
23 | 19 |
return NULL; |
24 | 20 |
} |
25 | 21 |
|
... | ... | |
33 | 29 |
|
34 | 30 |
if(shared_state < 0) |
35 | 31 |
{ |
36 |
printf("unable to get shared memory region\n");
|
|
37 |
return 1;
|
|
32 |
fprintf(stderr, "unable to get shared memory region\n");
|
|
33 |
return; |
|
38 | 34 |
} |
39 | 35 |
|
40 | 36 |
|
... | ... | |
50 | 46 |
|
51 | 47 |
ret = setitimer(ITIMER_VIRTUAL, &iv, NULL); |
52 | 48 |
|
53 |
printf("setitimer returned %d.\n waiting...\n", ret); |
|
49 |
//printf("setitimer returned %d.\n waiting...\n", ret);
|
|
54 | 50 |
fflush(stdout); |
55 | 51 |
|
56 | 52 |
//TODO: clean up code?? |
branches/simulator/projects/simulator/simulator/gui/gtk_environment_view.c | ||
---|---|---|
10 | 10 |
#include "gtk_environment_view.h" |
11 | 11 |
|
12 | 12 |
#include "robot.h" |
13 |
#include "world.h" |
|
13 | 14 |
|
14 | 15 |
#define ENVIRONMENT_VIEW_MIN_WIDTH 100 |
15 | 16 |
#define ENVIRONMENT_VIEW_MIN_HEIGHT 50 |
... | ... | |
38 | 39 |
GdkEventMotion* event); |
39 | 40 |
|
40 | 41 |
|
42 |
static void draw_world(GdkDrawable* drawable, GdkGC* gc, world_t* world); |
|
41 | 43 |
static void draw_robot(GdkDrawable* drawable, GdkGC* gc, |
42 | 44 |
float x, float y, float angle); |
43 | 45 |
|
... | ... | |
191 | 193 |
return FALSE; |
192 | 194 |
|
193 | 195 |
view = GTK_ENVIRONMENT_VIEW(widget); |
196 |
|
|
197 |
draw_world(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], &world); |
|
194 | 198 |
|
195 | 199 |
robot_iterator_reset(); |
196 | 200 |
Robot* r; |
197 | 201 |
while ((r = robot_iterator_next()) != NULL) { |
198 |
printf("x: %f, y:%f, Theta: %f\n", |
|
199 |
r->pose.x, r->pose.y, r->pose.theta); |
|
200 | 202 |
draw_robot(widget->window, |
201 | 203 |
widget->style->fg_gc[GTK_WIDGET_STATE(widget)], |
202 | 204 |
r->pose.x, r->pose.y, r->pose.theta); |
... | ... | |
352 | 354 |
gdk_threads_leave(); |
353 | 355 |
} |
354 | 356 |
|
357 |
static void draw_world(GdkDrawable* drawable, GdkGC* gc, world_t* world) |
|
358 |
{ |
|
359 |
int i, j; |
|
360 |
GdkPoint* points; |
|
361 |
poly_t* p; |
|
362 |
|
|
363 |
if (!drawable || !gc || !world) |
|
364 |
return; |
|
365 |
|
|
366 |
double leftx = world->win.p1.x; |
|
367 |
double upy = world->win.p1.x; |
|
368 |
double xwidth = world->win.p2.x - leftx; |
|
369 |
double yheight = world->win.p2.y - upy; |
|
370 |
|
|
371 |
|
|
372 |
int width, height; |
|
373 |
gdk_drawable_get_size(drawable, &width, &height); |
|
374 |
|
|
375 |
if (xwidth / width < yheight / height) |
|
376 |
width = (int)(height / yheight * xwidth); |
|
377 |
else |
|
378 |
height = (int)(width / xwidth * yheight); |
|
379 |
|
|
380 |
for (i = 0 ; i < world->max_objs; i++) |
|
381 |
{ |
|
382 |
object_t* o = &(world->objs[i]); |
|
383 |
switch (o->id) |
|
384 |
{ |
|
385 |
case ID_POLY: |
|
386 |
p = (poly_t*)o->props; |
|
387 |
points = (GdkPoint*)malloc(sizeof(GdkPoint) * p->num_pts); |
|
388 |
for (j = 0; j < p->num_pts; j++) |
|
389 |
{ |
|
390 |
points[j].x = (int)((p->pts[j].x - leftx) / xwidth * width); |
|
391 |
points[j].y = (int)((p->pts[j].y - upy) / yheight * height); |
|
392 |
} |
|
393 |
switch(p->type) |
|
394 |
{ |
|
395 |
case POLY_CONNECTED: |
|
396 |
gdk_draw_polygon(drawable, gc, 1, points, p->num_pts); |
|
397 |
break; |
|
398 |
default: |
|
399 |
fprintf(stderr, "Detected unexpected type of polygon.\n"); |
|
400 |
break; |
|
401 |
} |
|
402 |
free(points); |
|
403 |
break; |
|
404 |
// no object |
|
405 |
case ID_NULL: |
|
406 |
break; |
|
407 |
default: |
|
408 |
fprintf(stderr, "Unexpected object type %d in world.\n", o->id); |
|
409 |
break; |
|
410 |
} |
|
411 |
} |
|
412 |
} |
|
413 |
|
|
355 | 414 |
static void draw_robot(GdkDrawable* drawable, GdkGC* gc, |
356 | 415 |
float x, float y, float angle) |
357 | 416 |
{ |
branches/simulator/projects/simulator/simulator/core/main.c | ||
---|---|---|
27 | 27 |
exit(-1); |
28 | 28 |
} |
29 | 29 |
|
30 |
load_world("../../test/world.txt", 100);
|
|
30 |
load_world("../test/world.txt", 100); |
|
31 | 31 |
|
32 | 32 |
|
33 | 33 |
robot_create(argv[1]); |
branches/simulator/projects/simulator/simulator/core/robot.c | ||
---|---|---|
75 | 75 |
int pid,i; |
76 | 76 |
int id = first_available_id; |
77 | 77 |
Robot* r = &robots[id]; |
78 |
printf("ID: %d\n", id); |
|
79 | 78 |
// do shared memory stuff here |
80 | 79 |
key_t key = IPC_PRIVATE; |
81 | 80 |
//Memory accessible only to children with r/w privileges |
branches/simulator/projects/simulator/simulator/core/world.c | ||
---|---|---|
24 | 24 |
world.objs = calloc(max_objs, sizeof(object_t)); |
25 | 25 |
world.win = b; |
26 | 26 |
/* Add a polygon surrounding the world */ |
27 |
create(ID_POLY,4,POLY_CONNECTED,pts); |
|
27 |
// this devours the world - brian |
|
28 |
//create(ID_POLY,4,POLY_CONNECTED,pts); |
|
28 | 29 |
} |
29 | 30 |
int destroy_world() |
30 | 31 |
{ |
... | ... | |
245 | 246 |
{ |
246 | 247 |
rf.d = rf_thetas[ir]; |
247 | 248 |
x = collide_world(&rf); |
248 |
printf("[%d] = %g\n", ir, x); |
|
249 |
//printf("[%d] = %g\n", ir, x);
|
|
249 | 250 |
bot->shared->ranges.d[ir] = x; |
250 | 251 |
} |
251 | 252 |
} |
branches/simulator/projects/simulator/test/world.txt | ||
---|---|---|
1 |
WORLD 0 0 512 512 |
|
2 |
POLYGON 4 CONNECTED -1 -1 -1 1 1 1 1 -1 |
|
1 |
WORLD -1 -1 1 1 |
|
2 |
POLYGON 4 CONNECTED -1 -1 -1 1 -0.99 1 -0.99 -1 |
|
3 |
POLYGON 4 CONNECTED -0.99 -1 -0.99 -0.99 0.99 -0.99 0.99 -1 |
|
4 |
POLYGON 4 CONNECTED -0.99 1 -0.99 0.99 0.99 0.99 0.99 1 |
|
5 |
POLYGON 4 CONNECTED 1 -1 1 1 0.99 1 0.99 -1 |
|
6 |
|
|
7 |
POLYGON 4 CONNECTED -0.2 -0.2 -0.2 0.2 0.2 0.2 0.2 -0.2 |
|
8 |
|
Also available in: Unified diff