Skip to content

Commit d18e3c7

Browse files
committed
add linear actuator
1 parent 6ecdb82 commit d18e3c7

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package frc.robot.lib;
2+
3+
import edu.wpi.first.wpilibj.PWM;
4+
5+
public class LinearActuator extends PWM {
6+
7+
private final int minLength, maxLength;
8+
9+
public LinearActuator(int channel, int minLength, int maxLength) {
10+
super(channel);
11+
this.minLength = minLength;
12+
this.maxLength = maxLength;
13+
// Our linear actators accept a pulse between 1ms and 2ms
14+
setBounds(2, 0, 0, 0, 1);
15+
}
16+
17+
public void set(double value) {
18+
setPosition(value);
19+
}
20+
21+
public void setLength(double length) {
22+
// Get the length as a percentage of maxLength
23+
set((length - minLength) / (maxLength - minLength));
24+
}
25+
26+
public double getLength() {
27+
return get() * (maxLength - minLength) + minLength;
28+
}
29+
30+
public double get() {
31+
return getPosition();
32+
}
33+
34+
}

0 commit comments

Comments
 (0)