Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1284 | giacomo | 1 | |
2 | /* |
||
3 | * Project: S.Ha.R.K. |
||
4 | * |
||
5 | * Coordinators: Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * |
||
7 | * Authors : Paolo Gai <pj@hartik.sssup.it> |
||
8 | * (see authors.txt for full list of hartik's authors) |
||
9 | * |
||
10 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
11 | * |
||
12 | * http://www.sssup.it |
||
13 | * http://retis.sssup.it |
||
14 | * http://shark.sssup.it |
||
15 | */ |
||
16 | |||
17 | /* |
||
18 | * Copyright (C) 2000 Paolo Gai |
||
19 | * |
||
20 | * This program is free software; you can redistribute it and/or modify |
||
21 | * it under the terms of the GNU General Public License as published by |
||
22 | * the Free Software Foundation; either version 2 of the License, or |
||
23 | * (at your option) any later version. |
||
24 | * |
||
25 | * This program is distributed in the hope that it will be useful, |
||
26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
28 | * GNU General Public License for more details. |
||
29 | * |
||
30 | * You should have received a copy of the GNU General Public License |
||
31 | * along with this program; if not, write to the Free Software |
||
32 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
33 | * |
||
34 | */ |
||
35 | |||
36 | #include "servo.h" |
||
37 | #include <kernel/kern.h> |
||
38 | #include <drivers/scom.h> |
||
39 | #include <drivers/keyb.h> |
||
40 | |||
41 | /* COM Port Constants */ |
||
42 | #define COM_PORT COM2 |
||
43 | #define COM_SPEED 115200 |
||
44 | #define COM_PARITY NONE |
||
45 | #define COM_LEN 8 |
||
46 | #define COM_STOP 1 |
||
47 | |||
48 | /* Real Servo Value */ |
||
49 | #define TICK_ZERO 1600 |
||
50 | #define TICK_ANG (1800/180.0) |
||
51 | #define TICK_LEN 1.6 |
||
52 | #define TICK_AL ((float) TICK_ANG / TICK_LEN) |
||
53 | |||
54 | int init_serial() |
||
55 | { |
||
56 | int err=0; |
||
57 | err = servo_open(COM_PORT, COM_SPEED); |
||
58 | //if (com_open(COM_PORT, COM_SPEED, COM_PARITY, COM_LEN, COM_STOP)==-1) err = 1; |
||
59 | |||
60 | return err; |
||
61 | } |
||
62 | |||
63 | void end_serial() |
||
64 | { |
||
65 | servo_close(COM_PORT); |
||
66 | //com_close(COM_PORT); |
||
67 | } |
||
68 | |||
69 | TASK pic_generator() |
||
70 | { |
||
71 | int angle = -90; |
||
72 | int n_tick; |
||
73 | unsigned char buf, ech; |
||
74 | |||
75 | while (1) { |
||
76 | |||
77 | if (angle>90) angle = -90; |
||
78 | |||
79 | servo_set_angle_sec(COM2, 0,ANGLE2SEC(angle,0,0)); |
||
80 | |||
81 | /*n_tick = TICK_AL * (signed char)angle; |
||
82 | com_send(COM_PORT, 0); |
||
83 | ech = com_receive(COM_PORT); |
||
84 | |||
85 | buf = n_tick / 256; |
||
86 | com_send(COM_PORT, buf); |
||
87 | ech = com_receive(COM_PORT); |
||
88 | |||
89 | buf = n_tick % 256; |
||
90 | com_send(COM_PORT, buf); |
||
91 | ech = com_receive(COM_PORT);*/ |
||
92 | |||
93 | |||
94 | angle += 5; |
||
95 | |||
96 | task_endcycle(); |
||
97 | } |
||
98 | return 0; |
||
99 | } |
||
100 | |||
101 | |||
102 | void endfun(KEY_EVT *k) |
||
103 | { |
||
104 | cprintf("Ctrl-Brk pressed! Ending...\n"); |
||
105 | sys_end(); |
||
106 | } |
||
107 | |||
108 | void my_close(void *arg) |
||
109 | { |
||
110 | int i; |
||
111 | TIME tmp; |
||
112 | |||
113 | for (i=3; i<MAX_PROC; i++){ |
||
114 | if (!jet_getstat(i, NULL, &tmp, NULL, NULL)) |
||
115 | kern_printf("Task Name : %s - Max Time : %d\n", proc_table[i].name, (int)tmp); |
||
116 | } |
||
117 | |||
118 | end_serial(); |
||
119 | } |
||
120 | |||
121 | int main(int argc, char **argv) |
||
122 | { |
||
123 | KEY_EVT k; |
||
124 | TIME seme; |
||
125 | SOFT_TASK_MODEL mp; |
||
126 | PID pid; |
||
127 | |||
128 | k.flag = CNTR_BIT; |
||
129 | k.scan = KEY_C; |
||
130 | k.ascii = 'c'; |
||
131 | keyb_hook(k,endfun); |
||
132 | |||
133 | k.flag = CNTL_BIT; |
||
134 | k.scan = KEY_C; |
||
135 | k.ascii = 'c'; |
||
136 | keyb_hook(k,endfun); |
||
137 | |||
138 | seme = sys_gettime(NULL); |
||
139 | srand(seme); |
||
140 | |||
141 | sys_atrunlevel(my_close, NULL, RUNLEVEL_BEFORE_EXIT); |
||
142 | |||
143 | if (init_serial()) { |
||
144 | perror("Could not initialize serial port."); |
||
145 | sys_end(); |
||
146 | } |
||
147 | |||
148 | soft_task_default_model(mp); |
||
149 | soft_task_def_level(mp,1); |
||
150 | soft_task_def_ctrl_jet(mp); |
||
151 | soft_task_def_met(mp,700); |
||
152 | soft_task_def_period(mp,10000); |
||
153 | //soft_task_def_aperiodic(mp); |
||
154 | soft_task_def_usemath(mp); |
||
155 | pid = task_create("PIC_Generator", pic_generator, &mp, NULL); |
||
156 | if (pid == NIL) { |
||
157 | perror("Could not create task <Joystick>"); |
||
158 | sys_end(); |
||
159 | } else |
||
160 | task_activate(pid); |
||
161 | |||
162 | return 0; |
||
163 | } |