This repository was archived by the owner on Jul 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservo.txt
160 lines (111 loc) · 2.39 KB
/
servo.txt
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
stuff to try:
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <drogon/wiringpi/wiringPi/wiringPi.h>
#include <drogon/wiringpi/wiringPi/softServo.h>
int main ()
{
if (wiringPiSetup () == -1)
{
fprintf (stdout, "oops: %s\n", strerror (errno)) ;
return 1 ;
}
softServoSetup (0, 1, 2, 3, 4, 5, 6, 7) ;
softServoWrite (0, 500) ;
/*
softServoWrite (1, 1000) ;
softServoWrite (2, 1100) ;
softServoWrite (3, 1200) ;
softServoWrite (4, 1300) ;
softServoWrite (5, 1400) ;
softServoWrite (6, 1500) ;
softServoWrite (7, 2200) ;
*/
for (;;)
delay (10) ;
}
compiler stuff:
"other compiler options"
-fexceptions
-pthread
PIGPIO THING:
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <pigpio.h>
/*
# servo_demo.c
# 2016-10-08
# Public Domain
gcc -Wall -pthread -o servo_demo servo_demo.c -lpigpio
sudo ./servo_demo # Send servo pulses to GPIO 4.
sudo ./servo_demo 23 24 25 # Send servo pulses to GPIO 23, 24, 25.
*/
#define NUM_GPIO 32
#define MIN_WIDTH 1000
#define MAX_WIDTH 2000
int run=1;
int step[NUM_GPIO];
int width[NUM_GPIO];
int used[NUM_GPIO];
int randint(int from, int to)
{
return (random() % (to - from + 1)) + from;
}
void stop(int signum)
{
run = 0;
}
int main(int argc, char *argv[])
{
int i, g;
if (gpioInitialise() < 0) return -1;
gpioSetSignalFunc(SIGINT, stop);
if (argc == 1) used[4] = 1;
else
{
for (i=1; i<argc; i++)
{
g = atoi(argv[i]);
if ((g>=0) && (g<NUM_GPIO)) used[g] = 1;
}
}
printf("Sending servos pulses to GPIO");
for (g=0; g<NUM_GPIO; g++)
{
if (used[g])
{
printf(" %d", g);
step[g] = randint(5, 25);
if ((step[g] % 2) == 0) step[g] = -step[g];
width[g] = randint(MIN_WIDTH, MAX_WIDTH);
}
}
printf(", control C to stop.\n");
while(run)
{
for (g=0; g<NUM_GPIO; g++)
{
if (used[g])
{
gpioServo(g, width[g]);
// printf("%d %d\n", g, width[g]);
width[g] += step[g];
if ((width[g]<MIN_WIDTH) || (width[g]>MAX_WIDTH))
{
step[g] = -step[g];
width[g] += step[g];
}
}
}
time_sleep(0.1);
}
printf("\ntidying up\n");
for (g=0; g<NUM_GPIO; g++)
{
if (used[g]) gpioServo(g, 0);
}
gpioTerminate();
return 0;
}