-
Notifications
You must be signed in to change notification settings - Fork 0
/
CameraLights.java
50 lines (42 loc) · 1.15 KB
/
CameraLights.java
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
package org.team751.subsystems;
import edu.wpi.first.wpilibj.PWM;
import edu.wpi.first.wpilibj.command.Subsystem;
import org.team751.RobotMap;
/**
* This subsysytem controls the lights that provide reflective illumination for camera tracking
* @author Sam Crow
*/
public class CameraLights extends Subsystem {
/**
* The PWM channel
*/
protected PWM output = new PWM(RobotMap.lightsChannel);
/** The reference power level */
public static final double kPower = 0.3;
public void initDefaultCommand() {
// Set the default command for a subsystem here.
//setDefaultCommand(new MySpecialCommand());
}
/**
* Set the LEDs to illuminate at a given power level
* @param input The power level, 0-1
*/
public void setPower(double input){
output.setRaw(powerLevelToPWMCycle(input));
}
public void off(){
setPower(0);
}
public void on(){
setPower(kPower);
}
/**
* Convert a power level to a PWM duty cycle
* @param input The power from 0 to 1
* @return The corresponding PWM duty cycle from 0 to 255
*/
protected static int powerLevelToPWMCycle(double input){
int dutyCycle = (int)Math.round(255 * input);
return dutyCycle;
}
}