Project

General

Profile

Revision 1064

Cleaned up code, removed all compiler warnings.

View differences:

branches/simulator/projects/simulator/libsim/libsim.c
13 13

  
14 14
RobotShared* shared_state;
15 15

  
16
void *tick(int sig)
16
void tick(int sig)
17 17
{
18 18
  if(raise(SIGTSTP)<0)
19 19
    printf("could not kill self!\n");
20

  
21
  return NULL;
22 20
}
23 21

  
24 22

  
......
36 34
  }
37 35

  
38 36
                                             
39
  printf("hello. I am a robot w/ memory_id %s\n", getenv("memory_id"));
37
  //printf("hello. I am a robot w/ memory_id %s\n", getenv("memory_id"));
40 38

  
41 39

  
42 40
  iv.it_interval.tv_sec = 0;
branches/simulator/projects/simulator/simulator/core/robot.c
23 23
#include <pthread.h>
24 24
#include <err.h>
25 25

  
26
#include "gtk_gui.h"
27

  
26 28
#include "robot.h"
27 29
#include "motion.h"
30
#include "rangefinders.h"
28 31
#include "world.h"
29
#include "gtk_gui.h"
30 32

  
31 33
void sig_chld_handler(int sig);
32 34
void robot_update(int i);
branches/simulator/projects/simulator/simulator/core/world.c
16 16

  
17 17
world_t world;
18 18

  
19
int destroy(object_t *obj);
20

  
19 21
int init_world(int max_objs, bbox_t b)
20 22
{
21
    double pts[8] = {b.p1.x, b.p1.y, b.p1.x, b.p2.y, b.p2.x,b.p2.y,b.p2.x,b.p1.y};
22 23
    world.max_objs = max_objs;
23 24
    world.cur_objs = 0;
24 25
    world.objs = calloc(max_objs,  sizeof(object_t));
25 26
    world.win = b;
26
    /* Add a polygon surrounding the world */
27
	// this devours the world - brian
28
    //create(ID_POLY,4,POLY_CONNECTED,pts);
27

  
28
	return 0;
29 29
}
30

  
30 31
int destroy_world()
31 32
{
32 33
    int i;
33
    for (i = 0; i < world.cur_objs; i++) {
34
	destroy(&world.objs[i]);
35
    }
34
    for (i = 0; i < world.cur_objs; i++)
35
        destroy(&world.objs[i]);
36 36
    free(world.objs);
37

  
38
	return 0;
37 39
}
38 40

  
39 41
double (*collide_func[NUM_SHAPES])(ray_t *ray, object_t *obj) =
......
50 52
    };
51 53

  
52 54

  
53

  
54 55
double collide_circle(ray_t *ray, object_t *obj)
55 56
{
56 57
    return -1;
......
147 148
int destroy(object_t *obj) 
148 149
{
149 150
    if (obj->id == ID_NULL)
150
	return 0;
151
        return 0;
151 152
    destroy_func[obj->id+ID_OFFSET](obj);
152 153
    obj->id = ID_NULL;
154

  
155
    return 0;
153 156
}
154 157

  
155 158
/**
......
184 187

  
185 188
int create_rect(object_t *obj, va_list ap)
186 189
{
187
    int i;
190
    /*int i;
188 191
    poly_t *p;
189
    int argc = va_arg(ap, int);
192
    int argc = va_arg(ap, int);*/
193

  
194
	return 0;
190 195
}
191 196

  
192 197
int destroy_poly (object_t *obj)
......
228 233
}
229 234

  
230 235

  
231
/*
232
 * XXX: This shouldn't be here. Where should it be?
233
 */
