Project

General

Profile

Revision 1020

Now runs at a reasonable speed.

View differences:

branches/simulator/projects/simulator/libsim/libsim.c
8 8
#include <sys/ipc.h>
9 9
#include <robot_shared.h>
10 10
#include <string.h>
11

  
12

  
13 11
RobotShared* shared_state;
14 12

  
15 13
void *tick(int sig)
......
42 40
  printf("hello. I am a robot w/ memory_id %s\n", getenv("memory_id"));
43 41

  
44 42

  
45
  iv.it_interval.tv_sec = 1;
46
  iv.it_interval.tv_usec = 0;
47
  iv.it_value.tv_sec = 3;
48
  iv.it_value.tv_usec = 0;
43
  iv.it_interval.tv_sec = 0;
44
  iv.it_interval.tv_usec = 50000;
45
  iv.it_value.tv_sec = 0;
46
  iv.it_value.tv_usec = 50000;
49 47

  
50 48
  signal(SIGVTALRM, tick);
51 49

  
branches/simulator/projects/simulator/libsim/Makefile
17 17

  
18 18
TARGET = libsim
19 19

  
20
all: $(OBJ)
20
all: dist
21

  
22
build: $(OBJ)
21 23
	$(AR) rcs $(TARGET).a $(OBJ)
22 24

  
23 25
%.o: %.c
......
26 28
clean:
27 29
	$(RM) $(OBJ) $(TARGET).a
28 30

  
29
dist: all
31
dist: build
30 32
	$(CP) $(TARGET).a $(OUTPUT)
branches/simulator/projects/simulator/simulator/gui/gtk_environment_view.c
39 39

  
40 40

  
41 41
static void draw_robot(GdkDrawable* drawable, GdkGC* gc, 
42
                        int x, int y, int angle);
42
                        float x, float y, float angle);
43 43

  
44 44
GtkType gtk_environment_view_get_type(void)
45 45
{
......
195 195
	robot_iterator_reset();
196 196
	Robot* r;
197 197
	while ((r = robot_iterator_next()) != NULL) {
198
        printf("x: %d, y:%d, Theta: %f\n",
198
        printf("x: %f, y:%f, Theta: %f\n",
199 199
            r->pose.x, r->pose.y, r->pose.theta);
200 200
		draw_robot(widget->window, 
201 201
			widget->style->fg_gc[GTK_WIDGET_STATE(widget)], 
......
353 353
}
354 354

  
355 355
static void draw_robot(GdkDrawable* drawable, GdkGC* gc, 
356
                        int x, int y, int angle) 
356
                        float x, float y, float angle) 
357 357
{
358 358
	if (!drawable || !gc)
359 359
		return;
360
	double ang_rad = angle * ENVIRONMENT_PI / 180;
361
	int x_c = x - ENVIRONMENT_ROBOT_DIAMETER / 2;
362
	int y_c = y - ENVIRONMENT_ROBOT_DIAMETER / 2;
360
	int x_c = (int)x - ENVIRONMENT_ROBOT_DIAMETER / 2;
361
	int y_c = (int)y - ENVIRONMENT_ROBOT_DIAMETER / 2;
363 362

  
364 363
	gdk_draw_arc(drawable, gc, FALSE, x_c, y_c, 
365 364
	  	ENVIRONMENT_ROBOT_DIAMETER, ENVIRONMENT_ROBOT_DIAMETER, 
366 365
        0, 360*64);
367 366

  
368 367
	gdk_draw_line(drawable, gc, x, y, 
369
		x + (ENVIRONMENT_ROBOT_DIAMETER - 10) * cos(ang_rad),
370
		y - (ENVIRONMENT_ROBOT_DIAMETER - 10) * sin(ang_rad));
368
		x + (ENVIRONMENT_ROBOT_DIAMETER - 10) * cos(-angle),
369
		y - (ENVIRONMENT_ROBOT_DIAMETER - 10) * sin(-angle));
371 370
}
372 371

  
branches/simulator/projects/simulator/simulator/core/motion.c
10 10
#define TIME			1 /*sec*/
11 11
#define ROBOT_WIDTH 131 /*mm*/
12 12

  
13
#define MOTOR_CONVERSION_FACTOR 10.0
14

  
13 15
/** move will move a robot from its initial position, (x,y), and theta (in radians) to a new position given speed.
14 16
 * (x,y) and theta will be updated by the move function instead of returning a value
15 17
 * (x,y) is some kind of absolute position in the "world", let's make (0,0) the top left of the "world"
......
34 36
	if (ABS(speed2) < CUTOFF) {
35 37
		speed2 = 0;
36 38
	}
39
	speed1 = (speed1 - CUTOFF);
40
	speed2 = (speed2 - CUTOFF);
37 41
	double radius;
38 42
	if (speed1 == speed2) {
39 43
		/* go straight */
40
	r->pose.x += cos(theta) * speed1;
41
	r->pose.y += sin(theta) * speed1;
44
	r->pose.x += cos(theta) * speed1 / MOTOR_CONVERSION_FACTOR;
45
	r->pose.y += sin(theta) * speed1 / MOTOR_CONVERSION_FACTOR;
42 46
		return 0;
43 47
	}
