/unsupported/tags/rel_0_5/joy/makefile |
File deleted |
|
Property changes: |
Deleted: svn:executable |
## -1 +0,0 ## |
-* |
\ No newline at end of property |
Index: rel_0_5/joy/joy_test.c |
=================================================================== |
--- rel_0_5/joy/joy_test.c (revision 1667) |
+++ rel_0_5/joy/joy_test.c (nonexistent) |
@@ -1,131 +0,0 @@ |
- |
-/* |
- * Project: S.Ha.R.K. |
- * |
- * Coordinators: Giorgio Buttazzo <giorgio@sssup.it> |
- * |
- * Authors : Paolo Gai <pj@hartik.sssup.it> |
- * (see authors.txt for full list of hartik's authors) |
- * |
- * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
- * |
- * http://www.sssup.it |
- * http://retis.sssup.it |
- * http://shark.sssup.it |
- */ |
- |
-/* |
- * Copyright (C) 2000 Paolo Gai |
- * |
- * This program is free software; you can redistribute it and/or modify |
- * it under the terms of the GNU General Public License as published by |
- * the Free Software Foundation; either version 2 of the License, or |
- * (at your option) any later version. |
- * |
- * This program is distributed in the hope that it will be useful, |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
- * GNU General Public License for more details. |
- * |
- * You should have received a copy of the GNU General Public License |
- * along with this program; if not, write to the Free Software |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
- * |
- */ |
- |
-#include <kernel/kern.h> |
-#include <kernel/func.h> |
-#include <stdlib.h> |
-#include <drivers/keyb.h> |
-#include <math.h> |
- |
-#include "joy.h" |
- |
-PID pid; |
- |
-void endfun(KEY_EVT *k) |
-{ |
- cprintf("Ctrl-Brk pressed! Ending...\n"); |
- sys_end(); |
-} |
- |
-void my_close(void *arg) |
-{ |
- int i; |
- TIME tmp; |
- |
- kern_printf("Taskset Execution Time\n\n"); |
- for (i=3; i<MAX_PROC; i++){ |
- if (!jet_getstat(i, NULL, &tmp, NULL, NULL)) |
- kern_printf("Task Name : %s - Max Time : %d\n", proc_table[i].name, (int)tmp); |
- } |
-} |
- |
- |
-TASK write() |
-{ |
- JOY_STATE jsa; |
- |
- while (1) { |
- get_joystick_A(&jsa); |
- place(2,4); |
- cprintf("The X coord. is: %3d and the Y coord. is: %3d of the joystick1\n", jsa.x, jsa.y); |
- place(2,12); |
- cprintf("The button 1, joystick 1 is: %3d\n", jsa.b1); |
- place(2,14); |
- cprintf("The button 2, joystick 1 is: %3d\n", jsa.b2); |
- |
- task_endcycle(); |
- } |
- return 0; |
-} |
- |
-int main(int argc, char **argv) |
-{ |
- SOFT_TASK_MODEL ms; |
- KEY_EVT k; |
- TIME seme; |
- |
- JOY_BOUND jb; |
- |
- k.flag = CNTR_BIT; |
- k.scan = KEY_C; |
- k.ascii = 'c'; |
- keyb_hook(k,endfun); |
- |
- k.flag = CNTL_BIT; |
- k.scan = KEY_C; |
- k.ascii = 'c'; |
- keyb_hook(k,endfun); |
- |
- seme = sys_gettime(NULL); |
- srand(seme); |
- |
- sys_atrunlevel(my_close, NULL, RUNLEVEL_BEFORE_EXIT); |
- |
- clear(); |
- |
- if (get_joystick_bound_A(&jb)) { |
- perror("Could not find Joystick."); |
- sys_end(); |
- } |
- |
- place(2,2); |
- cprintf("The X bounds are: [ %3d - %3d ] and the Y bounds are: [ %3d - %3d ]\n", jb.x_min,jb.x_max,jb.y_min,jb.y_max); |
- |
- soft_task_default_model(ms); |
- soft_task_def_level(ms,1); |
- soft_task_def_ctrl_jet(ms); |
- soft_task_def_met(ms,100); |
- soft_task_def_period(ms,10000); |
- soft_task_def_usemath(ms); |
- pid = task_create("Write", write, &ms, NULL); |
- if (pid == NIL) { |
- perror("Could not create task <Write>"); |
- sys_end(); |
- } else { |
- task_activate(pid); |
- } |
- |
- return 0; |
-} |
/rel_0_5/joy/joy_test.c |
Property changes: |
Deleted: svn:executable |
## -1 +0,0 ## |
-* |
\ No newline at end of property |
Index: rel_0_5/joy/joy_grx.c |
=================================================================== |
--- rel_0_5/joy/joy_grx.c (revision 1667) |
+++ rel_0_5/joy/joy_grx.c (nonexistent) |
@@ -1,177 +0,0 @@ |
- |
-/* |
- * Project: S.Ha.R.K. |
- * |
- * Coordinators: Giorgio Buttazzo <giorgio@sssup.it> |
- * |
- * Authors : Paolo Gai <pj@hartik.sssup.it> |
- * (see authors.txt for full list of hartik's authors) |
- * |
- * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
- * |
- * http://www.sssup.it |
- * http://retis.sssup.it |
- * http://shark.sssup.it |
- */ |
- |
-/* |
- * Copyright (C) 2000 Paolo Gai |
- * |
- * This program is free software; you can redistribute it and/or modify |
- * it under the terms of the GNU General Public License as published by |
- * the Free Software Foundation; either version 2 of the License, or |
- * (at your option) any later version. |
- * |
- * This program is distributed in the hope that it will be useful, |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
- * GNU General Public License for more details. |
- * |
- * You should have received a copy of the GNU General Public License |
- * along with this program; if not, write to the Free Software |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
- * |
- */ |
- |
-#include <kernel/kern.h> |
-#include <kernel/func.h> |
-#include <stdlib.h> |
-#include <drivers/keyb.h> |
-#include <drivers/glib.h> |
-#include <semaphore.h> |
-#include "modules/sem.h" |
-#include "modules/hartport.h" |
- |
-#include <math.h> |
- |
-#include "joy.h" |
- |
-#define RGB_BLACK rgb16( 0, 0, 0) |
-#define RGB_GRAY rgb16(127,127,127) |
-#define RGB_WHITE rgb16(255,255,255) |
-#define RGB_RED rgb16(255, 0, 0) |
-#define RGB_GREEN rgb16( 0,255, 0) |
-#define RGB_BLUE rgb16( 0, 0,255) |
-#define RGB_YELLOW rgb16(255,255, 0) |
-#define RGB_MAGENTA rgb16(255, 0,255) |
-#define RGB_CYAN rgb16( 0,255,255) |
-#define RGB_D_RED rgb16(127, 0, 0) |
-#define RGB_D_GREEN rgb16( 0,127, 0) |
-#define RGB_D_BLUE rgb16( 0, 0,127) |
-#define RGB_D_YELLOW rgb16(127,127, 0) |
-#define RGB_D_MAGENTA rgb16(127, 0,127) |
-#define RGB_D_CYAN rgb16( 0,127,127) |
- |
-sem_t mx_mat, mx_grf; /* mutex semaphores */ |
-PID pid; |
-JOY_BOUND jb; |
- |
- |
-TASK write() |
-{ |
- int x = 319, y = 239; |
- float dx, dy; |
- JOY_STATE jsa; |
- |
- clear(); |
- |
- dx = 640 / (jb.x_max - jb.x_min); |
- dy = 480 / (jb.y_max - jb.y_min); |
- |
- while (1) { |
- sem_wait(&mx_grf); |
- grx_circle(10 + x, 10 + y, 9, RGB_BLACK); |
- sem_post(&mx_grf); |
- |
- get_joystick_A(&jsa); |
- |
- x = (jsa.x - jb.x_min) * dx; |
- y = (jsa.y - jb.y_min) * dy; |
- |
- sem_wait(&mx_grf); |
- if (jsa.b1==1) |
- grx_circle(10 + dx * x, 10 + dy * y, 9, RGB_RED); |
- else |
- grx_circle(10 + dx * x, 10 + dy * y, 9, RGB_YELLOW); |
- sem_post(&mx_grf); |
- |
- task_endcycle(); |
- } |
- return 0; |
-} |
- |
-void endfun(KEY_EVT *k) |
-{ |
- cprintf("Ctrl-Brk pressed! Ending...\n"); |
- sys_end(); |
-} |
- |
-void my_close(void *arg) |
-{ |
- int i; |
- TIME tmp; |
- |
- grx_close(); |
- kern_printf("Taskset Execution Time\n\n"); |
- for (i=3; i<MAX_PROC; i++){ |
- if (!jet_getstat(i, NULL, &tmp, NULL, NULL)) |
- kern_printf("Task Name : %s - Max Time : %d\n", proc_table[i].name, (int)tmp); |
- } |
-} |
- |
-void init_graph() { |
- grx_box( 0, 0,639,479,RGB_BLACK); |
-} |
- |
-int main(int argc, char **argv) |
-{ |
- SOFT_TASK_MODEL ms; |
- KEY_EVT k; |
- TIME seme; |
- int modenum; |
- |
- k.flag = CNTR_BIT; |
- k.scan = KEY_C; |
- k.ascii = 'c'; |
- keyb_hook(k,endfun); |
- |
- k.flag = CNTL_BIT; |
- k.scan = KEY_C; |
- k.ascii = 'c'; |
- keyb_hook(k,endfun); |
- |
- sem_init(&mx_mat,0,1); |
- sem_init(&mx_grf,0,1); |
- |
- seme = sys_gettime(NULL); |
- srand(seme); |
- |
- sys_atrunlevel(my_close, NULL, RUNLEVEL_BEFORE_EXIT); |
- |
- if (get_joystick_bound_A(&jb)) { |
- perror("Could not find Joystick."); |
- sys_end(); |
- } |
- |
- grx_init(); |
- modenum = grx_getmode(640, 480, 16); |
- grx_setmode(modenum); |
- init_graph(); |
- |
- soft_task_default_model(ms); |
- soft_task_def_level(ms,1); |
- soft_task_def_ctrl_jet(ms); |
- soft_task_def_met(ms,100); |
- soft_task_def_period(ms,10000); |
- soft_task_def_usemath(ms); |
- pid = task_create("Write", write, &ms, NULL); |
- if (pid == NIL) { |
- grx_close(); |
- perror("Could not create task <Write>"); |
- sys_end(); |
- } else { |
- task_activate(pid); |
- } |
- |
- return 0; |
-} |
/rel_0_5/joy/joy_grx.c |
Property changes: |
Deleted: svn:executable |
## -1 +0,0 ## |
-* |
\ No newline at end of property |
Index: rel_0_5/joy/initfile.c |
=================================================================== |
--- rel_0_5/joy/initfile.c (revision 1667) |
+++ rel_0_5/joy/initfile.c (nonexistent) |
@@ -1,84 +0,0 @@ |
-/* |
- * Project: HARTIK (HA-rd R-eal TI-me K-ernel) |
- * |
- * Coordinators: Giorgio Buttazzo <giorgio@sssup.it> |
- * Gerardo Lamastra <gerardo@sssup.it> |
- * |
- * Authors : Paolo Gai <pj@hartik.sssup.it> |
- * (see authors.txt for full list of hartik's authors) |
- * |
- * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
- * |
- * http://www.sssup.it |
- * http://retis.sssup.it |
- * http://hartik.sssup.it |
- */ |
- |
-/* |
- * Copyright (C) 2000 Paolo Gai |
- * |
- * This program is free software; you can redistribute it and/or modify |
- * it under the terms of the GNU General Public License as published by |
- * the Free Software Foundation; either version 2 of the License, or |
- * (at your option) any later version. |
- * |
- * This program is distributed in the hope that it will be useful, |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
- * GNU General Public License for more details. |
- * |
- * You should have received a copy of the GNU General Public License |
- * along with this program; if not, write to the Free Software |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
- * |
- */ |
- |
-#include <kernel/kern.h> |
-#include <kernel/func.h> |
-#include <stdlib.h> |
-#include <drivers/keyb.h> |
-#include <semaphore.h> |
-#include "modules/sem.h" |
-#include "modules/hartport.h" |
- |
-#include "modules/edf.h" |
-#include "modules/cbs.h" |
-#include "modules/rr.h" |
-#include "modules/dummy.h" |
- |
-/*+ sysyem tick in us +*/ |
-#define TICK 0 //300 |
- |
-/*+ RR tick in us +*/ |
-#define RRTICK 300 |
- |
-TIME __kernel_register_levels__(void *arg) |
-{ |
- struct multiboot_info *mb = (struct multiboot_info *)arg; |
- |
- EDF_register_level(EDF_ENABLE_ALL); |
- CBS_register_level(CBS_ENABLE_ALL, 0); |
- RR_register_level(RRTICK, RR_MAIN_YES, mb); |
- dummy_register_level(); |
- |
- SEM_register_module(); |
- |
- return TICK; |
-} |
- |
-TASK __init__(void *arg) |
-{ |
- struct multiboot_info *mb = (struct multiboot_info *)arg; |
- |
- KEYB_PARMS kparms = BASE_KEYB; |
- |
- HARTPORT_init(); |
- |
- //keyb_set_map(itaMap); |
- keyb_def_ctrlC(kparms, NULL); |
- KEYB_init(&kparms); |
- |
- __call_main__(mb); |
- |
- return (void *)0; |
-} |
/rel_0_5/joy/initfile.c |
Property changes: |
Deleted: svn:executable |
## -1 +0,0 ## |
-* |
\ No newline at end of property |
Index: rel_0_5/robots/lab.txt |
=================================================================== |
--- rel_0_5/robots/lab.txt (revision 1667) |
+++ rel_0_5/robots/lab.txt (nonexistent) |
@@ -1,10 +0,0 @@ |
-2 |
-530 380 15 270 |
-480 380 15 270 |
-380 300 400 5 |
-430 060 460 400 0 |
-350 100 430 130 0 |
-000 100 300 130 0 |
-150 200 430 230 0 |
-120 300 150 400 0 |
- |
Index: rel_0_5/robots/readme |
=================================================================== |
--- rel_0_5/robots/readme (revision 1667) |
+++ rel_0_5/robots/readme (nonexistent) |
@@ -1,9 +0,0 @@ |
-Robots demo |
------------ |
- |
-This demo has been developed in the University of Alveiro, Portugal. |
- |
-See the included PDF files for more informations. |
- |
-Paolo |
-pj@sssup.it |
Index: rel_0_5/robots/makefile |
=================================================================== |
--- rel_0_5/robots/makefile (revision 1667) |
+++ rel_0_5/robots/makefile (nonexistent) |
@@ -1,16 +0,0 @@ |
-# |
-# |
-# |
- |
-ifndef BASE |
-BASE=../.. |
-endif |
-include $(BASE)/config/config.mk |
- |
-PROGS = mouse2 |
- |
-include $(BASE)/config/example.mk |
- |
-mouse2: |
- make -f $(SUBMAKE) APP=mouse2 INIT= OTHEROBJS="initfile.o" OTHERINCL= SHARKOPT="__OLDCHAR__ __GRX__" |
- |
Index: rel_0_5/robots/lab3.txt |
=================================================================== |
--- rel_0_5/robots/lab3.txt (revision 1667) |
+++ rel_0_5/robots/lab3.txt (nonexistent) |
@@ -1,11 +0,0 @@ |
-3 |
-540 380 15 270 |
-510 380 15 270 |
-480 380 15 270 |
-380 300 400 5 |
-430 060 460 400 0 |
-350 100 430 130 0 |
-000 100 300 130 0 |
-150 200 430 230 0 |
-120 300 150 400 0 |
- |
Index: rel_0_5/robots/initfile.c |
=================================================================== |
--- rel_0_5/robots/initfile.c (revision 1667) |
+++ rel_0_5/robots/initfile.c (nonexistent) |
@@ -1,104 +0,0 @@ |
-/* |
- * Project: S.Ha.R.K. |
- * |
- * Coordinators: |
- * Giorgio Buttazzo <giorgio@sssup.it> |
- * Paolo Gai <pj@gandalf.sssup.it> |
- * |
- * Authors : |
- * Paolo Gai <pj@gandalf.sssup.it> |
- * (see the web pages for full authors list) |
- * |
- * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
- * |
- * http://www.sssup.it |
- * http://retis.sssup.it |
- * http://shark.sssup.it |
- */ |
- |
-/** |
- ------------ |
- CVS : $Id: initfile.c,v 1.1.1.1 2004-05-24 18:03:41 giacomo Exp $ |
- |
- File: $File$ |
- Revision: $Revision: 1.1.1.1 $ |
- Last update: $Date: 2004-05-24 18:03:41 $ |
- ------------ |
-**/ |
- |
-/* |
- * Copyright (C) 2001 Paolo Gai |
- * |
- * This program is free software; you can redistribute it and/or modify |
- * it under the terms of the GNU General Public License as published by |
- * the Free Software Foundation; either version 2 of the License, or |
- * (at your option) any later version. |
- * |
- * This program is distributed in the hope that it will be useful, |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
- * GNU General Public License for more details. |
- * |
- * You should have received a copy of the GNU General Public License |
- * along with this program; if not, write to the Free Software |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
- * |
- */ |
- |
-#include "kernel/kern.h" |
-#include "modules/edf.h" |
-#include "modules/cbs.h" |
-#include "modules/rr.h" |
-#include "modules/dummy.h" |
- |
-#include "modules/sem.h" |
-#include "modules/hartport.h" |
-#include "modules/cabs.h" |
-#include "drivers/keyb.h" |
- |
-/*+ sysyem tick in us +*/ |
-#define TICK 0 |
- |
-/*+ RR tick in us +*/ |
-#define RRTICK 2000 |
- |
-void read_cfgfile(int); |
- |
-int argc; |
-char *argv[100]; |
- |
-void read_cfg_file(int argc, char **argv); |
- |
-int main(int argc, char **argv); |
- |
-TIME __kernel_register_levels__(void *arg) |
-{ |
- struct multiboot_info *mb = (struct multiboot_info *)arg; |
- |
- EDF_register_level(0); |
- CBS_register_level(0, 0); |
- RR_register_level(RRTICK, RR_MAIN_YES, mb); |
- dummy_register_level(); |
- |
- SEM_register_module(); |
- |
- CABS_register_module(); |
- |
- __compute_args__(mb, &argc, argv); |
- |
- read_cfg_file(argc, argv); |
- |
- return TICK; |
-} |
- |
-TASK __init__(void *arg) |
-{ |
- KEYB_PARMS kparms = BASE_KEYB; |
- |
- HARTPORT_init(); |
- |
- keyb_def_ctrlC(kparms, NULL); |
- KEYB_init(&kparms); |
- |
- return (void *)main(argc,argv); |
-} |
Index: rel_0_5/robots/lab1m.txt |
=================================================================== |
--- rel_0_5/robots/lab1m.txt (revision 1667) |
+++ rel_0_5/robots/lab1m.txt (nonexistent) |
@@ -1,9 +0,0 @@ |
-1 |
-540 380 15 270 |
-380 300 400 5 |
-430 060 460 400 0 |
-350 100 430 130 0 |
-000 100 300 130 0 |
-150 200 430 230 0 |
-120 300 150 400 0 |
- |
Index: rel_0_5/robots/mouse2.c |
=================================================================== |
--- rel_0_5/robots/mouse2.c (revision 1667) |
+++ rel_0_5/robots/mouse2.c (nonexistent) |
@@ -1,933 +0,0 @@ |
-/*--------------------------------------------------------------*/ |
-/* Title: Mouse */ |
-/* Autor: João Capucho */ |
-/* Date: 9/12/2000 */ |
-/* Description: */ |
-/* Simulation of small automats based on the */ |
-/* "micro-rato" conteste */ |
-/*--------------------------------------------------------------*/ |
- |
-/* |
- * Copyright (C) 2001 João Capucho |
- * |
- * This program is free software; you can redistribute it and/or modify |
- * it under the terms of the GNU General Public License as published by |
- * the Free Software Foundation; either version 2 of the License, or |
- * (at your option) any later version. |
- * |
- * This program is distributed in the hope that it will be useful, |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
- * GNU General Public License for more details. |
- * |
- * You should have received a copy of the GNU General Public License |
- * along with this program; if not, write to the Free Software |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
- * |
- */ |
- |
- |
-// Includes |
-#include <ll/i386/x-dos.h> |
-#include <kernel/kern.h> |
-#include <drivers/glib.h> |
-#include <drivers/keyb.h> |
-#include <math.h> |
-#include <stdlib.h> |
-#include <limits.h> |
- |
-#define sqr(x) (x*x) |
- |
-// Error Types |
-#define OK 0 |
-#define MEMORY_ERROR -1 |
-#define ILEGAL_PARAMETER -2 |
- |
-// Types of sensors and motors |
-#define NONE 0 |
-#define OBSTACLE 1 |
-#define BEACON 2 |
-#define GROUND 3 |
-#define STEP 4 |
- |
-// Maze limits |
-#define LAB_XMIN 40 |
-#define LAB_XMAX 600 |
-#define LAB_YMIN 40 |
-#define LAB_YMAX 440 |
- |
-#define MOTOR_RIGHT 1 |
-#define MOTOR_LEFT 0 |
- |
-#define BACKCOLOR 0 // Background color |
-#define OUTCOLOR 14 // Color of the outside walls |
-#define FINISHCOLOR 7 // Finishin area color |
-#define NONBLOCKCOLOR 14 // Non block boxs |
-#define BLOCKCOLOR 13 // Block boxs |
- |
-#define BOX_BLOCK 1 // The box blocks the beacon |
-#define BOX_NON_BLOCK 2 // The box doesn´t block the beacon |
- |
-#define MAX_MOUSES 5 // Maximum of mouses in the Maze |
-#define MAX_BOXS 100 // Maximum of boxs in the Maze |
-#define MAX_SENSORS 20 // Maximum of sensors in each mouse |
-#define SENSOR_MIN_GROUND 0 // Minimum value of a ground sensor |
-#define SENSOR_MAX_GROUND 255 // Maximum value of a ground sensor |
-#define SENSOR_MIN_OBSTACLE 77 // Minimum value of a obstacle sensor |
-#define SENSOR_MAX_OBSTACLE 128 // Maximum value of a obstacle sensor |
-#define SENSOR_MIN_BEACON 77 // Minimum value of a beacon sensor |
-#define SENSOR_MAX_BEACON 128 // Maximum value of a beacon sensor |
-#define BEACON_INTENSITY 400 // Maximun intensity of the beacon |
- |
-#define MOUSE_PERIOD 20000 // Period |
-#define CALC_PERIOD 2000 // Period |
-#define REFEREE_PERIOD 1000 // Period of the referee |
-#define REDRAW_MOUSE_PERIOD 25000 // Period for redraw mouse |
-#define REDRAW_MAZE_PERIOD 100000 // Period for redraw maze |
-#define MOUSEGROUP 511 |
- |
-struct SENSOR |
-{ |
- int Type; // Tipe of sensor ( None - Obstacle - Beacon - Ground) |
- int Radius; // Distance from de center of the mouse |
- int Pos_Angle; // Angle between the sensor and the front of the mouse |
- int Dir; // Angle between the direction of the sensores and the front of the mouse |
- int Angle; // Half angle of visual field (between (Dir-Angle) and (Dir+Angle)) |
- int Intensity; // Sensativity of the sensor |
- float Value; // Last value readed |
-}; |
- |
-struct MOTOR |
-{ |
- int Radius; // Distance from de center of the mouse |
- int V; // Current velocity |
- float Old_V; // Previews velocity |
-}; |
- |
-struct MOUSE |
-{ |
- float X, Y; // Current position of the center |
- float Old_X, Old_Y; // Previous position of the center |
- int Radius; // Size of the mouse ( every mouse is considered round ) |
- float Dir; // Points to the front |
- float Old_Dir; // Previous front |
- int NSensors; // Number of sensors in the mouse |
- struct SENSOR Sensors[MAX_SENSORS]; // Pointer to the structer that contains the information of the sensors |
- struct MOTOR Motors[2]; // Pointer to the structer that contains the information of the motors |
- WORD NColision; // Total of colisions |
- WORD PColision; // Auxiliar for colisions |
- char Flag; // Initialization flag |
-}; |
- |
- |
- |
-struct BOX // Structer that represents the obstacles |
-{ //in this case all the obstacles are boxs |
- int Type; // Type of the obstatcle |
- int X1, Y1, X2, Y2; // position of the box |
-}; |
- |
-struct SBEACON // Beacon information |
-{ |
- int Intensity; // Intensity of the beacon |
- int X, Y; // position of the beacon |
-}; |
- |
-struct MAZE |
-{ |
- int X1, Y1, X2, Y2; // limites of the maze |
- int NBoxs; // Number of objstacles in the maze |
- struct BOX Boxs[MAX_BOXS]; // Information about all thr obstacles |
- struct SBEACON Beacon; // Beacon data |
- int Radius; // Size of the finishing area |
-}; |
- |
-int Seno[360+90]; // Sine table |
-int Tang[180]; // Tangente table |
-int NMouses=0; |
-struct MOUSE Mouse[MAX_MOUSES]; // Global variable that represents all the mouses |
-struct MAZE Maze; // Global variable that represents the maze |
- |
-// Init_Maze - Initialize the Maze |
-// Beacon_X - Coordinate X of the beacon |
-// Beacon_Y - Coordinate Y of the beacon |
-// Intensity - Intensity of the beacon |
-// NBoxs - Number of boxs in the maze |
-// Return: OK - Sucess |
- |
-int Init_Maze(int Beacon_X, int Beacon_Y, int Intensity, int NBoxs) |
-{ |
- int i; |
- Maze.X1=LAB_XMIN; |
- Maze.Y1=LAB_YMIN; |
- Maze.X2=LAB_XMAX; |
- Maze.Y2=LAB_YMAX; |
- Maze.Beacon.X=Beacon_X+LAB_XMIN; |
- Maze.Beacon.Y=Beacon_Y+LAB_YMIN; |
- if (Intensity<BEACON_INTENSITY) |
- Maze.Beacon.Intensity=Intensity; |
- else |
- Maze.Beacon.Intensity=BEACON_INTENSITY; |
- if (NBoxs<MAX_BOXS) |
- Maze.NBoxs=NBoxs; |
- else |
- Maze.NBoxs=MAX_BOXS; |
- Maze.Radius=50; |
- for(i=0; i < Maze.NBoxs; i++) |
- Maze.Boxs[i].Type=NONE; |
- return OK; |
-} |
- |
-// Init_Box - Initialize data of the NBox obstacle |
-// NBox - Identifier of the obstacle |
-// X1 - Coordinate X |
-// Y1 - Coordinate Y |
-// X2 - Coordinate X |
-// Y2 - Coordinate Y |
-// Type - Type of the obstacle |
-// Return: OK - Sucess |
- |
-int Init_Box(int NBox, int X1, int Y1, int X2, int Y2, int Type) |
-{ |
- Maze.Boxs[NBox].Type=Type; |
- if (X1<X2) |
- { |
- Maze.Boxs[NBox].X1=X1+LAB_XMIN; |
- Maze.Boxs[NBox].X2=X2+LAB_XMIN; |
- } |
- else |
- { |
- Maze.Boxs[NBox].X1=X2+LAB_XMIN; |
- Maze.Boxs[NBox].X2=X1+LAB_XMIN; |
- } |
- if (Y1<Y2) |
- { |
- Maze.Boxs[NBox].Y1=Y1+LAB_YMIN; |
- Maze.Boxs[NBox].Y2=Y2+LAB_YMIN; |
- } |
- else |
- { |
- Maze.Boxs[NBox].Y1=Y2+LAB_YMIN; |
- Maze.Boxs[NBox].Y2=Y1+LAB_YMIN; |
- } |
- return OK; |
-} |
- |
-// Draw_Maze - Draws the outline of the maze and the obstacles |
-// Return: OK - Sucess |
-int Draw_Maze(void) |
-{ |
- int i; |
- grx_rect( Maze.X1, Maze.Y1, Maze.X2, Maze.Y2, OUTCOLOR); |
- grx_rect( Maze.X1-1, Maze.Y1+1, Maze.X2+1, Maze.Y2+1, OUTCOLOR); |
- grx_rect( Maze.X1-2, Maze.Y1+2, Maze.X2+2, Maze.Y2+2, OUTCOLOR); |
- grx_circle(Maze.Beacon.X, Maze.Beacon.Y, Maze.Radius, FINISHCOLOR); |
- grx_disc(Maze.Beacon.X, Maze.Beacon.Y, 10, 7); |
- for (i=0; i<Maze.NBoxs; i++) |
- { |
- if (Maze.Boxs[i].Type==BOX_NON_BLOCK) |
- grx_box(Maze.Boxs[i].X1, Maze.Boxs[i].Y1, |
- Maze.Boxs[i].X2, Maze.Boxs[i].Y2, NONBLOCKCOLOR); |
- if (Maze.Boxs[i].Type==BOX_BLOCK) |
- grx_box(Maze.Boxs[i].X1, Maze.Boxs[i].Y1, |
- Maze.Boxs[i].X2, Maze.Boxs[i].Y2, BLOCKCOLOR); |
- } |
- return OK; |
-} |
- |
-int Init_Motor(int NMouse, int Motor, int Radius) |
-{ |
- if ((NMouse<0) || (NMouse>=MAX_MOUSES)) |
- return ILEGAL_PARAMETER; |
- if ((Motor<0) || (Motor>=2)) |
- return ILEGAL_PARAMETER; |
- Mouse[NMouse].Motors[Motor].Radius=Radius; |
- Mouse[NMouse].Motors[Motor].V=0; |
- Mouse[NMouse].Motors[Motor].Old_V=0.0; |
- return OK; |
-} |
- |
-// Init_Mouse - inicialize the parameters of each mouse |
-// NMouse - Identifier of the mouse |
-// X - Coordinate X of the center |
-// Y - Coordinate Y of the center |
-// Radius - Radius of the mouse (size) |
-// Dir - Angle of direction in witch i will start |
-// NSensors - Number of sensors in the mouse (all types) |
-// |
-// Return: OK - Sucess |
-// ILEGAL_PARAMETER - If NMouse negative of greater than maximum number of mouses |
-// Note: All the types of sensors and motors are initialize to NONE |
- |
-int Init_Mouse(int NMouse, int X, int Y, int Radius, int Dir, int NSensors) |
-{ |
- int i; |
- if ((NMouse<0) || (NMouse>=MAX_MOUSES)) |
- return ILEGAL_PARAMETER; |
- if ((NSensors<0) || (NSensors>MAX_SENSORS)) |
- return ILEGAL_PARAMETER; |
- Mouse[NMouse].X=(float)X+LAB_XMIN; |
- Mouse[NMouse].Y=(float)Y+LAB_YMIN; |
- Mouse[NMouse].Radius=Radius; |
- Mouse[NMouse].Dir=Dir; |
- Mouse[NMouse].Old_Dir=Mouse[NMouse].Dir; |
- Mouse[NMouse].NSensors=NSensors; |
- Mouse[NMouse].Old_X=Mouse[NMouse].X; |
- Mouse[NMouse].Old_Y=Mouse[NMouse].Y; |
- Mouse[NMouse].NColision=0; |
- Mouse[NMouse].PColision=0; |
- for(i=0; i < Mouse[NMouse].NSensors; i++) |
- Mouse[NMouse].Sensors[i].Type=NONE; |
- |
- Init_Motor(NMouse, MOTOR_LEFT, 10); |
- Init_Motor(NMouse, MOTOR_RIGHT, -10); |
- |
- return OK; |
-} |
- |
-// Init_Sensor - Initializes the sensor information |
-// NMouse - Identifier of the mouse |
-// Sensor - Identifier of the sensor to be used |
-// Type - Type of sensor ( Ground, obstacle or beacon sensor ) |
-// Radius and Pos_Angle - Polar coordinates to determen the sensor position |
-// Dir - Diretion of the sensor ( angle between the front and the sensor ) |
-// Angle - Half of the visual range |
-// Intensity - Maximun distance of detect |
-int Init_Sensor(int NMouse, int Sensor, int Type, int Radius, |
- int Pos_Angle, int Dir, int Angle, int Intensity) |
-{ |
- if ((NMouse<0) || (NMouse>=MAX_MOUSES)) |
- return ILEGAL_PARAMETER; |
- if ((Sensor<0) || (Sensor>=Mouse[NMouse].NSensors)) |
- return ILEGAL_PARAMETER; |
- Mouse[NMouse].Sensors[Sensor].Type=Type; |
- Mouse[NMouse].Sensors[Sensor].Radius=Radius; |
- Mouse[NMouse].Sensors[Sensor].Pos_Angle=Pos_Angle; |
- Mouse[NMouse].Sensors[Sensor].Dir=Dir; |
- Mouse[NMouse].Sensors[Sensor].Angle=Angle; |
- Mouse[NMouse].Sensors[Sensor].Intensity=Intensity; |
- if (Type == GROUND) |
- Mouse[NMouse].Sensors[Sensor].Value=(float)SENSOR_MIN_GROUND; |
- if (Type == OBSTACLE) |
- Mouse[NMouse].Sensors[Sensor].Value=(float)SENSOR_MIN_OBSTACLE; |
- if (Type == BEACON) |
- Mouse[NMouse].Sensors[Sensor].Value=(float)SENSOR_MIN_BEACON; |
- return OK; |
-} |
- |
-int Set_Motor_Vel(int NMouse, int NMotor, int Vel) |
-{ |
- if ((NMouse<0) || (NMouse>=MAX_MOUSES)) |
- return ILEGAL_PARAMETER; |
- if ((NMotor<0) || (NMotor>2)) |
- return ILEGAL_PARAMETER; |
- Mouse[NMouse].Motors[NMotor].V=Vel; |
- return OK; |
-} |
- |
-int Read_Sensor(int NMouse, int NSensor) |
-{ |
- int X, Y, Dir, cr, sr, AuxX, AuxY; |
- int Count, AuxCount, AngCount, AuxAngCount, RetColor, Intensity; |
- float Auxf; |
- |
- /* Inicial verifications */ |
- if ((NMouse<0) || (NMouse>=MAX_MOUSES)) |
- return ILEGAL_PARAMETER; |
- if ((NSensor<0) || (NSensor>Mouse[NMouse].NSensors)) |
- return ILEGAL_PARAMETER; |
- |
- /* If Sensor Not define exit */ |
- if ( Mouse[NMouse].Sensors[NSensor].Type == NONE ) |
- return OK; |
- |
- /* Calculate de position of the sensor and is direction */ |
- Dir=(int)Mouse[NMouse].Old_Dir+Mouse[NMouse].Sensors[NSensor].Dir; |
- if (Dir >= 360) |
- Dir -= 360; |
- if (Dir < 0) |
- Dir += 360; |
- X= Mouse[NMouse].Old_X*65536.0+((Mouse[NMouse].Sensors[NSensor].Radius*Seno[Dir+90])); |
- Y= Mouse[NMouse].Old_Y*65536.0+((Mouse[NMouse].Sensors[NSensor].Radius*Seno[Dir])); |
- |
- /* if the Sensor type is OBSTACLE */ |
- if ( Mouse[NMouse].Sensors[NSensor].Type == OBSTACLE ) |
- { |
- Intensity=Mouse[NMouse].Sensors[NSensor].Intensity; |
- AuxCount=Intensity; |
- /* Scan all the visual field */ |
- for (AngCount=(-Mouse[NMouse].Sensors[NSensor].Angle); |
- AngCount<=Mouse[NMouse].Sensors[NSensor].Angle; |
- AngCount++) |
- { |
- AuxAngCount=Dir+AngCount; |
- if (AuxAngCount >= 360) |
- AuxAngCount -= 360; |
- if (AuxAngCount < 0) |
- AuxAngCount += 360; |
- sr=Seno[AuxAngCount]; |
- cr=Seno[AuxAngCount+90]; |
- Count=Mouse[NMouse].Radius-Mouse[NMouse].Sensors[NSensor].Radius+2; |
- AuxX = X+cr*Count; |
- AuxY = Y+sr*Count; |
- for (; Count<=AuxCount; Count++) |
- { |
- AuxX += cr; |
- AuxY += sr; |
- RetColor = grx_getpixel(AuxX >> 16, AuxY >> 16); |
- if ((RetColor != BACKCOLOR)&&(RetColor != FINISHCOLOR)) |
- AuxCount=Count; |
- } |
- } |
- Count=Mouse[NMouse].Sensors[NSensor].Intensity; |
- Count*=Count; |
- AuxCount*=AuxCount; |
- Count = SENSOR_MAX_OBSTACLE-((SENSOR_MAX_OBSTACLE-SENSOR_MIN_OBSTACLE) |
- *AuxCount)/Count; |
- Mouse[NMouse].Sensors[NSensor].Value= |
- (0.5*Mouse[NMouse].Sensors[NSensor].Value+0.5*(float)Count); |
- } |
- if ( Mouse[NMouse].Sensors[NSensor].Type == GROUND ) |
- { |
- Mouse[NMouse].Sensors[NSensor].Value=(float)SENSOR_MIN_GROUND; |
- AuxX=abs((X>>16)-Maze.Beacon.X); |
- AuxY=abs((Y>>16)-Maze.Beacon.Y); |
- if ((AuxX>50) || (AuxY>50)) |
- return OK; |
- if ((AuxX*AuxX+AuxY*AuxY)<Maze.Radius*Maze.Radius) |
- Mouse[NMouse].Sensors[NSensor].Value=(float)SENSOR_MAX_GROUND; |
- } |
- |
- if ( Mouse[NMouse].Sensors[NSensor].Type == BEACON ) |
- { |
- AuxX=(X>>16)-Maze.Beacon.X; |
- AuxY=(Y>>16)-Maze.Beacon.Y; |
- AngCount=0; |
- if (AuxX!=0) |
- { |
- AuxAngCount=(AuxY<<16)/AuxX; |
- if (AuxAngCount<0) |
- AngCount=90; |
- for (Count=AngCount;Count<AngCount+90;Count++) |
- { |
- if ((Tang[Count]<=AuxAngCount) && (Tang[Count+1]>AuxAngCount)) |
- break; |
- } |
- } |
- else |
- Count=90; |
- if (AuxY<0) |
- Count+=180; |
- AuxAngCount=abs(180-abs(Dir-Count)); |
- Count=SENSOR_MIN_BEACON; |
- if (AuxAngCount<Mouse[NMouse].Sensors[NSensor].Angle) |
- { |
- Count=AuxX*AuxX+AuxY*AuxY; |
- AuxCount=(int)((float)Maze.Beacon.Intensity*(1.0+(0.4*(float)AuxAngCount)/(float)Mouse[NMouse].Sensors[NSensor].Angle)); |
- AuxCount*=AuxCount; |
- if (Count<AuxCount) |
- Count = SENSOR_MAX_OBSTACLE-((SENSOR_MAX_OBSTACLE-SENSOR_MIN_OBSTACLE)*Count)/AuxCount; |
- else |
- Count=SENSOR_MIN_BEACON; |
- } |
- Auxf=0.5*((float)Count); |
- Auxf+=0.5*((float)Mouse[NMouse].Sensors[NSensor].Value); |
- Mouse[NMouse].Sensors[NSensor].Value=Auxf; |
- } |
- return OK; |
-} |
- |
-int GetSensor(int NMouse, int NSensor) |
-{ |
- if ((NMouse<0) || (NMouse>=MAX_MOUSES)) |
- return ILEGAL_PARAMETER; |
- if ((NSensor<0) || (NSensor>Mouse[NMouse].NSensors)) |
- return ILEGAL_PARAMETER; |
- return (int)Mouse[NMouse].Sensors[NSensor].Value; |
-} |
- |
-int Draw_Mouse(int NMouse, int Flag) |
-{ |
- int Color; |
- if (!Flag) |
- Color=BACKCOLOR; |
- else |
- { |
- Mouse[NMouse].Old_X=Mouse[NMouse].X; |
- Mouse[NMouse].Old_Y=Mouse[NMouse].Y; |
- Mouse[NMouse].Old_Dir=Mouse[NMouse].Dir; |
- Color=2; |
- } |
- grx_circle(Mouse[NMouse].Old_X, Mouse[NMouse].Old_Y, Mouse[NMouse].Radius, Color); |
- grx_line(Mouse[NMouse].Old_X, Mouse[NMouse].Old_Y, |
- Mouse[NMouse].Old_X+((Mouse[NMouse].Radius*Seno[(int)Mouse[NMouse].Old_Dir+90]) >> 16), |
- Mouse[NMouse].Old_Y+((Mouse[NMouse].Radius*Seno[(int)Mouse[NMouse].Old_Dir]) >> 16), Color); |
- return OK; |
-} |
- |
-TASK Redraw_Mouse_Task(int NMouse) |
-{ |
- char str[40]; |
- TIME dwTicks; |
- while(1) |
- { |
- dwTicks=sys_gettime(NULL); |
- Draw_Mouse(NMouse, FALSE); |
- Draw_Mouse(NMouse, TRUE); |
- sprintf(str,"Colision: %4d", (int)Mouse[NMouse].NColision); |
- grx_text(str, NMouse*150, 21, 7, 0); |
- sprintf(str,"Motor: %4d Sensor 0: %4d Sensor 1: %4d Sensor 2: %4d Sensor 3: %4d", |
- (int)Mouse[NMouse].Motors[0].Old_V+(int)Mouse[NMouse].Motors[1].Old_V, |
- (int)Mouse[NMouse].Sensors[0].Value, (int)Mouse[NMouse].Sensors[1].Value, |
- (int)Mouse[NMouse].Sensors[2].Value, (int)Mouse[NMouse].Sensors[3].Value); |
- if (NMouse==0) |
- grx_text(str, 1, 1, 7, 0); |
- sprintf(str,"Sensor 4: %4d Sensor 5: %4d Ticks: %4d", |
- (int)Mouse[NMouse].Sensors[4].Value, (int)Mouse[NMouse].Sensors[5].Value, |
- (int)(sys_gettime(NULL)-dwTicks)/1000); |
- if (NMouse==0) |
- grx_text(str, 1, 11, 7, 0); |
- task_endcycle(); |
- } |
-} |
- |
-TASK Redraw_Maze_Task(void) |
-{ |
- while(1) |
- { |
- Draw_Maze(); |
- task_endcycle(); |
- } |
-} |
- |
-TASK Referee(void) |
-{ |
- int Counter, Box_Min_X, Box_Max_X ,Box_Min_Y, Box_Max_Y; |
- int deltaX, deltaY, Radius; |
- int Colision; |
- int NMouse; |
- |
- while(1) |
- { |
- for(NMouse=0;NMouse<NMouses;NMouse++) |
- { |
- Colision=0; |
- Radius=Mouse[NMouse].Radius; |
- if(Mouse[NMouse].Y<(Maze.Y1+Radius)) |
- Colision++; |
- if(Mouse[NMouse].Y>(Maze.Y2-Radius)) |
- Colision++; |
- if(Mouse[NMouse].X<(Maze.X1+Radius)) |
- Colision++; |
- if(Mouse[NMouse].X>(Maze.X2-Radius)) |
- Colision++; |
- for(Counter=0; Counter<Maze.NBoxs; Counter++) |
- { |
- Box_Min_X=Maze.Boxs[Counter].X1-1; |
- Box_Max_X=Maze.Boxs[Counter].X2+1; |
- Box_Min_Y=Maze.Boxs[Counter].Y1-1; |
- Box_Max_Y=Maze.Boxs[Counter].Y2+1; |
- Radius=Mouse[NMouse].Radius; |
- if(Mouse[NMouse].Y<(Box_Min_Y-Radius)) |
- continue; |
- if(Mouse[NMouse].Y>(Box_Max_Y+Radius)) |
- continue; |
- if(Mouse[NMouse].X<(Box_Min_X-Radius)) |
- continue; |
- if(Mouse[NMouse].X>(Box_Max_X+Radius)) |
- continue; |
- if((Mouse[NMouse].X>=Box_Min_X) && (Mouse[NMouse].X<=Box_Max_X)) |
- if((Mouse[NMouse].Y>=(Box_Min_Y-Radius)) |
- && (Mouse[NMouse].Y<=(Box_Max_Y+Radius))) |
- Colision++; |
- if((Mouse[NMouse].Y>=Box_Min_Y) && (Mouse[NMouse].Y<=Box_Max_Y)) |
- if((Mouse[NMouse].X>=(Box_Min_X-Radius)) |
- && (Mouse[NMouse].X<=(Box_Max_X+Radius))) |
- Colision++; |
- Radius=sqr(Radius); |
- deltaX=sqr(Mouse[NMouse].X-Box_Min_X); |
- deltaY=sqr(Mouse[NMouse].Y-Box_Min_Y); |
- if(deltaX+deltaY<=Radius) |
- Colision++; |
- deltaY=sqr(Mouse[NMouse].Y-Box_Max_Y); |
- if(deltaX+deltaY<=Radius) |
- Colision++; |
- deltaX=sqr(Mouse[NMouse].X-Box_Max_X); |
- deltaY=sqr(Mouse[NMouse].Y-Box_Min_Y); |
- if(deltaX+deltaY<=Radius) |
- Colision++; |
- deltaY=sqr(Mouse[NMouse].Y-Box_Max_Y); |
- if(deltaX+deltaY<=Radius) |
- Colision++; |
- } |
- if (Mouse[NMouse].PColision && !Colision) |
- Mouse[NMouse].NColision++; |
- |
- Mouse[NMouse].PColision=Colision; |
- } |
- task_endcycle(); |
- } |
- return (void *)0; |
-} |
- |
-TASK Calculate_Position(int NMouse) |
-{ |
- float w, v, dt; |
- int b; |
- while(1) |
- { |
- b=(Mouse[NMouse].Motors[MOTOR_LEFT].Radius- |
- Mouse[NMouse].Motors[MOTOR_RIGHT].Radius); |
- if (b<0) |
- b=-b; |
- w=(Mouse[NMouse].Motors[MOTOR_LEFT].Old_V- |
- Mouse[NMouse].Motors[MOTOR_RIGHT].Old_V); |
- w/=(float)b; |
- v=(Mouse[NMouse].Motors[MOTOR_LEFT].Old_V+ |
- Mouse[NMouse].Motors[MOTOR_RIGHT].Old_V); |
- v/=2.0; |
- dt=CALC_PERIOD/1000000.0; |
- Mouse[NMouse].Dir += (180.0*w/PI)*dt; |
- if (Mouse[NMouse].Dir >= 360) |
- Mouse[NMouse].Dir -= 360; |
- if (Mouse[NMouse].Dir < 0) |
- Mouse[NMouse].Dir += 360; |
- v *= dt/65536.0; |
- b=(float)Seno[(int)Mouse[NMouse].Dir+90]; |
- Mouse[NMouse].X += v*b; |
- b=(float)Seno[(int)Mouse[NMouse].Dir]; |
- Mouse[NMouse].Y += v*b; |
- Mouse[NMouse].Motors[0].Old_V= |
- (0.8187*Mouse[NMouse].Motors[0].Old_V+ |
- 0.1813*(float)Mouse[NMouse].Motors[0].V); |
- Mouse[NMouse].Motors[1].Old_V= |
- (0.8187*Mouse[NMouse].Motors[1].Old_V+ |
- 0.1813*(float)Mouse[NMouse].Motors[1].V); |
- task_endcycle(); |
- } |
-} |
- |
-#define SENSOR_LEFT 0 |
-#define SENSOR_FRONT 1 |
-#define SENSOR_RIGTH 2 |
-#define SENSOR_GROUND 3 |
-#define SENSOR_B_LEFT 4 |
-#define SENSOR_B_RIGHT 5 |
-#define MAX_SPEED 50 |
-#define DIST_DIR GetSensor(NMouse, SENSOR_RIGTH) |
-#define DIST_ESQ GetSensor(NMouse, SENSOR_LEFT) |
-#define DIST_FRENTE GetSensor(NMouse, SENSOR_FRONT) |
-#define FAROL_ESQ GetSensor(NMouse, SENSOR_B_LEFT) |
-#define FAROL_DIR GetSensor(NMouse, SENSOR_B_RIGHT) |
-#define FAROL_LIM_INF SENSOR_MIN_BEACON+5 |
- |
-#define DIST0 88 //Distancia minima optima |
-#define DIST1 DIST0 + 5 // 60% |
-#define DIST2 DIST1 + 10 // PARADO |
-#define DIST3 DIST2 + 10 // TRAS |
- |
-#define DISTMAX 120 |
-#define NENHUM 0 |
-#define ESQUERDA 1 |
-#define DIREITA 2 |
-#define contorno ContornoArr[NMouse] |
- |
-TASK MouseTask(int NMouse) |
-{ |
- int i; |
- //char str[100]; |
- unsigned char flag; |
- static unsigned char ContornoArr[MAX_MOUSES]; |
- signed char modulo; |
- |
- Init_Sensor(NMouse, SENSOR_LEFT, OBSTACLE, 14, -45, -45, 25, 15); // Left |
- Init_Sensor(NMouse, SENSOR_FRONT, OBSTACLE, 14, 0, 0, 25, 15); // Center |
- Init_Sensor(NMouse, SENSOR_RIGTH, OBSTACLE, 14, 45, 45, 25, 15); // Rigth |
- Init_Sensor(NMouse, SENSOR_GROUND, GROUND, 10, 180, 180, 0, 20); // Ground |
- Init_Sensor(NMouse, SENSOR_B_LEFT, BEACON, 4, -45, -25, 30, 0); // Left |
- Init_Sensor(NMouse, SENSOR_B_RIGHT, BEACON, 4, 45, 25, 30, 0); // Rigth |
- contorno = NENHUM; |
- Mouse[NMouse].Flag=1; |
- |
- while(1) |
- { |
- for(i=0; i<8; i++) |
- Read_Sensor(NMouse, i); |
- Set_Motor_Vel(NMouse, MOTOR_RIGHT, MAX_SPEED); |
- Set_Motor_Vel(NMouse, MOTOR_LEFT, MAX_SPEED); |
- |
- flag = ((DIST_DIR>DIST3) && contorno==ESQUERDA) || |
- ((DIST_ESQ>DIST3) && contorno==DIREITA); |
- |
- if ( (DIST_FRENTE>DISTMAX) || flag) { |
- Set_Motor_Vel(NMouse, MOTOR_RIGHT, MAX_SPEED/2); |
- Set_Motor_Vel(NMouse, MOTOR_LEFT, MAX_SPEED/2); |
- if (contorno == ESQUERDA) |
- Set_Motor_Vel(NMouse, MOTOR_RIGHT, -MAX_SPEED/2); |
- else |
- Set_Motor_Vel(NMouse, MOTOR_LEFT, -MAX_SPEED/2); |
- } |
- else { |
- |
- // ---------------- Contorno da Esquerda --------------- |
- if (contorno!=DIREITA){ |
- if (DIST_ESQ>DIST1) { // Sensor da esquerda |
- contorno = ESQUERDA; |
- if (DIST_ESQ>DIST3) { |
- Set_Motor_Vel(NMouse, MOTOR_RIGHT, -MAX_SPEED/2); |
- Set_Motor_Vel(NMouse, MOTOR_LEFT, MAX_SPEED/2); |
- } |
- else |
- if (DIST_ESQ>DIST2) |
- Set_Motor_Vel(NMouse, MOTOR_RIGHT, 10); |
- else |
- Set_Motor_Vel(NMouse, MOTOR_RIGHT, MAX_SPEED*3/4); |
- } |
- else |
- if (contorno== ESQUERDA) { |
- if(DIST_ESQ<DIST0) |
- Set_Motor_Vel(NMouse, MOTOR_LEFT, MAX_SPEED*3/10); |
- } |
- } |
- |
- // ---------------- Contorno da Direita --------------- |
- if (contorno!=ESQUERDA){ |
- if (DIST_DIR>DIST1) { // Sensor da direita |
- contorno = DIREITA; |
- if (DIST_DIR>DIST3) { |
- Set_Motor_Vel(NMouse, MOTOR_RIGHT, MAX_SPEED/2); |
- Set_Motor_Vel(NMouse, MOTOR_LEFT, -MAX_SPEED/2); |
- } |
- else |
- if (DIST_DIR>DIST2) |
- Set_Motor_Vel(NMouse, MOTOR_LEFT, 10); |
- else |
- Set_Motor_Vel(NMouse, MOTOR_LEFT, MAX_SPEED*3/4); |
- } |
- else |
- if (contorno== DIREITA) { |
- if (DIST_DIR<DIST0) |
- Set_Motor_Vel(NMouse, MOTOR_RIGHT, MAX_SPEED*3/10); |
- } |
- } |
- |
- // --------------- Desempancar contornos com o farol ------------ |
- |
- if ((contorno == ESQUERDA && FAROL_DIR > FAROL_ESQ && FAROL_DIR > FAROL_LIM_INF) || |
- (contorno == DIREITA && FAROL_ESQ > FAROL_DIR && FAROL_ESQ > FAROL_LIM_INF) ) |
- contorno = NENHUM; |
- |
- |
- |
- if (contorno == NENHUM) |
- { |
- modulo = FAROL_DIR - FAROL_ESQ; |
- if (modulo < 0 ) |
- modulo = - modulo; |
- |
- // Se nao estiver na direçao certa, ajustar |
- if (modulo > 10) { |
- if (FAROL_DIR > FAROL_ESQ) |
- Set_Motor_Vel(NMouse, MOTOR_RIGHT, 0); |
- else |
- Set_Motor_Vel(NMouse, MOTOR_LEFT, 0); |
- } |
- else //velocidade controlada |
- if (modulo > 2) { |
- if (FAROL_DIR > FAROL_ESQ) |
- Set_Motor_Vel(NMouse, MOTOR_RIGHT, MAX_SPEED*6/10); |
- else |
- Set_Motor_Vel(NMouse, MOTOR_LEFT, MAX_SPEED*6/10); |
- } |
- } |
- } |
- if (GetSensor(NMouse, SENSOR_GROUND)==SENSOR_MAX_GROUND) |
- { |
- Set_Motor_Vel(NMouse, MOTOR_RIGHT, 0); |
- Set_Motor_Vel(NMouse, MOTOR_LEFT, 0); |
- } |
- |
- task_endcycle(); |
- } |
- return (void *)0; |
-} |
- |
-void my_end(void *arg) |
-{ |
- grx_close(); |
-} |
- |
-/* --------------------------------- Main program -----------------------------*/ |
- |
-int main(int argc, char *argv[]) |
-{ |
- int i; |
- char c; |
- int pid; |
- |
- HARD_TASK_MODEL mp; |
- SOFT_TASK_MODEL ms; |
- |
- // char StrAux[15]; |
- |
- for (i=0; i<NMouses; i++) |
- Mouse[i].Flag=0; |
- for (i=0; i<(360+90); i++) // Inicializar a tabela de senos |
- Seno[i]=(int)(65536.0*sin((float)i/180.0*PI)); |
- |
- for (i=0; i<180; i++) // Inicializar a tabela de tangente |
- if (i!=90) |
- Tang[i]=(int)(((float)Seno[i]/(float)Seno[i+90])*65536.0); |
- else |
- Tang[i]=INT_MAX; |
- |
- // Definir funÆo de saida |
- sys_atrunlevel(my_end, (void *)NULL, RUNLEVEL_BEFORE_EXIT); |
- |
- hard_task_default_model(mp); |
- hard_task_def_usemath(mp); |
- hard_task_def_group(mp, MOUSEGROUP); |
- hard_task_def_wcet(mp, 1); // wcet ignored by the configuration file! |
- |
- soft_task_default_model(ms); |
- soft_task_def_group(ms, MOUSEGROUP); |
- soft_task_def_met(ms, 1000); |
- |
- for (i=0;i<NMouses;i++) |
- { |
- hard_task_def_arg(mp, (void *)i); |
- soft_task_def_arg(ms, (void *)i); |
- |
- hard_task_def_mit(mp, MOUSE_PERIOD); |
- pid = task_create("Mouse", MouseTask, &mp, NULL); |
- if (pid == NIL) |
- { |
- perror("Creating Mouse:"); |
- sys_end(); |
- } |
- |
- hard_task_def_mit(mp, CALC_PERIOD); |
- pid = task_create("Calc", Calculate_Position, &mp, NULL); |
- if (pid == NIL) |
- { |
- perror("Creating Calc:"); |
- sys_end(); |
- } |
- |
- soft_task_def_period(ms, REDRAW_MOUSE_PERIOD); |
- pid = task_create("Redraw_Mouse", Redraw_Mouse_Task, &ms, NULL); |
- if (pid == NIL) |
- { |
- perror("Creating Redraw_Moude:"); |
- sys_end(); |
- } |
- } |
- |
- hard_task_def_mit(mp, REFEREE_PERIOD); |
- pid = task_create("Referee1", Referee, &mp, NULL); |
- |
- hard_task_def_mit(mp, REDRAW_MAZE_PERIOD); |
- pid = task_create("Redraw_Maze", Redraw_Maze_Task, &mp, NULL); |
- |
- grx_open(640,480,8); |
- group_activate(MOUSEGROUP); |
- do |
- { |
- c = keyb_getch(BLOCK); |
- } while (c != ESC); |
- |
- task_nopreempt(); |
- sys_end(); |
- return 0; |
-} |
- |
-/* the buffer b is scannedc to search for numbers |
- at the first non-number the function stops */ |
-void geti(char *b, int *pos, int *res) |
-{ |
- // skip first chars |
- while (!isdigit(b[*pos])) |
- (*pos)++; |
- |
- |
- // read the numbers |
- *res = 0; |
- do { |
- *res = (*res * 10) + b[*pos] - '0'; |
- (*pos)++; |
- } while (isdigit(b[*pos])); |
-} |
- |
-void read_cfg_file(int argc, char **argv) |
-{ |
- int i, err, Temp1, Temp2, Temp3, Temp4, Temp5; |
- DOS_FILE *fp; |
- char myfilebuf[1000]; |
- int myfilebuf_length; |
- |
- int pos = 0; |
- |
- if (argc==2) { |
- fp = DOS_fopen(argv[1],"r"); |
- |
- if (fp) { |
- /* read up to 1000 chars */ |
- myfilebuf_length = DOS_fread(&myfilebuf,1,1000,fp); |
- |
- /* check for errors */ |
- err = DOS_error(); |
- |
- cprintf("Read %d bytes...\n", myfilebuf_length); |
- |
- if (err) { |
- cprintf("Error %d reading file...Using default values\n", err); |
- } |
- else |
- { |
- geti(myfilebuf, &pos, &NMouses); // Number of Mouses |
- for (i=0;i<NMouses;i++) { |
- geti(myfilebuf, &pos, &Temp1); // Mouse X coordinate |
- geti(myfilebuf, &pos, &Temp2); // Mouse Y coordinate |
- geti(myfilebuf, &pos, &Temp3); // Mouse radius |
- geti(myfilebuf, &pos, &Temp4); // Mouse orientation |
- Init_Mouse(i, Temp1, Temp2, Temp3, Temp4, 6); |
- } |
- geti(myfilebuf, &pos, &Temp1); // Beacon X coordinate |
- geti(myfilebuf, &pos, &Temp2); // Beacon Y coordinate |
- geti(myfilebuf, &pos, &Temp3); // Beacon intensity |
- geti(myfilebuf, &pos, &i); // Number of boxs |
- Init_Maze(Temp1, Temp2, Temp3, i); |
- for(; i>0; i--) { |
- geti(myfilebuf, &pos, &Temp1); // Box X1 Coordinate |
- geti(myfilebuf, &pos, &Temp2); // Box Y1 Coordinate |
- geti(myfilebuf, &pos, &Temp3); // Box X2 Coordinate |
- geti(myfilebuf, &pos, &Temp4); // Box Y2 Coordinate |
- geti(myfilebuf, &pos, &Temp5); // Type of Box |
- if (Temp5) |
- Init_Box(i-1, Temp1, Temp2, Temp3, Temp4, BOX_BLOCK); |
- else |
- Init_Box(i-1, Temp1, Temp2, Temp3, Temp4, BOX_NON_BLOCK); |
- } |
- DOS_fclose(fp); |
- return; |
- } |
- } |
- else { |
- /* error!! */ |
- err = DOS_error(); |
- /* note that if you call DOS_error() here, it return 0!!! */ |
- cprintf("Error %d opening myfile.txt...Using default values\n", err); |
- } |
- |
- // Default value if no file is passed |
- NMouses=2; |
- Init_Maze(500, 350, 400, 1); |
- Init_Box(0, 200, 200, 300, 250, BOX_NON_BLOCK); |
- Init_Mouse(0, 100, 100, 15, 45, 6); |
- Init_Mouse(1, 100, 150, 15, 90, 6); |
- } |
- else { |
- cprintf("Wrong number of arguments...\n"); |
- l1_exit(0); |
- } |
-} |
Index: rel_0_5/auto/edfact.c |
=================================================================== |
--- rel_0_5/auto/edfact.c (revision 1667) |
+++ rel_0_5/auto/edfact.c (nonexistent) |
@@ -1,565 +0,0 @@ |
-/* |
- * Project: S.Ha.R.K. |
- * |
- * Coordinators: |
- * Giorgio Buttazzo <giorgio@sssup.it> |
- * Paolo Gai <pj@gandalf.sssup.it> |
- * |
- * Authors : |
- * Paolo Gai <pj@gandalf.sssup.it> |
- * (see the web pages for full authors list) |
- * |
- * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
- * |
- * http://www.sssup.it |
- * http://retis.sssup.it |
- * http://shark.sssup.it |
- */ |
- |
-/** |
- ------------ |
- CVS : $Id: edfact.c,v 1.1.1.1 2004-05-24 18:03:39 giacomo Exp $ |
- |
- File: $File$ |
- Revision: $Revision: 1.1.1.1 $ |
- Last update: $Date: 2004-05-24 18:03:39 $ |
- ------------ |
-**/ |
- |
-/* |
- * Copyright (C) 2001 Paolo Gai |
- * |
- * This program is free software; you can redistribute it and/or modify |
- * it under the terms of the GNU General Public License as published by |
- * the Free Software Foundation; either version 2 of the License, or |
- * (at your option) any later version. |
- * |
- * This program is distributed in the hope that it will be useful, |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
- * GNU General Public License for more details. |
- * |
- * You should have received a copy of the GNU General Public License |
- * along with this program; if not, write to the Free Software |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
- * |
- */ |
- |
-#include "edfact.h" |
-#include <ll/stdio.h> |
-#include <ll/string.h> |
-#include <kernel/model.h> |
-#include <kernel/descr.h> |
-#include <kernel/var.h> |
-#include <kernel/func.h> |
- |
-//#define edfact_printf kern_printf |
-#define edfact_printf printk |
- |
-/*+ Status used in the level +*/ |
-#define EDFACT_READY MODULE_STATUS_BASE /*+ - Ready status +*/ |
-#define EDFACT_IDLE MODULE_STATUS_BASE+4 /*+ to wait the deadline +*/ |
- |
-/*+ flags +*/ |
-#define EDFACT_FLAG_NORAISEEXC 2 |
- |
-/*+ the level redefinition for the Earliest Deadline First level +*/ |
-typedef struct { |
- level_des l; /*+ the standard level descriptor +*/ |
- |
- TIME period[MAX_PROC]; /*+ The task periods; the deadlines are |
- stored in the priority field +*/ |
- int deadline_timer[MAX_PROC]; |
- /*+ The task deadline timers +*/ |
- |
- struct timespec deadline_timespec[MAX_PROC]; |
- |
- int dline_miss[MAX_PROC]; /*+ Deadline miss counter +*/ |
- int wcet_miss[MAX_PROC]; /*+ Wcet miss counter +*/ |
- |
- int nact[MAX_PROC]; /*+ Wcet miss counter +*/ |
- |
- int flag[MAX_PROC]; |
- /*+ used to manage the JOB_TASK_MODEL and the |
- periodicity +*/ |
- |
- IQUEUE ready; /*+ the ready queue +*/ |
- |
- int flags; /*+ the init flags... +*/ |
- |
- bandwidth_t U; /*+ the used bandwidth +*/ |
- |
-} EDFACT_level_des; |
- |
- |
-static void EDFACT_timer_deadline(void *par); |
- |
-static void EDFACT_internal_activate(EDFACT_level_des *lev, PID p, |
- struct timespec *t) |
-{ |
- struct timespec *temp; |
- |
- temp = iq_query_timespec(p, &lev->ready); |
- |
- TIMESPEC_ASSIGN(temp,t); |
- ADDUSEC2TIMESPEC(lev->period[p], temp); |
- |
- TIMESPEC_ASSIGN(&lev->deadline_timespec[p], |
- temp); |
- |
- /* Insert task in the correct position */ |
- proc_table[p].status = EDFACT_READY; |
- iq_timespec_insert(p,&lev->ready); |
- |
- /* needed because when there is a wcet miss I disable CONTROL_CAP */ |
- proc_table[p].control |= CONTROL_CAP; |
-} |
- |
-static void EDFACT_timer_deadline(void *par) |
-{ |
- PID p = (PID) par; |
- EDFACT_level_des *lev; |
- |
- lev = (EDFACT_level_des *)level_table[proc_table[p].task_level]; |
- |
- switch (proc_table[p].status) { |
- case EDFACT_IDLE: |
- edfact_printf("I%d",p); |
- |
- EDFACT_internal_activate(lev,p, &lev->deadline_timespec[p]); |
- |
- event_need_reschedule(); |
- break; |
- |
- default: |
- edfact_printf("D%d",p); |
- /* else, a deadline miss occurred!!! */ |
- lev->dline_miss[p]++; |
- |
- /* the task is into another state */ |
- lev->nact[p]++; |
- |
- /* Set the deadline timer */ |
- ADDUSEC2TIMESPEC(lev->period[p], &lev->deadline_timespec[p]); |
- } |
- |
- /* Set the deadline timer */ |
- lev->deadline_timer[p] = kern_event_post(&lev->deadline_timespec[p], |
- EDFACT_timer_deadline, |
- (void *)p); |
- |
-} |
- |
-static void EDFACT_timer_guest_deadline(void *par) |
-{ |
- PID p = (PID) par; |
- |
- edfact_printf("AAARRRGGGHHH!!!"); |
- kern_raise(XDEADLINE_MISS,p); |
-} |
- |
- |
-/* The scheduler only gets the first task in the queue */ |
-static PID EDFACT_public_scheduler(LEVEL l) |
-{ |
- EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]); |
- |
- return iq_query_first(&lev->ready); |
-} |
- |
-/* The on-line guarantee is enabled only if the appropriate flag is set... */ |
-static int EDFACT_public_guarantee(LEVEL l, bandwidth_t *freebandwidth) |
-{ |
- EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]); |
- |
- if (lev->flags & EDFACT_FAILED_GUARANTEE) { |
- *freebandwidth = 0; |
- return 0; |
- } |
- else |
- if (*freebandwidth >= lev->U) { |
- *freebandwidth -= lev->U; |
- return 1; |
- } |
- else |
- return 0; |
- |
-} |
- |
-static int EDFACT_public_create(LEVEL l, PID p, TASK_MODEL *m) |
-{ |
- EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]); |
- |
- HARD_TASK_MODEL *h; |
- |
- if (m->pclass != HARD_PCLASS) return -1; |
- if (m->level != 0 && m->level != l) return -1; |
- h = (HARD_TASK_MODEL *)m; |
- if (!h->wcet || !h->mit || h->periodicity != PERIODIC) return -1; |
- /* now we know that m is a valid model */ |
- |
- lev->period[p] = h->mit; |
- |
- lev->flag[p] = 0; |
- lev->deadline_timer[p] = -1; |
- lev->dline_miss[p] = 0; |
- lev->wcet_miss[p] = 0; |
- lev->nact[p] = 0; |
- |
- /* Enable wcet check */ |
- proc_table[p].avail_time = h->wcet; |
- proc_table[p].wcet = h->wcet; |
- proc_table[p].control |= CONTROL_CAP; |
- |
- /* update the bandwidth... */ |
- if (lev->flags & EDFACT_ENABLE_GUARANTEE) { |
- bandwidth_t b; |
- b = (MAX_BANDWIDTH / h->mit) * h->wcet; |
- |
- /* really update lev->U, checking an overflow... */ |
- if (MAX_BANDWIDTH - lev->U > b) |
- lev->U += b; |
- else |
- /* The task can NOT be guaranteed (U>MAX_BANDWIDTH)... |
- in this case, we don't raise an exception... in fact, after the |
- EDFACT_task_create the task_create will call level_guarantee that return |
- -1... return -1 in EDFACT_task_create isn't correct, because: |
- . generally, the guarantee must be done when also the resources |
- are registered |
- . returning -1 will cause the task_create to return with an errno |
- ETASK_CREATE instead of ENO_GUARANTEE!!! |
- |
- Why I use the flag??? because if the lev->U overflows, if i.e. I set |
- it to MAX_BANDWIDTH, I lose the correct allocated bandwidth... |
- */ |
- lev->flags |= EDFACT_FAILED_GUARANTEE; |
- } |
- |
- return 0; /* OK, also if the task cannot be guaranteed... */ |
-} |
- |
-static void EDFACT_public_detach(LEVEL l, PID p) |
-{ |
- /* the EDFACT level doesn't introduce any dinamic allocated new field. |
- we have only to reset the NO_GUARANTEE FIELD and decrement the allocated |
- bandwidth */ |
- |
- EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]); |
- |
- if (lev->flags & EDFACT_FAILED_GUARANTEE) |
- lev->flags &= ~EDFACT_FAILED_GUARANTEE; |
- else |
- lev->U -= (MAX_BANDWIDTH / lev->period[p]) * proc_table[p].wcet; |
-} |
- |
-static void EDFACT_public_dispatch(LEVEL l, PID p, int nostop) |
-{ |
- EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]); |
- |
- /* the task state is set EXE by the scheduler() |
- we extract the task from the ready queue |
- NB: we can't assume that p is the first task in the queue!!! */ |
- iq_extract(p, &lev->ready); |
-} |
- |
-static void EDFACT_public_epilogue(LEVEL l, PID p) |
-{ |
- EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]); |
- |
- /* check if the wcet is finished... */ |
- if (proc_table[p].avail_time <= 0 && proc_table[p].control&CONTROL_CAP) { |
- /* wcet finished: disable wcet event and count wcet miss */ |
- edfact_printf("W%d",p); |
- proc_table[p].control &= ~CONTROL_CAP; |
- lev->wcet_miss[p]++; |
- } |
- |
- /* the task it returns into the ready queue... */ |
- iq_timespec_insert(p,&lev->ready); |
- proc_table[p].status = EDFACT_READY; |
-} |
- |
-static void EDFACT_public_activate(LEVEL l, PID p) |
-{ |
- EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]); |
- struct timespec t; |
- |
- /* Test if we are trying to activate a non sleeping task */ |
- /* save activation (only if needed... */ |
- if (proc_table[p].status != SLEEP) { |
- /* a periodic task cannot be activated when it is already active */ |
- kern_raise(XACTIVATION,p); |
- return; |
- } |
- |
- kern_gettime(&t); |
- EDFACT_internal_activate(lev,p, &t); |
- |
- /* Set the deadline timer */ |
- lev->deadline_timer[p] = kern_event_post(&lev->deadline_timespec[p], |
- EDFACT_timer_deadline, |
- (void *)p); |
- |
-} |
- |
-static void EDFACT_public_unblock(LEVEL l, PID p) |
-{ |
- EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]); |
- |
- /* Insert task in the coEDFect position */ |
- proc_table[p].status = EDFACT_READY; |
- iq_timespec_insert(p,&lev->ready); |
-} |
- |
-static void EDFACT_public_block(LEVEL l, PID p) |
-{ |
-} |
- |
-static int EDFACT_public_message(LEVEL l, PID p, void *m) |
-{ |
- EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]); |
- struct timespec t; |
- |
- /* we reset the capacity counters... */ |
- proc_table[p].avail_time = proc_table[p].wcet; |
- |
- if (lev->nact[p] > 0) { |
- edfact_printf("E%d",p); |
- |
- /* Pending activation: reactivate the thread!!! */ |
- lev->nact[p]--; |
- |
- /* see also EDFACT_timer_deadline */ |
- kern_gettime(&t); |
- EDFACT_internal_activate(lev,p, &t); |
- |
- /* check if the deadline has already expired */ |
- if (TIMESPEC_A_LT_B(iq_query_timespec(p, &lev->ready), &schedule_time)) { |
- /* count the deadline miss */ |
- lev->dline_miss[p]++; |
- kern_event_delete(lev->deadline_timer[p]); |
- } |
- |
- } |
- else { |
- edfact_printf("e%d",p); |
- |
- /* the task has terminated his job before it consume the wcet. All OK! */ |
- proc_table[p].status = EDFACT_IDLE; |
- |
- /* when the deadline timer fire, it recognize the situation and set |
- correctly all the stuffs (like reactivation, etc... ) */ |
- } |
- |
- jet_update_endcycle(); /* Update the Jet data... */ |
- |
- return 0; |
-} |
- |
-static void EDFACT_public_end(LEVEL l, PID p) |
-{ |
- EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]); |
- |
- edfact_printf("Û%d",p); |
- |
- /* we finally put the task in the ready queue */ |
- proc_table[p].status = FREE; |
- iq_insertfirst(p,&freedesc); |
- /* and free the allocated bandwidth */ |
- lev->U -= (MAX_BANDWIDTH/lev->period[p]) * proc_table[p].wcet; |
- |
- if (lev->deadline_timer[p] != -1) { |
- edfact_printf("²%d",p); |
- kern_event_delete(lev->deadline_timer[p]); |
- } |
-} |
- |
- |
-/* Guest Functions |
- These functions manages a JOB_TASK_MODEL, that is used to put |
- a guest task in the EDFACT ready queue. */ |
- |
-static void EDFACT_private_insert(LEVEL l, PID p, TASK_MODEL *m) |
-{ |
- EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]); |
- |
- JOB_TASK_MODEL *job; |
- |
- if (m->pclass != JOB_PCLASS || (m->level != 0 && m->level != l) ) { |
- kern_raise(XINVALID_TASK, p); |
- return; |
- } |
- |
- job = (JOB_TASK_MODEL *)m; |
- |
- TIMESPEC_ASSIGN(iq_query_timespec(p, &lev->ready), &job->deadline); |
- |
- lev->deadline_timer[p] = -1; |
- lev->dline_miss[p] = 0; |
- lev->wcet_miss[p] = 0; |
- lev->nact[p] = 0; |
- |
- if (job->noraiseexc) |
- lev->flag[p] = EDFACT_FLAG_NORAISEEXC; |
- else { |
- lev->flag[p] = 0; |
- lev->deadline_timer[p] = kern_event_post(iq_query_timespec(p, &lev->ready), |
- EDFACT_timer_guest_deadline, |
- (void *)p); |
- } |
- |
- lev->period[p] = job->period; |
- |
- /* Insert task in the correct position */ |
- iq_timespec_insert(p,&lev->ready); |
- proc_table[p].status = EDFACT_READY; |
- |
- /* there is no bandwidth guarantee at this level, it is performed |
- by the level that inserts guest tasks... */ |
-} |
- |
-static void EDFACT_private_dispatch(LEVEL l, PID p, int nostop) |
-{ |
- EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]); |
- |
- /* the task state is set to EXE by the scheduler() |
- we extract the task from the ready queue |
- NB: we can't assume that p is the first task in the queue!!! */ |
- iq_extract(p, &lev->ready); |
-} |
- |
-static void EDFACT_private_epilogue(LEVEL l, PID p) |
-{ |
- EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]); |
- |
- /* the task has been preempted. it returns into the ready queue... */ |
- iq_timespec_insert(p,&lev->ready); |
- proc_table[p].status = EDFACT_READY; |
-} |
- |
-static void EDFACT_private_extract(LEVEL l, PID p) |
-{ |
- EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]); |
- |
- //kern_printf("EDFACT_guest_end: dline timer %d\n",lev->deadline_timer[p]); |
- if (proc_table[p].status == EDFACT_READY) |
- { |
- iq_extract(p, &lev->ready); |
- //kern_printf("(g_end rdy extr)"); |
- } |
- |
- /* we remove the deadline timer, because the slice is finished */ |
- if (lev->deadline_timer[p] != NIL) { |
-// kern_printf("EDFACT_guest_end: dline timer %d\n",lev->deadline_timer[p]); |
- kern_event_delete(lev->deadline_timer[p]); |
- lev->deadline_timer[p] = NIL; |
- } |
- |
-} |
- |
-/* Registration functions */ |
- |
-/*+ Registration function: |
- int flags the init flags ... see EDFACT.h +*/ |
-LEVEL EDFACT_register_level(int flags) |
-{ |
- LEVEL l; /* the level that we register */ |
- EDFACT_level_des *lev; /* for readableness only */ |
- PID i; /* a counter */ |
- |
- printk("EDFACT_register_level\n"); |
- |
- /* request an entry in the level_table */ |
- l = level_alloc_descriptor(sizeof(EDFACT_level_des)); |
- |
- lev = (EDFACT_level_des *)level_table[l]; |
- |
- printk(" lev=%d\n",(int)lev); |
- |
- /* fill the standard descriptor */ |
- lev->l.private_insert = EDFACT_private_insert; |
- lev->l.private_extract = EDFACT_private_extract; |
- lev->l.private_dispatch = EDFACT_private_dispatch; |
- lev->l.private_epilogue = EDFACT_private_epilogue; |
- |
- lev->l.public_scheduler = EDFACT_public_scheduler; |
- if (flags & EDFACT_ENABLE_GUARANTEE) |
- lev->l.public_guarantee = EDFACT_public_guarantee; |
- else |
- lev->l.public_guarantee = NULL; |
- lev->l.public_create = EDFACT_public_create; |
- lev->l.public_detach = EDFACT_public_detach; |
- lev->l.public_end = EDFACT_public_end; |
- lev->l.public_dispatch = EDFACT_public_dispatch; |
- lev->l.public_epilogue = EDFACT_public_epilogue; |
- lev->l.public_activate = EDFACT_public_activate; |
- lev->l.public_unblock = EDFACT_public_unblock; |
- lev->l.public_block = EDFACT_public_block; |
- lev->l.public_message = EDFACT_public_message; |
- |
- /* fill the EDFACT descriptor part */ |
- for(i=0; i<MAX_PROC; i++) { |
- lev->period[i] = 0; |
- lev->deadline_timer[i] = -1; |
- lev->flag[i] = 0; |
- lev->dline_miss[i] = 0; |
- lev->wcet_miss[i] = 0; |
- lev->nact[i] = 0; |
- } |
- |
- iq_init(&lev->ready,&freedesc, 0); |
- lev->flags = flags & 0x07; |
- lev->U = 0; |
- |
- return l; |
-} |
- |
-bandwidth_t EDFACT_usedbandwidth(LEVEL l) |
-{ |
- EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]); |
- |
- return lev->U; |
-} |
- |
-int EDFACT_get_dline_miss(PID p) |
-{ |
- LEVEL l = proc_table[p].task_level; |
- EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]); |
- |
- return lev->dline_miss[p]; |
-} |
- |
-int EDFACT_get_wcet_miss(PID p) |
-{ |
- LEVEL l = proc_table[p].task_level; |
- EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]); |
- |
- return lev->wcet_miss[p]; |
-} |
- |
-int EDFACT_get_nact(PID p) |
-{ |
- LEVEL l = proc_table[p].task_level; |
- EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]); |
- |
- return lev->nact[p]; |
-} |
- |
-int EDFACT_reset_dline_miss(PID p) |
-{ |
- LEVEL l = proc_table[p].task_level; |
- EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]); |
- |
- lev->dline_miss[p] = 0; |
- return 0; |
-} |
- |
-int EDFACT_reset_wcet_miss(PID p) |
-{ |
- LEVEL l = proc_table[p].task_level; |
- EDFACT_level_des *lev = (EDFACT_level_des *)(level_table[l]); |
- |
- lev->wcet_miss[p] = 0; |
- return 0; |
-} |
- |
Index: rel_0_5/auto/tracks.c |
=================================================================== |
--- rel_0_5/auto/tracks.c (revision 1667) |
+++ rel_0_5/auto/tracks.c (nonexistent) |
@@ -1,111 +0,0 @@ |
-/* |
- * Project: S.Ha.R.K. |
- * |
- * Coordinators: |
- * Giorgio Buttazzo <giorgio@sssup.it> |
- * Paolo Gai <pj@gandalf.sssup.it> |
- * |
- * Authors : |
- * Paolo Gai <pj@gandalf.sssup.it> |
- * Massimiliano Giorgi <massy@gandalf.sssup.it> |
- * Luca Abeni <luca@gandalf.sssup.it> |
- * (see the web pages for full authors list) |
- * |
- * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
- * |
- * http://www.sssup.it |
- * http://retis.sssup.it |
- * http://shark.sssup.it |
- */ |
- |
- |
-/** |
- ------------ |
- CVS : $Id: tracks.c,v 1.1.1.1 2004-05-24 18:03:39 giacomo Exp $ |
- |
- File: $File$ |
- Revision: $Revision: 1.1.1.1 $ |
- Last update: $Date: 2004-05-24 18:03:39 $ |
- ------------ |
-**/ |
- |
-/* |
- * Copyright (C) 2000 Marco Dallera and Marco Fiocca |
- * |
- * This program is free software; you can redistribute it and/or modify |
- * it under the terms of the GNU General Public License as published by |
- * the Free Software Foundation; either version 2 of the License, or |
- * (at your option) any later version. |
- * |
- * This program is distributed in the hope that it will be useful, |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
- * GNU General Public License for more details. |
- * |
- * You should have received a copy of the GNU General Public License |
- * along with this program; if not, write to the Free Software |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
- * |
- */ |
- |
-/* |
- * AUTO |
- * |
- * Another Unuseful Track simulatOr |
- * |
- * Authors: Marco Dallera |
- * Marco Fiocca |
- * |
- */ |
- |
-/* -------------- */ |
-/* Track loader */ |
-/* -------------- */ |
- |
-#include "include/auto.h" |
-#include "include/const.h" |
- |
-track track_list[TRACK_NUMBER]; |
- |
-int track_init() |
-{ |
- track demo1; |
- track demo2; |
- track brazil; |
- track monaco; |
- |
- strcpy(demo1.name, "demo1.raw"); |
- demo1.pole_pos.x = 150; |
- demo1.pole_pos.y = 35; |
- demo1.pole_orient = 0.0; |
- demo1.lap = CLOCK; |
- demo1.selected = 0; |
- |
- strcpy(demo2.name, "demo2.raw"); |
- demo2.pole_pos.x = 150; |
- demo2.pole_pos.y = 30; |
- demo2.pole_orient = 0.0; |
- demo2.lap = CLOCK; |
- demo2.selected = 0; |
- |
- strcpy(brazil.name, "brazil.raw"); |
- brazil.pole_pos.x = 140; |
- brazil.pole_pos.y = 185; |
- brazil.pole_orient = 225.0; |
- brazil.lap = ANTICLOCK; |
- brazil.selected = 0; |
- |
- strcpy(monaco.name, "monaco.raw"); |
- monaco.pole_pos.x = 35; |
- monaco.pole_pos.y = 315; |
- monaco.pole_orient = 85.0; |
- monaco.lap = CLOCK; |
- monaco.selected = 0; |
- |
- track_list[0] = demo1; |
- track_list[1] = demo2; |
- track_list[2] = brazil; |
- track_list[3] = monaco; |
- |
- return 0; |
-} |
Index: rel_0_5/auto/keyb.c |
=================================================================== |
--- rel_0_5/auto/keyb.c (revision 1667) |
+++ rel_0_5/auto/keyb.c (nonexistent) |
@@ -1,105 +0,0 @@ |
-/* |
- * Project: S.Ha.R.K. |
- * |
- * Coordinators: |
- * Giorgio Buttazzo <giorgio@sssup.it> |
- * Paolo Gai <pj@gandalf.sssup.it> |
- * |
- * Authors : |
- * Paolo Gai <pj@gandalf.sssup.it> |
- * Massimiliano Giorgi <massy@gandalf.sssup.it> |
- * Luca Abeni <luca@gandalf.sssup.it> |
- * (see the web pages for full authors list) |
- * |
- * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
- * |
- * http://www.sssup.it |
- * http://retis.sssup.it |
- * http://shark.sssup.it |
- */ |
- |
- |
-/** |
- ------------ |
- CVS : $Id: keyb.c,v 1.1.1.1 2004-05-24 18:03:39 giacomo Exp $ |
- |
- File: $File$ |
- Revision: $Revision: 1.1.1.1 $ |
- Last update: $Date: 2004-05-24 18:03:39 $ |
- ------------ |
-**/ |
- |
-/* |
- * Copyright (C) 2000 Marco Dallera and Marco Fiocca |
- * |
- * This program is free software; you can redistribute it and/or modify |
- * it under the terms of the GNU General Public License as published by |
- * the Free Software Foundation; either version 2 of the License, or |
- * (at your option) any later version. |
- * |
- * This program is distributed in the hope that it will be useful, |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
- * GNU General Public License for more details. |
- * |
- * You should have received a copy of the GNU General Public License |
- * along with this program; if not, write to the Free Software |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
- * |
- */ |
- |
-/* |
- * AUTO |
- * |
- * Another Unuseful Track simulatOr |
- * |
- * Authors: Marco Dallera |
- * Marco Fiocca |
- * |
- */ |
- |
-/* ------------------ */ |
-/* Keyboard handler */ |
-/* ------------------ */ |
- |
-#include "include/auto.h" |
-#include "include/const.h" |
- |
- |
-void keyb_handler() { |
- KEY_EVT k; |
- keyb_set_map(itaMap); |
- |
- /* Exit keys: ENTER */ |
- k.flag = 0; |
- k.scan = KEY_ENT; |
- k.ascii = 13; |
- keyb_hook(k, endfun); |
- |
- /* Creates a new HARD car */ |
- k.flag = 0; |
- k.scan = KEY_H; |
- k.ascii = 'h'; |
- keyb_hook(k, hard_car_create); |
- |
- /* Creates a new SOFT car */ |
- k.flag = 0; |
- k.scan = KEY_S; |
- k.ascii = 's'; |
- keyb_hook(k, soft_car_create); |
-} |
- |
- |
-void endfun(KEY_EVT *k) |
-{ |
- grx_close(); |
- cprintf("Ctrl-Brk pressed! Ending...\n"); |
- sys_end(); |
-} |
- |
- |
-void my_close(void *arg) |
-{ |
- kern_printf("my_close\n"); |
-} |
- |
Index: rel_0_5/auto/edfact.h |
=================================================================== |
--- rel_0_5/auto/edfact.h (revision 1667) |
+++ rel_0_5/auto/edfact.h (nonexistent) |
@@ -1,152 +0,0 @@ |
-/* |
- * Project: S.Ha.R.K. |
- * |
- * Coordinators: |
- * Giorgio Buttazzo <giorgio@sssup.it> |
- * Paolo Gai <pj@gandalf.sssup.it> |
- * |
- * Authors : |
- * Paolo Gai <pj@gandalf.sssup.it> |
- * Massimiliano Giorgi <massy@gandalf.sssup.it> |
- * Luca Abeni <luca@gandalf.sssup.it> |
- * (see the web pages for full authors list) |
- * |
- * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
- * |
- * http://www.sssup.it |
- * http://retis.sssup.it |
- * http://shark.sssup.it |
- */ |
- |
-/** |
- ------------ |
- CVS : $Id: edfact.h,v 1.1.1.1 2004-05-24 18:03:39 giacomo Exp $ |
- |
- File: $File$ |
- Revision: $Revision: 1.1.1.1 $ |
- Last update: $Date: 2004-05-24 18:03:39 $ |
- ------------ |
- |
- This file contains the server EDFACT (EDF with pending activations) |
- |
- Title: |
- EDFACT |
- |
- Task Models Accepted: |
- HARD_TASK_MODEL - Hard Tasks (only Periodic) |
- wcet field and mit field must be != 0. They are used to set the wcet |
- and period of the tasks. |
- periodicity field can be only PERIODIC |
- drel field is ignored |
- |
- Guest Models Accepted: |
- JOB_TASK_MODEL - a single guest task activation |
- Identified by an absolute deadline and a period. |
- period field is ignored |
- |
- Description: |
- This module schedule his tasks following the classic EDF scheme. |
- The task guarantee is based on the factor utilization approach. |
- The tasks scheduled are only periodic. |
- All the task are put in a queue and the scheduling is based on the |
- deadline value. |
- NO GUARANTEE is performed on guest tasks. The guarantee must be performed |
- by the level that inserts guest tasks in the EDF level. |
- If a task miss a deadline a counter is incremented. |
- If a task exausts the wcet a counter is incremented |
- No ZOMBIE support!!!!!! |
- |
- Exceptions raised: |
- XUNVALID_GUEST XUNVALID_TASK |
- some primitives are not implemented: |
- task_sleep, task_delay, guest_endcycle, guest_sleep, guest_delay |
- |
- XACTIVATION |
- If a task is actiated through task_activate or guest_activate more than |
- one time |
- |
- Restrictions & special features: |
- - This level doesn't manage the main task. |
- - At init time we have to specify: |
- . guarantee check |
- (when all task are created the system will check that the task_set |
- will not use more than the available bandwidth) |
- - A function to return the used bandwidth of the level is provided. |
- - Functions to return and reset the nact, wcet and dline miss counters |
- |
-**/ |
- |
-/* |
- * Copyright (C) 2001 Paolo Gai |
- * |
- * This program is free software; you can redistribute it and/or modify |
- * it under the terms of the GNU General Public License as published by |
- * the Free Software Foundation; either version 2 of the License, or |
- * (at your option) any later version. |
- * |
- * This program is distributed in the hope that it will be useful, |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
- * GNU General Public License for more details. |
- * |
- * You should have received a copy of the GNU General Public License |
- * along with this program; if not, write to the Free Software |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
- * |
- */ |
- |
- |
-#ifndef __EDFACT_H__ |
-#define __EDFACT_H__ |
- |
-#include <ll/ll.h> |
-#include <kernel/config.h> |
-#include <sys/types.h> |
-#include <kernel/types.h> |
- |
- |
- |
- |
- |
- |
- |
- |
-/*+ flags... +*/ |
-#define EDFACT_ENABLE_GUARANTEE 1 /*+ Task Guarantee enabled +*/ |
-#define EDFACT_ENABLE_ALL 1 |
- |
-#define EDFACT_FAILED_GUARANTEE 8 /*+ used in the module, unsettabl |
- in EDF_register_level... +*/ |
- |
- |
- |
- |
- |
-#define ELASTIC_HARD_PCLASS 0x0600 |
- |
-#define EDFACT_LEVELNAME "EDFACT base" |
-#define EDFACT_LEVEL_CODE 166 |
-#define EDFACT_LEVEL_VERSION 1 |
- |
- |
-/*+ Registration function: |
- int flags Options to be used in this level instance... |
- |
- returns the level number at which the module has been registered. |
-+*/ |
-LEVEL EDFACT_register_level(int flags); |
- |
-/*+ Returns the used bandwidth of a level +*/ |
-bandwidth_t EDFACT_usedbandwidth(LEVEL l); |
- |
-/*+ returns respectively the number of dline, wcet or nact; -1 if error +*/ |
-int EDFACT_get_dline_miss(PID p); |
-int EDFACT_get_wcet_miss(PID p); |
-int EDFACT_get_nact(PID p); |
- |
-/*+ resets respectively the number of dline, wcet miss; -1 if error +*/ |
-int EDFACT_reset_dline_miss(PID p); |
-int EDFACT_reset_wcet_miss(PID p); |
- |
-#endif |
- |
Index: rel_0_5/auto/info.c |
=================================================================== |
--- rel_0_5/auto/info.c (revision 1667) |
+++ rel_0_5/auto/info.c (nonexistent) |
@@ -1,154 +0,0 @@ |
-/* |
- * Project: S.Ha.R.K. |
- * |
- * Coordinators: |
- * Giorgio Buttazzo <giorgio@sssup.it> |
- * Paolo Gai <pj@gandalf.sssup.it> |
- * |
- * Authors : |
- * Paolo Gai <pj@gandalf.sssup.it> |
- * Massimiliano Giorgi <massy@gandalf.sssup.it> |
- * Luca Abeni <luca@gandalf.sssup.it> |
- * (see the web pages for full authors list) |
- * |
- * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
- * |
- * http://www.sssup.it |
- * http://retis.sssup.it |
- * http://shark.sssup.it |
- */ |
- |
- |
-/** |
- ------------ |
- CVS : $Id: info.c,v 1.1.1.1 2004-05-24 18:03:39 giacomo Exp $ |
- |
- File: $File$ |
- Revision: $Revision: 1.1.1.1 $ |
- Last update: $Date: 2004-05-24 18:03:39 $ |
- ------------ |
-**/ |
- |
-/* |
- * Copyright (C) 2000 Marco Dallera and Marco Fiocca |
- * |
- * This program is free software; you can redistribute it and/or modify |
- * it under the terms of the GNU General Public License as published by |
- * the Free Software Foundation; either version 2 of the License, or |
- * (at your option) any later version. |
- * |
- * This program is distributed in the hope that it will be useful, |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
- * GNU General Public License for more details. |
- * |
- * You should have received a copy of the GNU General Public License |
- * along with this program; if not, write to the Free Software |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
- * |
- */ |
- |
-/* |
- * AUTO |
- * |
- * Another Unuseful Track simulatOr |
- * |
- * Authors: Marco Dallera |
- * Marco Fiocca |
- * |
- */ |
- |
-/* ------------------- */ |
-/* Information panel */ |
-/* ------------------- */ |
- |
-#include "include/auto.h" |
-#include "include/const.h" |
-#include "include/utils.h" |
- |
-extern sem_t grx_mutex; |
- |
-/* ------------------------------------------------------------------ */ |
- |
-void bar_display(point p1, int width, int height, int border, float var, float max, int color, char *name) |
-{ |
- int background = BLACK; |
- int amp = 0; |
- point p2; |
- |
- p2.x = p1.x + width; |
- p2.y = p1.y + height; |
- |
- sem_wait(&grx_mutex); |
- |
- grx_text(name, p1.x, p1.y + height + 3, color, background); |
- grx_rect(p1.x - 1, p1.y - 1, p2.x + 1, p2.y + 1, border); |
- |
- grx_box(p1.x, p1.y, p2.x, p2.y, BLACK); |
- amp = abs(round( var * (float)(p2.x - p1.x) / max )); |
- grx_box(p1.x, p1.y, p1.x + amp, p2.y, color); |
- |
- sem_post(&grx_mutex); |
-} |
- |
-/* ------------------------------------------------------------------ */ |
- |
-void bidir_bar_display(point p1, int width, int height, int border, float var, float max, int color, char *name) |
-{ |
- int background = BLACK; |
- int amp = 0; |
- point p2; |
- |
- p2.x = p1.x + width; |
- p2.y = p1.y + height; |
- |
- sem_wait(&grx_mutex); |
- |
- grx_text(name, p1.x, p1.y + height + 3, color, background); |
- grx_rect(p1.x - 1, p1.y - 1, p2.x + 1, p2.y + 1, border); |
- |
- grx_box(p1.x, p1.y, p2.x, p2.y, BLACK); |
- amp = round( var * (float)((p2.x - p1.x)/2) / max ); |
- if (amp >= 0) |
- grx_box((p1.x+p2.x)/2, p1.y, ((p1.x+p2.x)/2)+amp, p2.y, color); |
- else |
- grx_box((p1.x+p2.x)/2+amp, p1.y, ((p1.x+p2.x)/2), p2.y, color); |
- grx_line((p1.x+p2.x)/2, p1.y-2, (p1.x+p2.x)/2, p2.y+2, border); |
- |
- sem_post(&grx_mutex); |
-} |
- |
-/* ------------------------------------------------------------------ */ |
- |
-void cmd_display() |
-{ |
- point p1; |
- |
- p1.x = TRACK_X1; |
- p1.y = TRACK_Y2+3; |
- |
- sem_wait(&grx_mutex); |
- grx_rect(p1.x, p1.y, p1.x+CMD_WIDTH, p1.y+CMD_HEIGHT, BLUE); |
- grx_rect(p1.x+1, p1.y+1, p1.x+CMD_WIDTH-1, p1.y+CMD_HEIGHT-1, CYAN); |
- grx_rect(p1.x+2, p1.y+2, p1.x+CMD_WIDTH-2, p1.y+CMD_HEIGHT-2, LIGHTBLUE); |
- grx_text("## Another Unuseful Track simulatOr ##", |
- p1.x+8, p1.y+8, YELLOW, BLACK); |
- grx_text("## -------------------------------- ##", |
- p1.x+8, p1.y+16, YELLOW, BLACK); |
- grx_text("Marco Dallera", p1.x+8, p1.y+24, GREEN, BLACK); |
- grx_text("marchicchio@libero.it", p1.x+120, p1.y+24, GREEN, BLACK); |
- grx_text("Marco Fiocca", p1.x+8, p1.y+32, GREEN, BLACK); |
- grx_text("marqinho@tiscalinet.it", p1.x+120, p1.y+32, GREEN, BLACK); |
- |
- grx_text("Command keys ", p1.x+8, p1.y+48, LIGHTBLUE, BLACK); |
- grx_text("------------------------", p1.x+8, p1.y+56, LIGHTBLUE, BLACK); |
- grx_text("h create a HARD car", p1.x+8, p1.y+64, CYAN, BLACK); |
- grx_text("s create a SOFT car", p1.x+8, p1.y+72, CYAN, BLACK); |
- grx_text("ENTER exit to DOS", p1.x+8, p1.y+80, CYAN, BLACK); |
- |
- sem_post(&grx_mutex); |
- |
-} |
- |
-/* ------------------------------------------------------------------ */ |
- |
Index: rel_0_5/auto/makefile |
=================================================================== |
--- rel_0_5/auto/makefile (revision 1667) |
+++ rel_0_5/auto/makefile (nonexistent) |
@@ -1,22 +0,0 @@ |
-# |
-# Auto Makefile |
-# |
- |
-ifndef BASE |
-BASE=../.. |
-endif |
-include $(BASE)/config/config.mk |
- |
-PROGS= auto auto2 auto3 |
- |
-include $(BASE)/config/example.mk |
- |
-auto: |
- make -f $(SUBMAKE) APP=auto INIT= OTHEROBJS="initfil1.o sensor.o control.o keyb.o info.o utils.o tracks.o jetctrl.o" SHARKOPT="__OLDCHAR__ __GRX__" |
- |
-auto2: |
- make -f $(SUBMAKE) APP=auto INIT= OTHEROBJS="initfil2.o sensor.o control.o keyb.o info.o utils.o tracks.o jetctrl.o" SHARKOPT="__OLDCHAR__ __GRX__" |
- |
-auto3: |
- make -f $(SUBMAKE) APP=auto INIT= OTHEROBJS="initfil3.o sensor.o control.o keyb.o info.o utils.o tracks.o edfact.o jetctrl.o" SHARKOPT="__OLDCHAR__ __GRX__" |
- |
Index: rel_0_5/auto/utils.c |
=================================================================== |
--- rel_0_5/auto/utils.c (revision 1667) |
+++ rel_0_5/auto/utils.c (nonexistent) |
@@ -1,131 +0,0 @@ |
-/* |
- * Project: S.Ha.R.K. |
- * |
- * Coordinators: |
- * Giorgio Buttazzo <giorgio@sssup.it> |
- * Paolo Gai <pj@gandalf.sssup.it> |
- * |
- * Authors : |
- * Paolo Gai <pj@gandalf.sssup.it> |
- * Massimiliano Giorgi <massy@gandalf.sssup.it> |
- * Luca Abeni <luca@gandalf.sssup.it> |
- * (see the web pages for full authors list) |
- * |
- * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
- * |
- * http://www.sssup.it |
- * http://retis.sssup.it |
- * http://shark.sssup.it |
- */ |
- |
- |
-/** |
- ------------ |
- CVS : $Id: utils.c,v 1.1.1.1 2004-05-24 18:03:39 giacomo Exp $ |
- |
- File: $File$ |
- Revision: $Revision: 1.1.1.1 $ |
- Last update: $Date: 2004-05-24 18:03:39 $ |
- ------------ |
-**/ |
- |
-/* |
- * Copyright (C) 2000 Marco Dallera and Marco Fiocca |
- * |
- * This program is free software; you can redistribute it and/or modify |
- * it under the terms of the GNU General Public License as published by |
- * the Free Software Foundation; either version 2 of the License, or |
- * (at your option) any later version. |
- * |
- * This program is distributed in the hope that it will be useful, |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
- * GNU General Public License for more details. |
- * |
- * You should have received a copy of the GNU General Public License |
- * along with this program; if not, write to the Free Software |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
- * |
- */ |
- |
-/* |
- * AUTO |
- * |
- * Another Unuseful Track simulatOr |
- * |
- * Authors: Marco Dallera |
- * Marco Fiocca |
- * |
- */ |
- |
-#include "include/auto.h" |
-#include "include/utils.h" |
-#include <string.h> |
-#include <stdlib.h> |
- |
-float rand_01() |
-{ |
- return (((float)(rand()%20) / 100.0) + 0.8); |
-} |
- |
-int rand_color() |
-{ |
- return (rand()%16); |
-} |
- |
-int round(float value) |
-{ |
- return ((int)(value + 0.5)); |
-} |
- |
-void reverse(char s[]) { |
- int c, i, j; |
- |
- for (i = 0, j = strlen(s)-1; i<j; i++, j--) { |
- c = s[i]; |
- s[i] = s[j]; |
- s[j] = c; |
- } |
-} |
- |
-char * itoa(int n, char *s) { |
- int i, sign; |
- |
- if ((sign = n) < 0) |
- n = -n; |
- i = 0; |
- |
- do { |
- s[i++] = n % 10 + '0'; |
- } while ((n /= 10) > 0); |
- |
- if (sign < 0) |
- s[i++] = '-'; |
- s[i] = 0; |
- |
- reverse(s); |
- |
- return s; |
-} |
- |
-time int2time(int t) |
-{ |
- time ts; |
- |
- ts.dec = t % 10; |
- ts.sec = (t/10) % 60; |
- ts.min = (int)(t / 600); |
- |
- return ts; |
-} |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
Index: rel_0_5/auto/include/const.h |
=================================================================== |
--- rel_0_5/auto/include/const.h (revision 1667) |
+++ rel_0_5/auto/include/const.h (nonexistent) |
@@ -1,141 +0,0 @@ |
-/* |
- * Project: S.Ha.R.K. |
- * |
- * Coordinators: |
- * Giorgio Buttazzo <giorgio@sssup.it> |
- * Paolo Gai <pj@gandalf.sssup.it> |
- * |
- * Authors : |
- * Paolo Gai <pj@gandalf.sssup.it> |
- * Massimiliano Giorgi <massy@gandalf.sssup.it> |
- * Luca Abeni <luca@gandalf.sssup.it> |
- * (see the web pages for full authors list) |
- * |
- * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
- * |
- * http://www.sssup.it |
- * http://retis.sssup.it |
- * http://shark.sssup.it |
- */ |
- |
- |
-/** |
- ------------ |
- CVS : $Id: const.h,v 1.1.1.1 2004-05-24 18:03:39 giacomo Exp $ |
- |
- File: $File$ |
- Revision: $Revision: 1.1.1.1 $ |
- Last update: $Date: 2004-05-24 18:03:39 $ |
- ------------ |
-**/ |
- |
-/* |
- * Copyright (C) 2000 Marco Dallera and Marco Fiocca |
- * |
- * This program is free software; you can redistribute it and/or modify |
- * it under the terms of the GNU General Public License as published by |
- * the Free Software Foundation; either version 2 of the License, or |
- * (at your option) any later version. |
- * |
- * This program is distributed in the hope that it will be useful, |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
- * GNU General Public License for more details. |
- * |
- * You should have received a copy of the GNU General Public License |
- * along with this program; if not, write to the Free Software |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
- * |
- */ |
- |
-/* |
- * AUTO |
- * |
- * Another Unuseful Track simulatOr |
- * |
- * Authors: Marco Dallera |
- * Marco Fiocca |
- * |
- */ |
- |
-/* ------------------ */ |
-/* Useful constants */ |
-/* ------------------ */ |
- |
-#ifndef __CONST_H_ |
- |
-#define __CONST_H_ |
- |
-/* Screen dimensions */ |
-#define SCREEN_WIDTH 800 |
-#define SCREEN_HEIGHT 600 |
-#define SCREEN_BIT_COLORS 8 |
- |
-/* Visible area */ |
-#define TEL_WIDTH 50 |
-#define TEL_HEIGHT 50 |
- |
-/* Car dimensions */ |
-#define CAR_WIDTH 12 |
-#define CAR_HEIGHT 12 |
-#define CAR_W 8 |
-#define CAR_H 10 |
- |
-/* Track dimensions */ |
-#define TRACK_WIDTH 500 |
-#define TRACK_HEIGHT 500 |
- |
-/* Track position */ |
-#define TRACK_X1 0 |
-#define TRACK_Y1 0 |
-#define TRACK_X2 TRACK_X1+TRACK_WIDTH-1 |
-#define TRACK_Y2 TRACK_Y1+TRACK_HEIGHT-1 |
- |
-/* Max number of car on track */ |
-#define MAX_CAR_NUMBER 10 |
-#define DRIVERS_NUMBER 20 |
-#define MAX_DRIVER_NAME_LENGTH 20 |
-#define MAX_TRACK_NAME_LENGTH 20 |
-#define TRACK_NUMBER 4 |
- |
-/* Lap direction */ |
-#define CLOCK 0 |
-#define ANTICLOCK 1 |
- |
-/* Information display coords */ |
-#define CMD_WIDTH TRACK_WIDTH |
-#define CMD_HEIGHT (SCREEN_HEIGHT-TRACK_HEIGHT-3) |
- |
-/* Car position limits */ |
-#define MIN_CAR_X (TRACK_X1 + CAR_WIDTH/2 + 4) |
-#define MIN_CAR_Y (TRACK_Y1 + CAR_HEIGHT/2 + 4) |
-#define MAX_CAR_X (TRACK_X2 - CAR_WIDTH/2 - 4) |
-#define MAX_CAR_Y (TRACK_Y2 - CAR_HEIGHT/2 - 4) |
- |
-/* Road constants */ |
-#define LEFT_ONLY 10 |
-#define RIGHT_ONLY 11 |
-#define ROAD_OK 12 |
-#define NO_ROAD 13 |
- |
-/* Collision constants */ |
-#define COLLISION_LEFT 20 |
-#define COLLISION_RIGHT 21 |
-#define COLLISION_BACK 22 |
-#define NO_COLL 0 |
- |
-/* CAB constants */ |
-#define ROAD_MSG_DIM sizeof(road_info) |
-#define ROAD_MSG_READER 4 |
- |
-#define CAR_MSG_DIM sizeof(car_status) |
-#define CAR_MSG_READER 5 |
- |
-/* Tasks parameters */ |
-#define SENSOR_WCET 3000 |
-#define SENSOR_PERIOD 40000 |
-#define CONTROL_WCET 1000 |
-#define CONTROL_PERIOD 40000 |
- |
-#endif |
- |
Index: rel_0_5/auto/include/auto.h |
=================================================================== |
--- rel_0_5/auto/include/auto.h (revision 1667) |
+++ rel_0_5/auto/include/auto.h (nonexistent) |
@@ -1,188 +0,0 @@ |
-/* |
- * Project: S.Ha.R.K. |
- * |
- * Coordinators: |
- * Giorgio Buttazzo <giorgio@sssup.it> |
- * Paolo Gai <pj@gandalf.sssup.it> |
- * |
- * Authors : |
- * Paolo Gai <pj@gandalf.sssup.it> |
- * Massimiliano Giorgi <massy@gandalf.sssup.it> |
- * Luca Abeni <luca@gandalf.sssup.it> |
- * (see the web pages for full authors list) |
- * |
- * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
- * |
- * http://www.sssup.it |
- * http://retis.sssup.it |
- * http://shark.sssup.it |
- */ |
- |
- |
-/** |
- ------------ |
- CVS : $Id: auto.h,v 1.1.1.1 2004-05-24 18:03:39 giacomo Exp $ |
- |
- File: $File$ |
- Revision: $Revision: 1.1.1.1 $ |
- Last update: $Date: 2004-05-24 18:03:39 $ |
- ------------ |
-**/ |
- |
-/* |
- * Copyright (C) 2000 Marco Dallera and Marco Fiocca |
- * |
- * This program is free software; you can redistribute it and/or modify |
- * it under the terms of the GNU General Public License as published by |
- * the Free Software Foundation; either version 2 of the License, or |
- * (at your option) any later version. |
- * |
- * This program is distributed in the hope that it will be useful, |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
- * GNU General Public License for more details. |
- * |
- * You should have received a copy of the GNU General Public License |
- * along with this program; if not, write to the Free Software |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
- * |
- */ |
- |
-/* |
- * AUTO |
- * |
- * Another Unuseful Track simulatOr |
- * |
- * Authors: Marco Dallera |
- * Marco Fiocca |
- * |
- */ |
- |
-/* ------------------- */ |
-/* Useful structures */ |
-/* ------------------- */ |
- |
-#ifndef __CAR_H_ |
- |
-#define __CAR_H_ |
- |
-#include <modules/cabs.h> |
-#include <kernel/func.h> |
-#include <kernel/model.h> |
-#include <kernel/types.h> |
-#include <drivers/keyb.h> |
-#include <drivers/glib.h> |
-#include <semaphore.h> |
-#include <math.h> |
-#include <stdio.h> |
-#include <stdlib.h> |
-#include <string.h> |
-#include "const.h" |
- |
-#define degree_to_rad(a) ((M_PI/180.0)*(a)) |
-#define rad_to_degree(a) ((180.0/M_PI)*(a)) |
- |
-typedef struct { |
- int x; |
- int y; |
-} point; |
- |
-typedef struct { |
- float x,y; |
-} point_f; |
- |
-typedef struct { |
- float mod; |
- float phase; |
-} vector; |
- |
-typedef struct { |
- point_f pos; |
- float orient; |
-} car_status; |
- |
-typedef struct { |
- int left_border; |
- int right_border; |
- int distance; |
- float curve; |
- point opps_list[MAX_CAR_NUMBER]; |
- int opps_number; |
- int collision; |
- int flag; |
-} road_info; |
- |
-typedef struct { |
- int left,center,right; |
-} road_strip; |
- |
-typedef struct { |
- PID sensor_pid,control_pid; |
- int number; |
- char driver[MAX_DRIVER_NAME_LENGTH]; |
- float max_speed, min_acc, max_acc; |
- float rage; |
- CAB road_status_cab; |
- CAB car_status_cab; |
- int color; |
-} car_params; |
- |
-typedef struct { |
- char name[MAX_TRACK_NAME_LENGTH]; // il nome del file |
- point pole_pos; // la posizione di partenza |
- float pole_orient; // la direzione di partenza |
- int lap; // il senso di marcia: CLOCK, ANTICLOCK |
- int selected; // it's a flag marking the actually selected track |
-} track; |
- |
-typedef struct { |
- int min; |
- int sec; |
- int dec; |
-} time; |
- |
-extern car_params cars[MAX_CAR_NUMBER]; |
-extern char track_img[TRACK_WIDTH*TRACK_HEIGHT]; |
-extern track track_list[TRACK_NUMBER]; |
- |
-/* ---------------------------------------- */ |
-/* Functions definition */ |
-/* ---------------------------------------- */ |
- |
-/* CABs R/W functions */ |
-int set_car_status(car_status, CAB); // sends the new status according to the control law |
-car_status get_car_status(CAB); // reads car status from a CAB |
-int set_road_info(road_info, CAB); // sends the new road informations |
-road_info get_road_info(CAB); // reads road status values from a CAB |
- |
-/* Keyboard functions */ |
-void keyb_handler(); |
-void endfun(KEY_EVT *); |
-void my_close(void *); |
- |
-/* Display functions */ |
-void bar_display(point p1, int width, int height, int border, float var, float max, int color, char *name); |
-void bidir_bar_display(point p1, int width, int height, int border, float var, float max, int color, char *name); |
-void cmd_display(); |
- |
-/* Closing function */ |
-void byebye(); |
-void error_msg(); |
- |
-/* Tasks */ |
-TASK sensor(); // Camera car task |
-TASK control(); // Car controller task |
-TASK manual(); // Manual driving task |
-TASK actuator(); // Graphic drawing task |
-TASK info(); // Car informations display task |
- |
-/* Tasks management */ |
-void hard_car_create(); |
-void soft_car_create(); |
-void killcar(); |
- |
-/* Tracks management */ |
-int track_init(); |
- |
-#endif |
- |
Index: rel_0_5/auto/include/utils.h |
=================================================================== |
--- rel_0_5/auto/include/utils.h (revision 1667) |
+++ rel_0_5/auto/include/utils.h (nonexistent) |
@@ -1,76 +0,0 @@ |
-/* |
- * Project: S.Ha.R.K. |
- * |
- * Coordinators: |
- * Giorgio Buttazzo <giorgio@sssup.it> |
- * Paolo Gai <pj@gandalf.sssup.it> |
- * |
- * Authors : |
- * Paolo Gai <pj@gandalf.sssup.it> |
- * Massimiliano Giorgi <massy@gandalf.sssup.it> |
- * Luca Abeni <luca@gandalf.sssup.it> |
- * (see the web pages for full authors list) |
- * |
- * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
- * |
- * http://www.sssup.it |
- * http://retis.sssup.it |
- * http://shark.sssup.it |
- */ |
- |
- |
-/** |
- ------------ |
- CVS : $Id: utils.h,v 1.1.1.1 2004-05-24 18:03:39 giacomo Exp $ |
- |
- File: $File$ |
- Revision: $Revision: 1.1.1.1 $ |
- Last update: $Date: 2004-05-24 18:03:39 $ |
- ------------ |
-**/ |
- |
-/* |
- * Copyright (C) 2000 Marco Dallera and Marco Fiocca |
- * |
- * This program is free software; you can redistribute it and/or modify |
- * it under the terms of the GNU General Public License as published by |
- * the Free Software Foundation; either version 2 of the License, or |
- * (at your option) any later version. |
- * |
- * This program is distributed in the hope that it will be useful, |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
- * GNU General Public License for more details. |
- * |
- * You should have received a copy of the GNU General Public License |
- * along with this program; if not, write to the Free Software |
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
- * |
- */ |
- |
-/* |
- * AUTO |
- * |
- * Another Unuseful Track simulatOr |
- * |
- * Authors: Marco Dallera |
- * Marco Fiocca |
- * |
- */ |
- |
-/* ------------------ */ |
-/* Useful functions */ |
-/* ------------------ */ |
- |
-#ifndef __UTILS_H_ |
- |
-#define __UTILS_H_ |
- |
-float rand_01(); |
-int rand_color(); |
-int round(float value); |
-char * itoa(int n, char *s); |
-void reverse(char s[]); |
-time int2time(int t); |
- |
-#endif |
Index: rel_0_5/auto/tracks/monaco.raw |
=================================================================== |
--- rel_0_5/auto/tracks/monaco.raw (revision 1667) |
+++ rel_0_5/auto/tracks/monaco.raw (nonexistent) |
@@ -1 +0,0 @@ |
- |
\ No newline at end of file |
Index: rel_0_5/auto/tracks/brazil.raw |
=================================================================== |
--- rel_0_5/auto/tracks/brazil.raw (revision 1667) |
+++ rel_0_5/auto/tracks/brazil.raw (nonexistent) |
@@ -1,2 +0,0 @@ |
-
- ! " |
---|