-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContinuousServo.java
More file actions
91 lines (87 loc) · 2.55 KB
/
Copy pathContinuousServo.java
File metadata and controls
91 lines (87 loc) · 2.55 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
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
package com.walnuthillseagles.walnutlibrary;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.hardware.Servo;
/**
* Created by Yan Vologzhanin on 2/8/2016.
*/
public class ContinuousServo implements Drivable{
private Servo servo;
private int tablePos;
private double deadZone;
private int orientation;
private String name;
private double trueCenter;
public ContinuousServo(Servo myServo, String myName, double startPos,
String myControl, boolean reverse, double myDeadzone) {
servo = myServo;
name = myName;
//Assign Table Position
String nonCaseSensetive = myControl.toUpperCase();
setTable(AnalogValues.valueOf(nonCaseSensetive));
if(reverse)
orientation = -1;
else
orientation = 1;
deadZone = myDeadzone;
//@TODO: Use this if necessary
//trueCenter = startPos;
stop();
}
public void stop(){
servo.setPosition(0.5);
}
private void setTable(AnalogValues myControl){
switch(myControl){
case LEFTX1:
tablePos = 0;
break;
case LEFTY1:
tablePos = 1;
break;
case RIGHTX1:
tablePos = 2;
break;
case RIGHTY1:
tablePos = 3;
break;
case LEFTZ1:
tablePos = 4;
break;
case RIGHTZ1:
tablePos = 5;
break;
case LEFTX2:
tablePos = 6;
break;
case LEFTY2:
tablePos = 7;
break;
case RIGHTX2:
tablePos = 8;
break;
case RIGHTY2:
tablePos = 9;
break;
case LEFTZ2:
tablePos = 10;
break;
case RIGHTZ2:
tablePos = 11;
break;
default:
tablePos = 0;
}
}
public void setPower(double power) {
servo.setPosition(power / 2 + 0.5);
}
public void operate(){
double val = VirtualGamepad.doubleValues[tablePos];
if(Math.abs(val)>deadZone )
this.setPower(val*orientation);
else if(Math.abs(val)>0.95)
this.setPower(0.95 * orientation);
else
this.stop();
}
}