-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctrlTask.c
76 lines (64 loc) · 1.53 KB
/
ctrlTask.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "include.h"
#include "timer.h"
#include "structure.h"
#include <sys/neutrino.h>
#include <pthread.h>
//receive the message and start a thread for control function
typedef union
{
ClientMessageT msg;
struct _pulse pulse;
} MessageT;
extern int ctrltrig;
extern int chid;
extern double MOTOR_DES_POS[7];
extern double MOTOR_DES_TIME;
extern int JOINT;
extern unsigned char MODE;
extern unsigned char TRIG;
extern void control(void);
int ctrlEndFlag = 0;
void ctrlTask(void)
{
int debug = 0;
int rcvid=1;
MessageT msg;
static unsigned long ticks = 0;
pthread_attr_t attr;
int print_once_flag[7] = {1, 1, 1, 1, 1, 1, 1};
int i;
if(debug) printf("\nControl Task function");
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED );
while(ctrltrig)
{
rcvid = MsgReceive(chid, &msg, sizeof(msg), NULL);
if(rcvid == 0)
{
if(!ctrlEndFlag)
{
printf("ERROR : Control Task is out of time.\n fin\n");
fin();
}
if(debug)
{
printf("\nINSIDE ctrlTask FUNCTION");
for(i = 0; i < 7; i++)
{
if((debug == 1) && (print_once_flag[i] == 1))
{
printf("\nmotor %d trig = %d",i+1, TRIG);
printf("\nmotor %d mode = %d",i+1, MODE);
printf("\nmotor desired position = %lf", MOTOR_DES_POS[i]);
printf("\nmotor %d desired time = %lf",i+1, MOTOR_DES_TIME);
printf("\nSTARTING CONTROL THREAD");
print_once_flag[i] = 0;
}
}
}
ctrlEndFlag = 0;
pthread_create(NULL,&attr,(void *)control,NULL);
ticks++;
}
}
}