|
@@ -1,494 +0,0 @@
|
1
|
|
-/*
|
2
|
|
- * Copyright (C) 2018 dimercur
|
3
|
|
- *
|
4
|
|
- * This program is free software: you can redistribute it and/or modify
|
5
|
|
- * it under the terms of the GNU General Public License as published by
|
6
|
|
- * the Free Software Foundation, either version 3 of the License, or
|
7
|
|
- * (at your option) any later version.
|
8
|
|
- *
|
9
|
|
- * This program is distributed in the hope that it will be useful,
|
10
|
|
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
|
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
|
- * GNU General Public License for more details.
|
13
|
|
- *
|
14
|
|
- * You should have received a copy of the GNU General Public License
|
15
|
|
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
|
- */
|
17
|
|
-
|
18
|
|
-#include "tasks_pthread.h"
|
19
|
|
-#include <time.h>
|
20
|
|
-
|
21
|
|
-#ifdef __WITH_PTHREAD__
|
22
|
|
-
|
23
|
|
-// Déclaration des priorités des taches
|
24
|
|
-#define PRIORITY_TSERVER 30
|
25
|
|
-#define PRIORITY_TOPENCOMROBOT 20
|
26
|
|
-#define PRIORITY_TMOVE 10
|
27
|
|
-#define PRIORITY_TSENDTOMON 25
|
28
|
|
-#define PRIORITY_TRECEIVEFROMMON 22
|
29
|
|
-#define PRIORITY_TSTARTROBOT 20
|
30
|
|
-
|
31
|
|
-/*
|
32
|
|
- * Some remarks:
|
33
|
|
- * 1- This program is mostly a template. It shows you how to create tasks, semaphore
|
34
|
|
- * message queues, mutex ... and how to use them
|
35
|
|
- *
|
36
|
|
- * 2- semDumber is, as name say, useless. Its goal is only to show you how to use semaphore
|
37
|
|
- *
|
38
|
|
- * 3- Data flow is probably not optimal
|
39
|
|
- *
|
40
|
|
- * 4- Take into account that ComRobot::Write will block your task when serial buffer is full,
|
41
|
|
- * time for internal buffer to flush
|
42
|
|
- *
|
43
|
|
- * 5- Same behavior existe for ComMonitor::Write !
|
44
|
|
- *
|
45
|
|
- * 6- When you want to write something in terminal, use cout and terminate with endl and flush
|
46
|
|
- *
|
47
|
|
- * 7- Good luck !
|
48
|
|
- */
|
49
|
|
-
|
50
|
|
-void Tasks::Init() {
|
51
|
|
- int status;
|
52
|
|
-
|
53
|
|
- /* Open com port with STM32 */
|
54
|
|
- cout << "Open serial com (";
|
55
|
|
- status = robot.Open();
|
56
|
|
- cout << status;
|
57
|
|
- cout << ")" << endl;
|
58
|
|
-
|
59
|
|
- if (status >= 0) {
|
60
|
|
- // Open server
|
61
|
|
-
|
62
|
|
- status = monitor.Open(SERVER_PORT);
|
63
|
|
- cout << "Open server on port " << (SERVER_PORT) << " (" << status << ")" << endl;
|
64
|
|
-
|
65
|
|
- if (status < 0) throw std::runtime_error {
|
66
|
|
- "Unable to start server on port " + std::to_string(SERVER_PORT)
|
67
|
|
- };
|
68
|
|
- } else
|
69
|
|
- throw std::runtime_error {
|
70
|
|
- "Unable to open serial port /dev/ttyS0 "
|
71
|
|
- };
|
72
|
|
-}
|
73
|
|
-
|
74
|
|
-void Tasks::Run() {
|
75
|
|
- threadTimer = new thread((void (*)(void*)) & Tasks::TimerTask, this);
|
76
|
|
- threadServer = new thread((void (*)(void*)) & Tasks::ServerTask, this);
|
77
|
|
-
|
78
|
|
- // threadSendToMon=new thread((void (*)(void*)) &Tasks::SendToMonTask,this);
|
79
|
|
-
|
80
|
|
- //
|
81
|
|
- // Camera camera=Camera(sm);
|
82
|
|
- // cout << "Try opening camera"<<endl<<flush;
|
83
|
|
- // if (camera.Open()) cout<<"Camera opened successfully"<<endl<<flush;
|
84
|
|
- // else cout<<"Failed to open camera"<<endl<<flush;
|
85
|
|
- //
|
86
|
|
- // counter = 0;
|
87
|
|
- // while (1) {
|
88
|
|
- // Img image=camera.Grab();
|
89
|
|
- //
|
90
|
|
- // counter++;
|
91
|
|
- //
|
92
|
|
- // if (flag == true) {
|
93
|
|
- // cout<< "Image info: "<<image.ToString()<<endl<<flush;
|
94
|
|
- // cout << "FPS = "<<to_string(counter)<<endl<<flush;
|
95
|
|
- // flag=false;
|
96
|
|
- // counter=0;
|
97
|
|
- // }
|
98
|
|
- // }
|
99
|
|
-
|
100
|
|
-
|
101
|
|
- // msgSend = ComRobot::Ping();
|
102
|
|
- // cout << "Send => " << msgSend->ToString() << endl << flush;
|
103
|
|
- // msgRcv = robot.SendCommand(msgSend, MESSAGE_ANSWER_ACK, 3);
|
104
|
|
- // cout << "Rcv <= " << msgRcv->ToString() << endl << flush;
|
105
|
|
- //
|
106
|
|
- // delete(msgRcv);
|
107
|
|
- //
|
108
|
|
- // msgSend = ComRobot::StartWithoutWD();
|
109
|
|
- // cout << "Send => " << msgSend->ToString() << endl << flush;
|
110
|
|
- // msgRcv = robot.SendCommand(msgSend, MESSAGE_ANSWER_ACK, 3);
|
111
|
|
- // cout << "Rcv <= " << msgRcv->ToString() << endl << flush;
|
112
|
|
- //
|
113
|
|
- // delete(msgRcv);
|
114
|
|
- //
|
115
|
|
- // msgSend = ComRobot::Move(1000);
|
116
|
|
- // cout << "Send => " << msgSend->ToString() << endl << flush;
|
117
|
|
- // msgRcv = robot.SendCommand(msgSend, MESSAGE_ANSWER_ACK, 3);
|
118
|
|
- // cout << "Rcv <= " << msgRcv->ToString() << endl << flush;
|
119
|
|
- //
|
120
|
|
- // delete(msgRcv);
|
121
|
|
- //
|
122
|
|
- // msgSend = ComRobot::GetBattery();
|
123
|
|
- // cout << "Send => " << msgSend->ToString() << endl << flush;
|
124
|
|
- // msgRcv = robot.SendCommand(msgSend, MESSAGE_ROBOT_BATTERY_LEVEL, 3);
|
125
|
|
- // cout << "Rcv <= " << msgRcv->ToString() << endl << flush;
|
126
|
|
- //
|
127
|
|
- // delete(msgRcv);
|
128
|
|
- cout << "Tasks launched" << endl << flush;
|
129
|
|
-}
|
130
|
|
-
|
131
|
|
-void Tasks::Stop() {
|
132
|
|
- monitor.Close();
|
133
|
|
- robot.Close();
|
134
|
|
-}
|
135
|
|
-
|
136
|
|
-void Tasks::ServerTask(void *arg) {
|
137
|
|
- Message *msgRcv;
|
138
|
|
- Message *msgSend;
|
139
|
|
- bool isActive = true;
|
140
|
|
-
|
141
|
|
- cout << "Start " << __PRETTY_FUNCTION__ << endl << flush;
|
142
|
|
-
|
143
|
|
- while (isActive) {
|
144
|
|
- msgRcv = NULL;
|
145
|
|
- msgSend = NULL;
|
146
|
|
-
|
147
|
|
- msgRcv = monitor.Read();
|
148
|
|
- cout << "Rcv <= " << msgRcv->ToString() << endl << flush;
|
149
|
|
-
|
150
|
|
- if (msgRcv->CompareID(MESSAGE_ROBOT_COM_OPEN)) msgSend = new Message(MESSAGE_ANSWER_ACK);
|
151
|
|
- if (msgRcv->CompareID(MESSAGE_ROBOT_COM_CLOSE)) msgSend = new Message(MESSAGE_ANSWER_ACK);
|
152
|
|
-
|
153
|
|
- if (msgRcv->CompareID(MESSAGE_ROBOT_START_WITH_WD)) msgSend = new Message(MESSAGE_ANSWER_ACK);
|
154
|
|
- if (msgRcv->CompareID(MESSAGE_ROBOT_START_WITHOUT_WD)) msgSend = new Message(MESSAGE_ANSWER_ACK);
|
155
|
|
-
|
156
|
|
- if (msgRcv->CompareID(MESSAGE_ROBOT_COM_CLOSE)) isActive = false;
|
157
|
|
-
|
158
|
|
- if (msgRcv->CompareID(MESSAGE_CAM_OPEN)) {
|
159
|
|
- sendImage = true;
|
160
|
|
- msgSend = new Message(MESSAGE_ANSWER_ACK);
|
161
|
|
- }
|
162
|
|
-
|
163
|
|
- if (msgRcv->CompareID(MESSAGE_CAM_CLOSE)) {
|
164
|
|
- sendImage = false;
|
165
|
|
- msgSend = new Message(MESSAGE_ANSWER_ACK);
|
166
|
|
- }
|
167
|
|
-
|
168
|
|
- if (msgRcv->CompareID(MESSAGE_CAM_POSITION_COMPUTE_START)) {
|
169
|
|
- sendPosition = true;
|
170
|
|
- msgSend = new Message(MESSAGE_ANSWER_ACK);
|
171
|
|
- }
|
172
|
|
-
|
173
|
|
- if (msgRcv->CompareID(MESSAGE_CAM_POSITION_COMPUTE_STOP)) {
|
174
|
|
- sendPosition = false;
|
175
|
|
- msgSend = new Message(MESSAGE_ANSWER_ACK);
|
176
|
|
- }
|
177
|
|
-
|
178
|
|
- if (msgRcv->CompareID(MESSAGE_ROBOT_BATTERY_GET)) msgSend = new MessageBattery(MESSAGE_ROBOT_BATTERY_LEVEL, BATTERY_FULL);
|
179
|
|
-
|
180
|
|
- if (msgRcv->CompareID(MESSAGE_CAM_ASK_ARENA)) showArena = true;
|
181
|
|
- if (msgRcv->CompareID(MESSAGE_CAM_ARENA_CONFIRM)) showArena = false;
|
182
|
|
- if (msgRcv->CompareID(MESSAGE_CAM_ARENA_INFIRM)) showArena = false;
|
183
|
|
-
|
184
|
|
- if (msgSend != NULL) monitor.Write(msgSend);
|
185
|
|
- delete(msgRcv);
|
186
|
|
- }
|
187
|
|
-}
|
188
|
|
-
|
189
|
|
-void Tasks::TimerTask(void* arg) {
|
190
|
|
- struct timespec tim, tim2;
|
191
|
|
- Message *msgSend;
|
192
|
|
- int counter;
|
193
|
|
- int cntFrame = 0;
|
194
|
|
- Position pos;
|
195
|
|
- Arena arena;
|
196
|
|
-
|
197
|
|
- tim.tv_sec = 0;
|
198
|
|
- tim.tv_nsec = 50000000; // 50ms (20fps)
|
199
|
|
-
|
200
|
|
- cout << "Start " << __PRETTY_FUNCTION__ << endl << flush;
|
201
|
|
-
|
202
|
|
- Camera camera = Camera(sm, 20);
|
203
|
|
- cout << "Try opening camera" << endl << flush;
|
204
|
|
- if (camera.Open()) cout << "Camera opened successfully" << endl << flush;
|
205
|
|
- else {
|
206
|
|
- cout << "Failed to open camera" << endl << flush;
|
207
|
|
-
|
208
|
|
- exit(0);
|
209
|
|
- }
|
210
|
|
-
|
211
|
|
- pos.angle = 0.0;
|
212
|
|
- pos.robotId = -1;
|
213
|
|
- pos.center = cv::Point2f(0, 0);
|
214
|
|
- pos.direction = cv::Point2f(0, 0);
|
215
|
|
-
|
216
|
|
- while (1) {
|
217
|
|
- //std::this_thread::sleep_for(std::chrono::seconds )
|
218
|
|
- //sleep(1);
|
219
|
|
- // if (nanosleep(&tim, &tim2) < 0) {
|
220
|
|
- // printf("Nano sleep system call failed \n");
|
221
|
|
- // return;
|
222
|
|
- // }
|
223
|
|
-
|
224
|
|
- // counter++;
|
225
|
|
- // if (counter>=10) {
|
226
|
|
- // flag=true;
|
227
|
|
- // counter=0;
|
228
|
|
- // }
|
229
|
|
- //mutexTimer.unlock();
|
230
|
|
- Img image = camera.Grab(); // 15fps
|
231
|
|
-
|
232
|
|
- if (sendPosition == true) {
|
233
|
|
- counter++;
|
234
|
|
-
|
235
|
|
- if (counter >= 1) { // div =15
|
236
|
|
- counter = 0;
|
237
|
|
-
|
238
|
|
- //if (!arena.IsEmpty()) {
|
239
|
|
- image.dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::PREDEFINED_DICTIONARY_NAME(3));
|
240
|
|
-
|
241
|
|
- std::list<Position> poses = image.SearchRobot(arena);
|
242
|
|
- cout << "Nbr of pos detected: " << to_string(poses.size()) << endl << flush;
|
243
|
|
-
|
244
|
|
- if (poses.size() > 0) {
|
245
|
|
- Position firstPos = poses.front();
|
246
|
|
-
|
247
|
|
- pos.angle = firstPos.angle;
|
248
|
|
- pos.robotId = firstPos.robotId;
|
249
|
|
- pos.center = firstPos.center;
|
250
|
|
- pos.direction = firstPos.direction;
|
251
|
|
- } else {
|
252
|
|
- // Nothing found
|
253
|
|
- pos.angle = 0.0;
|
254
|
|
- pos.robotId = -1;
|
255
|
|
- pos.center = cv::Point2f(0,0);
|
256
|
|
- pos.direction = cv::Point2f(0,0);
|
257
|
|
- }
|
258
|
|
-
|
259
|
|
- MessagePosition *msgp = new MessagePosition(MESSAGE_CAM_POSITION, pos);
|
260
|
|
- monitor.Write(msgp);
|
261
|
|
- cout << "Position sent" << endl << flush;
|
262
|
|
- }
|
263
|
|
- }
|
264
|
|
-
|
265
|
|
- if (sendImage == true) {
|
266
|
|
- if (showArena) {
|
267
|
|
- arena = image.SearchArena();
|
268
|
|
-
|
269
|
|
- if (!arena.IsEmpty()) image.DrawArena(arena);
|
270
|
|
- else cout << "Arena not found" << endl << flush;
|
271
|
|
- }
|
272
|
|
-
|
273
|
|
- if (sendPosition == true) {
|
274
|
|
- image.DrawRobot(pos);
|
275
|
|
- }
|
276
|
|
-
|
277
|
|
- if (!arena.IsEmpty()) image.DrawArena(arena);
|
278
|
|
-
|
279
|
|
- MessageImg *msg = new MessageImg(MESSAGE_CAM_IMAGE, &image);
|
280
|
|
-
|
281
|
|
- monitor.Write(msg);
|
282
|
|
- cntFrame++;
|
283
|
|
- cout << "cnt: " << to_string(cntFrame) << endl << flush;
|
284
|
|
- }
|
285
|
|
- }
|
286
|
|
-}
|
287
|
|
-
|
288
|
|
-void Tasks::SendToMonTask(void* arg) {
|
289
|
|
- cout << "Start " << __PRETTY_FUNCTION__ << endl << flush;
|
290
|
|
-
|
291
|
|
- while (1) {
|
292
|
|
-
|
293
|
|
- }
|
294
|
|
-}
|
295
|
|
-
|
296
|
|
-//void Tasks::f_sendToMon(void * arg) {
|
297
|
|
-// int err;
|
298
|
|
-// MessageToMon msg;
|
299
|
|
-//
|
300
|
|
-// /* INIT */
|
301
|
|
-// RT_TASK_INFO info;
|
302
|
|
-// rt_task_inquire(NULL, &info);
|
303
|
|
-// printf("Init %s\n", info.name);
|
304
|
|
-// rt_sem_p(&sem_barrier, TM_INFINITE);
|
305
|
|
-//
|
306
|
|
-//#ifdef _WITH_TRACE_
|
307
|
|
-// printf("%s : waiting for sem_serverOk\n", info.name);
|
308
|
|
-//#endif
|
309
|
|
-// rt_sem_p(&sem_serverOk, TM_INFINITE);
|
310
|
|
-// while (1) {
|
311
|
|
-//
|
312
|
|
-//#ifdef _WITH_TRACE_
|
313
|
|
-// printf("%s : waiting for a message in queue\n", info.name);
|
314
|
|
-//#endif
|
315
|
|
-// if (rt_queue_read(&q_messageToMon, &msg, sizeof (MessageToRobot), TM_INFINITE) >= 0) {
|
316
|
|
-//#ifdef _WITH_TRACE_
|
317
|
|
-// printf("%s : message {%s,%s} in queue\n", info.name, msg.header, (char*)msg.data);
|
318
|
|
-//#endif
|
319
|
|
-//
|
320
|
|
-// send_message_to_monitor(msg.header, msg.data);
|
321
|
|
-// free_msgToMon_data(&msg);
|
322
|
|
-// rt_queue_free(&q_messageToMon, &msg);
|
323
|
|
-// } else {
|
324
|
|
-// printf("Error msg queue write: %s\n", strerror(-err));
|
325
|
|
-// }
|
326
|
|
-// }
|
327
|
|
-//}
|
328
|
|
-//
|
329
|
|
-//void Tasks::f_receiveFromMon(void *arg) {
|
330
|
|
-// MessageFromMon msg;
|
331
|
|
-// int err;
|
332
|
|
-//
|
333
|
|
-// /* INIT */
|
334
|
|
-// RT_TASK_INFO info;
|
335
|
|
-// rt_task_inquire(NULL, &info);
|
336
|
|
-// printf("Init %s\n", info.name);
|
337
|
|
-// rt_sem_p(&sem_barrier, TM_INFINITE);
|
338
|
|
-//
|
339
|
|
-//#ifdef _WITH_TRACE_
|
340
|
|
-// printf("%s : waiting for sem_serverOk\n", info.name);
|
341
|
|
-//#endif
|
342
|
|
-// rt_sem_p(&sem_serverOk, TM_INFINITE);
|
343
|
|
-// do {
|
344
|
|
-//#ifdef _WITH_TRACE_
|
345
|
|
-// printf("%s : waiting for a message from monitor\n", info.name);
|
346
|
|
-//#endif
|
347
|
|
-// err = receive_message_from_monitor(msg.header, msg.data);
|
348
|
|
-//#ifdef _WITH_TRACE_
|
349
|
|
-// printf("%s: msg {header:%s,data=%s} received from UI\n", info.name, msg.header, msg.data);
|
350
|
|
-//#endif
|
351
|
|
-// if (strcmp(msg.header, HEADER_MTS_COM_DMB) == 0) {
|
352
|
|
-// if (msg.data[0] == OPEN_COM_DMB) { // Open communication supervisor-robot
|
353
|
|
-//#ifdef _WITH_TRACE_
|
354
|
|
-// printf("%s: message open Xbee communication\n", info.name);
|
355
|
|
-//#endif
|
356
|
|
-// rt_sem_v(&sem_openComRobot);
|
357
|
|
-// }
|
358
|
|
-// } else if (strcmp(msg.header, HEADER_MTS_DMB_ORDER) == 0) {
|
359
|
|
-// if (msg.data[0] == DMB_START_WITHOUT_WD) { // Start robot
|
360
|
|
-//#ifdef _WITH_TRACE_
|
361
|
|
-// printf("%s: message start robot\n", info.name);
|
362
|
|
-//#endif
|
363
|
|
-// rt_sem_v(&sem_startRobot);
|
364
|
|
-//
|
365
|
|
-// } else if ((msg.data[0] == DMB_GO_BACK)
|
366
|
|
-// || (msg.data[0] == DMB_GO_FORWARD)
|
367
|
|
-// || (msg.data[0] == DMB_GO_LEFT)
|
368
|
|
-// || (msg.data[0] == DMB_GO_RIGHT)
|
369
|
|
-// || (msg.data[0] == DMB_STOP_MOVE)) {
|
370
|
|
-//
|
371
|
|
-// rt_mutex_acquire(&mutex_move, TM_INFINITE);
|
372
|
|
-// robotMove = msg.data[0];
|
373
|
|
-// rt_mutex_release(&mutex_move);
|
374
|
|
-//#ifdef _WITH_TRACE_
|
375
|
|
-// printf("%s: message update movement with %c\n", info.name, robotMove);
|
376
|
|
-//#endif
|
377
|
|
-//
|
378
|
|
-// }
|
379
|
|
-// }
|
380
|
|
-// } while (err > 0);
|
381
|
|
-//
|
382
|
|
-//}
|
383
|
|
-//
|
384
|
|
-//void Tasks::f_openComRobot(void * arg) {
|
385
|
|
-// int err;
|
386
|
|
-//
|
387
|
|
-// /* INIT */
|
388
|
|
-// RT_TASK_INFO info;
|
389
|
|
-// rt_task_inquire(NULL, &info);
|
390
|
|
-// printf("Init %s\n", info.name);
|
391
|
|
-// rt_sem_p(&sem_barrier, TM_INFINITE);
|
392
|
|
-//
|
393
|
|
-// while (1) {
|
394
|
|
-//#ifdef _WITH_TRACE_
|
395
|
|
-// printf("%s : Wait sem_openComRobot\n", info.name);
|
396
|
|
-//#endif
|
397
|
|
-// rt_sem_p(&sem_openComRobot, TM_INFINITE);
|
398
|
|
-//#ifdef _WITH_TRACE_
|
399
|
|
-// printf("%s : sem_openComRobot arrived => open communication robot\n", info.name);
|
400
|
|
-//#endif
|
401
|
|
-// err = open_communication_robot();
|
402
|
|
-// if (err == 0) {
|
403
|
|
-//#ifdef _WITH_TRACE_
|
404
|
|
-// printf("%s : the communication is opened\n", info.name);
|
405
|
|
-//#endif
|
406
|
|
-// MessageToMon msg;
|
407
|
|
-// set_msgToMon_header(&msg, (char*)HEADER_STM_ACK);
|
408
|
|
-// write_in_queue(&q_messageToMon, msg);
|
409
|
|
-// } else {
|
410
|
|
-// MessageToMon msg;
|
411
|
|
-// set_msgToMon_header(&msg, (char*)HEADER_STM_NO_ACK);
|
412
|
|
-// write_in_queue(&q_messageToMon, msg);
|
413
|
|
-// }
|
414
|
|
-// }
|
415
|
|
-//}
|
416
|
|
-//
|
417
|
|
-//void Tasks::f_startRobot(void * arg) {
|
418
|
|
-// int err;
|
419
|
|
-//
|
420
|
|
-// /* INIT */
|
421
|
|
-// RT_TASK_INFO info;
|
422
|
|
-// rt_task_inquire(NULL, &info);
|
423
|
|
-// printf("Init %s\n", info.name);
|
424
|
|
-// rt_sem_p(&sem_barrier, TM_INFINITE);
|
425
|
|
-//
|
426
|
|
-// while (1) {
|
427
|
|
-//#ifdef _WITH_TRACE_
|
428
|
|
-// printf("%s : Wait sem_startRobot\n", info.name);
|
429
|
|
-//#endif
|
430
|
|
-// rt_sem_p(&sem_startRobot, TM_INFINITE);
|
431
|
|
-//#ifdef _WITH_TRACE_
|
432
|
|
-// printf("%s : sem_startRobot arrived => Start robot\n", info.name);
|
433
|
|
-//#endif
|
434
|
|
-// err = send_command_to_robot(DMB_START_WITHOUT_WD);
|
435
|
|
-// if (err == 0) {
|
436
|
|
-//#ifdef _WITH_TRACE_
|
437
|
|
-// printf("%s : the robot is started\n", info.name);
|
438
|
|
-//#endif
|
439
|
|
-// rt_mutex_acquire(&mutex_robotStarted, TM_INFINITE);
|
440
|
|
-// robotStarted = 1;
|
441
|
|
-// rt_mutex_release(&mutex_robotStarted);
|
442
|
|
-// MessageToMon msg;
|
443
|
|
-// set_msgToMon_header(&msg, (char*)HEADER_STM_ACK);
|
444
|
|
-// write_in_queue(&q_messageToMon, msg);
|
445
|
|
-// } else {
|
446
|
|
-// MessageToMon msg;
|
447
|
|
-// set_msgToMon_header(&msg, (char*)HEADER_STM_NO_ACK);
|
448
|
|
-// write_in_queue(&q_messageToMon, msg);
|
449
|
|
-// }
|
450
|
|
-// }
|
451
|
|
-//}
|
452
|
|
-//
|
453
|
|
-//void Tasks::f_move(void *arg) {
|
454
|
|
-// /* INIT */
|
455
|
|
-// RT_TASK_INFO info;
|
456
|
|
-// rt_task_inquire(NULL, &info);
|
457
|
|
-// printf("Init %s\n", info.name);
|
458
|
|
-// rt_sem_p(&sem_barrier, TM_INFINITE);
|
459
|
|
-//
|
460
|
|
-// /* PERIODIC START */
|
461
|
|
-//#ifdef _WITH_PERIODIC_TRACE_
|
462
|
|
-// printf("%s: start period\n", info.name);
|
463
|
|
-//#endif
|
464
|
|
-// rt_task_set_periodic(NULL, TM_NOW, 100000000);
|
465
|
|
-// while (1) {
|
466
|
|
-//#ifdef _WITH_PERIODIC_TRACE_
|
467
|
|
-// printf("%s: Wait period \n", info.name);
|
468
|
|
-//#endif
|
469
|
|
-// rt_task_wait_period(NULL);
|
470
|
|
-//#ifdef _WITH_PERIODIC_TRACE_
|
471
|
|
-// printf("%s: Periodic activation\n", info.name);
|
472
|
|
-// printf("%s: move equals %c\n", info.name, robotMove);
|
473
|
|
-//#endif
|
474
|
|
-// rt_mutex_acquire(&mutex_robotStarted, TM_INFINITE);
|
475
|
|
-// if (robotStarted) {
|
476
|
|
-// rt_mutex_acquire(&mutex_move, TM_INFINITE);
|
477
|
|
-// send_command_to_robot(robotMove);
|
478
|
|
-// rt_mutex_release(&mutex_move);
|
479
|
|
-//#ifdef _WITH_TRACE_
|
480
|
|
-// printf("%s: the movement %c was sent\n", info.name, robotMove);
|
481
|
|
-//#endif
|
482
|
|
-// }
|
483
|
|
-// rt_mutex_release(&mutex_robotStarted);
|
484
|
|
-// }
|
485
|
|
-//}
|
486
|
|
-//
|
487
|
|
-//void write_in_queue(RT_QUEUE *queue, MessageToMon msg) {
|
488
|
|
-// void *buff;
|
489
|
|
-// buff = rt_queue_alloc(&q_messageToMon, sizeof (MessageToMon));
|
490
|
|
-// memcpy(buff, &msg, sizeof (MessageToMon));
|
491
|
|
-// rt_queue_send(&q_messageToMon, buff, sizeof (MessageToMon), Q_NORMAL);
|
492
|
|
-//}
|
493
|
|
-
|
494
|
|
-#endif //__WITH_PTHREAD__
|