OpenEL 3.0.0

utrx-17-1.c
Go to the documentation of this file.
1 #include "openEL.h"
2 #include "openEL_motor.h"
3 #include <stdint.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <unistd.h>
7
8 uint32_t now1 = 0;
9 uint32_t now2 = 0;
10
11 void position1(uint32_t m, uint32_t pos)
12 {
13 int i;
14 int32_t d = now1 - pos;
15
16 for (i = 0; i < abs(d) / 5 - 1; ++i) {
17 if (0 <= d)
18 HalMotorSetPosition_I32(m, now1 - 5 * i, 0, 0);
19 else
20 HalMotorSetPosition_I32(m, now1 + 5 * i, 0, 0);
21 usleep(40 * 1000);
22 }
23 HalMotorSetPosition_I32(m, pos, 0, 0);
24 now1 = pos;
25 }
26
27 void position2(uint32_t m, uint32_t pos, uint32_t *now)
28 {
29 int i;
30 int32_t d = (int32_t)*now - (int32_t)pos;
31
32 for (i = 0; i < abs(d) / 5 - 1; ++i) {
33 if (0 <= d)
34 HalMotorSetPosition_I32(m, *now - 5 * i, 0, 0);
35 else
36 HalMotorSetPosition_I32(m, *now + 5 * i, 0, 0);
37 usleep(40 * 1000);
38 }
39 HalMotorSetPosition_I32(m, pos, 0, 0);
40 *now = pos;
41 }
42
43 #define WAIT 8
44
45 int main()
46 {
47 uint32_t count = 0;
48 uint32_t motor1 = 0;
49 uint32_t motor2 = 0;
50 uint32_t *Motor_1;
51 uint32_t *Motor_2;
52 int rnd;
53 int rnd_old = 0;
54 int off = 45;
55
56 Motor_1 = &motor1;
57 Motor_2 = &motor2;
58
59 HalInit(Motor_1, 0, 0, 16);
60
61 printf("deg 90\n");
62 HalMotorSetPosition_I32(*Motor_1, 90 + off, 0, 0);
63 now1 = 90;
64 sleep(WAIT);
65
66 for (;;) {
67 rnd = rand() % 7;
68 if (rnd_old == rnd)
69 continue;
70 rnd_old = rnd;
71
72 if (10 < count++) {
73 rnd = 3;
74 count = 0;
75 }
76
77 // printf("rnd %d\n", rnd);
78
79 if (rnd == 0) {
80 printf("deg 45\n");
81 position2(*Motor_1, 45 + off, &now1);
82 sleep(WAIT);
83 } else if (rnd == 1) {
84 printf("deg 60\n");
85 position2(*Motor_1, 60 + off, &now1);
86 sleep(WAIT);
87 } else if (rnd == 2) {
88 printf("deg 75\n");
89 position2(*Motor_1, 75 + off, &now1);
90 sleep(WAIT);
91 } else if (rnd == 3) {
92 printf("deg 90\n");
93 position2(*Motor_1, 90 + off, &now1);
94 sleep(WAIT);
95 } else if (rnd == 4) {
96 printf("deg 105\n");
97 position2(*Motor_1, 105 + off, &now1);
98 sleep(WAIT);
99 } else if (rnd == 5) {
100 printf("deg 120\n");
101 position2(*Motor_1, 120 + off, &now1);
102 sleep(WAIT);
103 } else if (rnd == 6) {
104 printf("deg 135\n");
105 position2(*Motor_1, 135 + off, &now1);
106 sleep(WAIT);
107 }
108 }
109
110 HalMotorSetPosition_I32(*Motor_1, 90 + off, 0, 0);
111 HalExit(*Motor_1);
112 }
now1
uint32_t now1
Definition: utrx-17-1.c:8
WAIT
#define WAIT
Definition: utrx-17-1.c:43
openEL.h
OpenEL Common Header File 3.0.0.
now2
uint32_t now2
Definition: utrx-17-1.c:9
position1
void position1(uint32_t m, uint32_t pos)
Definition: utrx-17-1.c:11
position2
void position2(uint32_t m, uint32_t pos, uint32_t *now)
Definition: utrx-17-1.c:27
HalInit
enum ReturnCode HalInit(HALCOMPONENT_T *halComponent)
Definition: openEL.c:75
openEL_motor.h
OpenEL Motor Common File 3.0.0.
main
int main()
Definition: utrx-17-1.c:45