summaryrefslogtreecommitdiff
path: root/servo/servo_accessors.go
blob: 3258e7466632dfe72858d7e9c5179a4e74c687ff (plain)
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
/* SPDX-License-Identifier: MIT
 *
 * Copyright (C) 2020 jet tsang zeon-git. All Rights Reserved.
 */

package servo

// MoveTimeWrite
func (s *Servo) MoveTimeWrite(position uint16, ms uint16) error {
	return s.sendInstruction(MoveTimeWrite, []uint16{position, ms})
}

// MoveTimeRead
func (s *Servo) MoveTimeRead() ([]byte, error) {
	return s.getData(MoveTimeRead)
}

// MoveTimeWaitWrite
func (s *Servo) MoveTimeWaitWrite(position uint16, ms uint16) error {
	return s.sendInstruction(MoveTimeWaitWrite, []uint16{position, ms})
}

// MoveTimeWaitRead
func (s *Servo) MoveTimeWaitRead() ([]byte, error) {
	return s.getData(MoveTimeWaitRead)
}

// MoveStart
func (s *Servo) MoveStart() error {
	return s.sendInstruction(MoveStart, nil)
}

// MoveStop
func (s *Servo) MoveStop() ([]byte, error) {
	return s.getData(MoveStop)
}

// IDWrite
func (s *Servo) IDWrite(newID uint16) error {
	return s.sendInstruction(IDWrite, []uint16{newID})
}

// IDRead
func (s *Servo) IDRead() ([]byte, error) {
	return s.getData(IDRead)
}

// AngleOffsetAdjust
func (s *Servo) AngleOffsetAdjust(adjust uint16) error {
	return s.sendInstruction(AngleOffsetAdjust, []uint16{adjust})
}

// AngleOffsetWrite: Save Offset to Servo's EEPROM
func (s *Servo) AngleOffsetWrite() error {
	return s.sendInstruction(AngleOffsetWrite, nil)
}

// AngleOffsetRead: Read Offset from Servo's EEPROM
func (s *Servo) AngleOffsetRead() ([]byte, error) {
	return s.getData(AngleOffsetRead)
}

// AngleLimitWrite: Set angle limit
func (s *Servo) AngleLimitWrite(minAngle uint16, maxAngle uint16) error {
	return s.sendInstruction(AngleLimitWrite, []uint16{minAngle, maxAngle})
}

// AngleLimitRead
// TODO: translate byte to angle and position
func (s *Servo) AngleLimitRead() ([]byte, error) {
	return s.getData(AngleLimitRead)
}

// VoltageLimitWrite
func (s *Servo) VoltageLimitWrite(minVoltage uint16, maxVoltage uint16) error {
	return s.sendInstruction(VoltageLimitWrite, []uint16{minVoltage, maxVoltage})
}

// VoltageLimitRead
func (s *Servo) VoltageLimitRead() ([]byte, error) {
	return s.getData(VoltageLimitRead)
}

// TemperatureMaxLimitWrite
func (s *Servo) TemperatureMaxLimitWrite(maxTemperature uint16) error {
	return s.sendInstruction(TemperatureMaxLimitWrite, []uint16{maxTemperature})
}

// TemperatureMaxLimitRead
func (s *Servo) TemperatureMaxLimitRead() ([]byte, error) {
	return s.getData(TemperatureMaxLimitRead)
}

// TemperatureRead
func (s *Servo) TemperatureRead() ([]byte, error) {
	return s.getData(TemperatureRead)
}

// VoltageRead
func (s *Servo) VoltageRead() ([]byte, error) {
	return s.getData(VoltageRead)
}

// PositionRead
func (s *Servo) PositionRead() ([]byte, error) {
	return s.getData(PositionRead)
}

// MotorModeWrite
// speed: -1000 to 1000
func (s *Servo) MotorModeWrite(isMotor uint16, speed uint16) error {
	return s.sendInstruction(MotorModeWrite, []uint16{isMotor << 8, speed})
}

// MotorModeRead
func (s *Servo) MotorModeRead() ([]byte, error) {
	return s.getData(MotorModeRead)
}

// LoadOrUnloadWrite
func (s *Servo) LoadOrUnloadWrite(isLoad uint16) error {
	return s.sendInstruction(LoadOrUnloadWrite, []uint16{isLoad})
}

// LoadOrUnloadRead
func (s *Servo) LoadOrUnloadRead() ([]byte, error) {
	return s.getData(LoadOrUnloadRead)
}

// LEDControlWrite
func (s *Servo) LEDControlWrite(isAlwayOn uint16) error {
	return s.sendInstruction(LEDControlWrite, []uint16{isAlwayOn})
}

// LEDControlRead
func (s *Servo) LEDControlRead() ([]byte, error) {
	return s.getData(LEDControlRead)
}

// LEDErrorWrite
// lightColor: 1~7
func (s *Servo) LEDErrorWrite(lightColor uint16) error {
	return s.sendInstruction(LEDErrorWrite, []uint16{lightColor})
}

// LEDErrorRead
func (s *Servo) LEDErrorRead() ([]byte, error) {
	return s.getData(LEDErrorRead)
}