-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
104 lines (85 loc) · 1.99 KB
/
main.go
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
package main
import (
"log"
"time"
"github.com/stianeikeland/go-rpio/v4"
)
//pwm pins: 13,19,12,18
//18 and 12 on one channel
//13 and 19 on the other channel
const escPinID = 12
const servoPinID = 13
// const panPinID = 14
// const tiltPinID = 15
/*DON'T MODIFY THIS*/
const frequency = 100000
const cycleLen = uint32(2000)
const maxvalue_limited = uint32(200)
const maxvalue = uint32(250)
const midvalue = uint32(150)
const minvalue_limited = uint32(100)
const minvalue = uint32(50)
/*DON'T MODIFY THIS*/
const enableServo = true
const enableESC = true
func main() {
err := rpio.Open()
if err != nil {
log.Fatal("failed to open rpio")
}
defer rpio.Close()
if enableServo {
go func() {
servo := rpio.Pin(servoPinID)
servo.Mode(rpio.Pwm)
//c.pins.servo.Pwm()
servo.Freq(frequency)
servo.DutyCycle(midvalue, cycleLen)
log.Printf("Servo to middle")
time.Sleep(5 * time.Second)
log.Println("Start sweeping")
i := uint32(100)
for {
if i > maxvalue_limited {
i = minvalue_limited
}
//log.Printf("Sending %d of %d\n", i, maxvalue)
servo.DutyCycle(i, cycleLen)
time.Sleep(100 * time.Millisecond)
if i == maxvalue {
log.Println("waiting on top")
time.Sleep(5 * time.Second)
}
if i == minvalue {
log.Println("Waiting at bottom")
time.Sleep(5 * time.Second)
}
i++
}
}()
}
if enableESC {
go func() {
esc := rpio.Pin(escPinID)
esc.Mode(rpio.Pwm)
//c.pins.servo.Pwm()
esc.Freq(frequency)
log.Println("Starting ESC Calibration")
log.Println("Setting FULL throttle for 10 seconds")
esc.DutyCycle(maxvalue, cycleLen)
time.Sleep(10 * time.Second)
log.Println("Setting MIN throttle for 5 seconds")
esc.DutyCycle(minvalue, cycleLen)
time.Sleep(5 * time.Second)
log.Println("Setting CENTER throttle for 5 seconds")
esc.DutyCycle(midvalue, cycleLen)
time.Sleep(5 * time.Second)
for {
esc.DutyCycle(200, cycleLen)
time.Sleep(5 * time.Second)
}
}()
}
for {
}
}