-
Notifications
You must be signed in to change notification settings - Fork 0
/
stepper.go
105 lines (90 loc) · 2.14 KB
/
stepper.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
105
//
// Laser Range Finder
// stepper.go
//
// Cole Smith - [email protected]
// Eric Lin - [email protected]
// LICENSE: Apache 2.0
//
package roombaControl
import (
"time"
"github.com/stianeikeland/go-rpio"
)
type Stepper struct {
pin_step rpio.Pin
delayMillisecond float64
pin_direction rpio.Pin
pin_microstep1 rpio.Pin
pin_microstep2 rpio.Pin
pin_microstep3 rpio.Pin
}
func (s Stepper) Spin() {
count := 0
for count < 1600 {
s.Step()
count += 1
}
}
func (s Stepper) Step() {
s.pin_step.Output()
s.pin_step.High()
time.Sleep(time.Duration(s.delayMillisecond) * time.Millisecond)
s.pin_step.Low()
time.Sleep(time.Duration(s.delayMillisecond) * time.Millisecond)
}
/*
Here's the exported State constant from rpio
// State of pin, High / Low
const (
Low State = iota
High
)
*/
func (s Stepper) set_direction(state rpio.State) {
s.pin_direction.Output()
s.pin_direction.Write(state)
}
func (s Stepper) set_full_step() {
s.pin_microstep1.Output()
s.pin_microstep1.Low()
s.pin_microstep2.Output()
s.pin_microstep2.Low()
s.pin_microstep3.Output()
s.pin_microstep3.Low()
}
func (s Stepper) set_half_step() {
s.pin_microstep1.Output()
s.pin_microstep1.High()
s.pin_microstep2.Output()
s.pin_microstep2.Low()
s.pin_microstep3.Output()
s.pin_microstep3.Low()
}
func (s Stepper) set_quater_step() {
s.pin_microstep1.Output()
s.pin_microstep1.Low()
s.pin_microstep2.Output()
s.pin_microstep2.High()
s.pin_microstep3.Output()
s.pin_microstep3.Low()
}
func (s Stepper) set_eighth_step() {
s.pin_microstep1.Output()
s.pin_microstep1.High()
s.pin_microstep2.Output()
s.pin_microstep2.High()
s.pin_microstep3.Output()
s.pin_microstep3.Low()
}
func (s Stepper) set_sixteenth_step() {
s.pin_microstep1.Output()
s.pin_microstep1.High()
s.pin_microstep2.Output()
s.pin_microstep2.High()
s.pin_microstep3.Output()
s.pin_microstep3.High()
}
func InitializeStepper(pin_step int, delayMillisecond float64, pin_direction, pin_microstep1 int, pin_microstep2 int, pin_microstep3 int) Stepper {
return Stepper{rpio.Pin(pin_step), delayMillisecond, rpio.Pin(pin_direction), rpio.Pin(pin_microstep1), rpio.Pin(pin_microstep2), rpio.Pin(pin_microstep3)}
}