44 48
	radius = ROBOT_WIDTH * speed1 / (speed1 - speed2);
45 49
	
46
	double t = speed1 / radius;
50
	double t = speed1 / radius / MOTOR_CONVERSION_FACTOR;
47 51

  
48
	double newx = radius * sin(t);
49
	double newy = radius - radius * cos(t);
52
	double newx = (radius * sin(t)) / MOTOR_CONVERSION_FACTOR;
53
	double newy = (radius - radius * cos(t)) / MOTOR_CONVERSION_FACTOR;
50 54
	
51 55
	r->pose.x += newx * cos(theta);
52 56
	r->pose.y += newx * sin(theta);
branches/simulator/projects/simulator/simulator/core/robot.h
15 15

  
16 16
typedef struct PoseType
17 17
{
18
	int x,y; /* position of robot in environment */
18
	float x,y; /* position of robot in environment */
19 19
	float theta; /* orientation of robot in environment */
20 20
} Pose;
21 21

  
branches/simulator/projects/template/main.c
4 4
{
5 5
	dragonfly_init(ALL_ON);
6 6
	bom_leds_on(BOM_ALL);
7
	motor1_set(1, 200);
8
	motor2_set(1, 150);
7 9
	while(1){}
8 10
	return 0;
9 11
}
branches/simulator/projects/template/Makefile
12 12
# USE_WIRELESS = 1
13 13

  
14 14
# Relative path to the root directory (containing lib directory)
15
PROJECTSROOT = ..
15 16
ifndef COLONYLIB
16
COLONYLIB = ../../lib
17
COLONYLIB = $(PROJECTSROOT)/../lib
17 18
endif
18 19

  
19 20
#
......
292 293
REMOVE = rm -f
293 294
REMOVEDIR = rm -rf
294 295
COPY = cp
296
CP = cp
295 297
WINSHELL = cmd
296 298

  
297 299

  
......
338 340
all: begin gccversion sizebefore build sizeafter end
339 341

  
340 342
build: elf hex eep lss sym
341
sim: $(SIMOBJ)
343
sim: dist
344

  
345
buildsim: $(SIMOBJ)
342 346
	$(SIMCC) $(SIMALL_CFLAGS) $^ -o $(TARGET) $(SIMLDFLAGS)
347
dist: buildsim
348
	$(CP) $(TARGET) $(PROJECTSROOT)/simulator/simulator/bin/
343 349

  
344 350
%.obj : %.c
345 351
	$(SIMCC) -c $(SIMALL_CFLAGS) $< -o $@

Also available in: Unified diff