Repository navigation
Expand file tree
/
Copy pathProgrammingBoard_9_1.java
More file actions
50 lines (41 loc) · 1.57 KB
/
Copy pathProgrammingBoard_9_1.java
File metadata and controls
50 lines (41 loc) · 1.57 KB
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.firstinspires.ftc.teamcode.solutions;
import com.qualcomm.robotcore.hardware.AnalogInput;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.DigitalChannel;
import com.qualcomm.robotcore.hardware.HardwareMap;
import com.qualcomm.robotcore.hardware.Servo;
import com.qualcomm.robotcore.util.Range;
public class ProgrammingBoard_9_1 {
private DigitalChannel touchSensor;
private DcMotor motor;
private double ticksPerRotation;
private Servo servo;
private AnalogInput pot;
public void init(HardwareMap hwMap) {
touchSensor = hwMap.get(DigitalChannel.class, "touch_sensor");
touchSensor.setMode(DigitalChannel.Mode.INPUT);
motor = hwMap.get(DcMotor.class, "motor");
motor.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
ticksPerRotation = motor.getMotorType().getTicksPerRev();
servo = hwMap.get(Servo.class, "servo");
pot = hwMap.get(AnalogInput.class, "pot");
}
public boolean isTouchSensorPressed() {
return !touchSensor.getState();
}
public void setMotorSpeed(double speed) {
motor.setPower(speed);
}
public double getMotorRotations() {
return motor.getCurrentPosition() / ticksPerRotation;
}
public void setServoPosition(double position) {
servo.setPosition(position);
}
public double getPotAngle() {
return Range.scale(pot.getVoltage(), 0, pot.getMaxVoltage(), 0, 270);
}
public double getPotRange() {
return Range.scale(pot.getVoltage(), 0, pot.getMaxVoltage(), 0, 1.0);
}
}