234
/* These need to be measured... */
235
double rf_thetas[5] = {0.0, 2*M_PI/5, 4*M_PI/5, 6*M_PI/5, 8*M_PI/5};
236
//double rf_thetas[5] = {0.0, 0.0, M_PI/2, M_PI, 3*M_PI/2};
237
void update_rangefinders(Robot *bot)
238
{
239
    RangeFinder r = bot->shared->ranges;
240
    ray_t rf = {bot->pose.x, bot->pose.y, 0};
241
    /* Motion code has +y going down, I don't.
242
     * So to compensate, just reflect theta up to first quadrant.*/
243
    double theta = bot->pose.theta;
244
    int ir;
245
    double x;
246
    for (ir = 0; ir < 5; ir++)
247
    {
248
	rf.d = theta + rf_thetas[ir];
249
	x = collide_world(&rf);
250
	//printf("@(%g) - [%d] = %g --> %d\n",rf.d, ir, x, (short)x);
251
	bot->shared->ranges.d[ir] = x;
252
    }
253
}
254

  
255 236
int load_object (const char* line) {
256 237
  char buf[BUF_SIZE];
257 238
  int i = 0;
......
317 298
int load_world (const char* filename,int max_objs) {
318 299
  FILE* fin;
319 300
  char buf[BUF_SIZE];
320
  bbox_t bbox = {0,0,0,0};
301
  bbox_t bbox;
321 302
  if ((fin = fopen(filename,"r"))==NULL){
322 303
    // open file failed
323 304
		perror("Fail to open file");
branches/simulator/projects/simulator/simulator/core/rangefinders.c
1
#include "rangefinders.h"
2

  
3
#include <math.h>
4

  
5
#include "robot.h"
6
#include "world.h"
7

  
8
//TODO: These need to be measured...
9
double rf_thetas[5] = {0.0, 2*M_PI/5, 4*M_PI/5, 6*M_PI/5, 8*M_PI/5};
10
//double rf_thetas[5] = {0.0, 0.0, M_PI/2, M_PI, 3*M_PI/2};
11

  
12
void update_rangefinders(Robot *bot)
13
{
14
    ray_t rf;
15
	rf.p.x = bot->pose.x;
16
	rf.p.y = bot->pose.y;
17
	rf.d = 0.0;
18
    /* Motion code has +y going down, I don't.
19
     * So to compensate, just reflect theta up to first quadrant.*/
20
    double theta = bot->pose.theta;
21
    int ir;
22
    double x;
23
    for (ir = 0; ir < 5; ir++)
24
    {
25
	rf.d = theta + rf_thetas[ir];
26
	x = collide_world(&rf);
27
	//printf("@(%g) - [%d] = %g --> %d\n",rf.d, ir, x, (short)x);
28
	bot->shared->ranges.d[ir] = x;
29
    }
30
}
31

  
branches/simulator/projects/simulator/simulator/core/rangefinders.h
1
#ifndef __RANGEFINDERS_H__
2
#define __RANGEFINDERS_H__
3

  
4
struct RobotType;
5

  
6
void update_rangefinders(struct RobotType *bot);
7

  
8
#endif
9

  
branches/simulator/projects/simulator/simulator/Makefile
1 1
# Add new files here
2 2
COMMON_SRCS :=
3
CORE_SRCS := main.c robot.c motion.c world.c
3
CORE_SRCS := main.c robot.c motion.c world.c rangefinders.c
4 4
GUI_SRCS := gtk_gui.c gtk_environment_view.c
5 5

  
6 6
CORE_DIR := core
......
11 11
SRCS += $(addprefix $(CORE_DIR)/, $(CORE_SRCS))
12 12
SRCS += $(addprefix $(GUI_DIR)/, $(GUI_SRCS))
13 13
OBJS = $(patsubst %.c, %.o, $(SRCS))
14
VIM_LEFTOVERS = $(patsubst %, %~, $(SRCS))
14
VIM_LEFTOVERS = $(CORE_DIR)/*~ $(COMMON_DIR)/*~ $(GUI_DIR)/*~
15 15
PROG = simulator
16 16

  
17 17
INCLUDES = -I$(COMMON_DIR) -I$(CORE_DIR) -I$(GUI_DIR)
......
32 32
	$(CC) $(CFLAGS) -c -o $@ $<
33 33

  
34 34
clean:
35
	rm *~ $(OBJS) $(VIM_LEFTOVERS) $(PROG)
35
	rm -f *~ $(OBJS) $(VIM_LEFTOVERS) $(PROG)
36 36

  

Also available in: Unified diff