Project

General

Profile

Revision 997

Started on drawing robots in the right place.

View differences:

branches/simulator/projects/simulator/simulator/gui/gtk_environment_view.c
10 10
#include "gtk_environment_view.h"
11 11
#include "draw_funcs.h"
12 12

  
13
#include "robot.h"
14

  
13 15
#define ENVIRONMENT_VIEW_MIN_WIDTH		100
14 16
#define ENVIRONMENT_VIEW_MIN_HEIGHT		50
15 17

  
......
190 192
//	gdk_draw_arc(widget->window, 
191 193
//		widget->style->fg_gc[GTK_WIDGET_STATE(widget)], FALSE, 0, 0,
192 194
//		100, 100, 0, 360*64);
193
	draw_robot(widget->window, 
194
		widget->style->fg_gc[GTK_WIDGET_STATE(widget)], 10, 10, 370);
195
	
196
	robot_iterator_reset();
197
	Robot* r;
198
	while ((r = robot_iterator_next()) != NULL)
199
		draw_robot(widget->window, 
200
			widget->style->fg_gc[GTK_WIDGET_STATE(widget)], r->pose.x, r->pose.y, r->pose.theta);
195 201

  
196 202
	return FALSE;
197 203
}
branches/simulator/projects/simulator/simulator/core/robot.c
31 31
Robot* robots = NULL;
32 32
int robots_size = 0;
33 33

  
34
int iterator_pos = 0;
35

  
34 36
int robots_initialize(void)
35 37
{
38
	int i;
36 39
	if (signal(SIGCHLD, sig_chld_handler) == SIG_ERR)
37 40
		return -1;
38 41

  
......
41 44
	if (!robots)
42 45
		return -1;
43 46
	memset(robots, 0, sizeof(Robot) * robots_size);
47
	for (i = 0; i < robots_size; i++)
48
		robots[i].id = -1;
44 49

  
45 50
	return 0;
46 51
}
......
84 89

  
85 90
	if((pid = fork()) < 0)
86 91
	{
87
		
88 92
		//Free Shared Memory Region
89
		if (!shmdt(r->shared))                    
93
		if (!shmdt(r->shared))
90 94
			fprintf(stderr, "Failed to free shared memory.\n");
91 95
		
92
		if (!shmctl(r->sharedMemID, IPC_RMID, NULL))	
93
			fprintf(stderr, "Failed to free shared memory.\n");      
96
		if (!shmctl(r->sharedMemID, IPC_RMID, NULL))
97
			fprintf(stderr, "Failed to free shared memory.\n");
94 98

  
95
		r->id = 0;
99
		r->id = -1;
96 100
		fprintf(stderr, "Failed to fork robot process.\n");
97 101
		return -1;
98
	}											 
102
	}
99 103
	
100 104

  
101 105
	if(!pid)
......
161 165
	}
162 166

  
163 167
	memset(r, 0, sizeof(Robot));
168
	r->id = -1;
164 169

  
165 170
	if (id < first_available_id)
166 171
		first_available_id = 0;
......
168 173
	return 0;
169 174
}
170 175

  
176
void robot_iterator_reset(void)
177
{
178
	iterator_pos = 0;
179
}
180

  
181
// note: addresses may change, replace with
182
// allocated memory
183
Robot* robot_iterator_next(void)
184
{
185
	while (iterator_pos < robots_size && 
186
			robots[iterator_pos].id == -1)
187
		iterator_pos++;
188
	
189
	if (iterator_pos >= robots_size)
190
		return NULL;
191
	
192
	return &(robots[iterator_pos]);
193
}
194

  
171 195
void sig_chld_handler(int sig)
172 196
{
173 197
	pid_t pid;
branches/simulator/projects/simulator/simulator/core/robot.h
35 35
int robot_create(char *execname);
36 36
int robot_destroy(int id);
37 37

  
38
void robot_iterator_reset(void);
39
Robot* robot_iterator_next(void);
40

  
38 41
#endif
39 42

  

Also available in: Unified diff