-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDistanceDrive.java
More file actions
99 lines (84 loc) · 2.85 KB
/
Copy pathDistanceDrive.java
File metadata and controls
99 lines (84 loc) · 2.85 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
92
93
94
95
96
97
98
99
package com.walnuthillseagles.walnutlibrary;
import java.util.ArrayList;
/**
* Created by Yan Vologzhanin on 1/4/2016.
*/
public class DistanceDrive {
protected DistanceMotor leftDrive;
protected DistanceMotor rightDrive;
protected double robotWidth;
//Just cause
public static final int REVERSEORIENTATION = -1;
//Constructor used for first two motors
public DistanceDrive(DistanceMotor myLeft, DistanceMotor myRight, double width){
//Initilize ArrayLists
leftDrive = myLeft;
rightDrive = myRight;
//Initilize other variables
robotWidth = width;
}
//Autonomous Methods
public void linearDrive(double inches, double pow){
//Tell motors to start
leftDrive.operate(inches,pow);
rightDrive.operate(inches, pow);
}
public void linearDrive(double inches){
linearDrive(inches, 1);
}
//Right is positive, left is negetive
public void tankTurn(double degrees, double pow){
if(degrees != 0){
double factor = 360/degrees;
double distance = (Math.PI * robotWidth)/factor;
//One is inverted to create a tank turn
leftDrive.operate(distance,pow);
rightDrive.operate(distance * REVERSEORIENTATION, pow * REVERSEORIENTATION);
}
}
public void tankTurn(double degrees){
tankTurn(degrees, 1);
}
public void pivotTurn(double degrees, double pow){
if(degrees!=0){
double factor = Math.abs(360/degrees);
double distance = (Math.PI * robotWidth * 2)/factor;
if(pow>0){
if(degrees>0)
leftDrive.operate(distance,pow);
else
rightDrive.operate(distance,pow);
}
else //if(pow<0)
{
if(degrees>0)
rightDrive.operate(-distance,pow);
else
leftDrive.operate(-distance,pow);
}
}
}
public void forwardPivotTurn(double degrees){
forwardPivotTurn(degrees,1);
}
public void forwardPivotTurn(double degrees, double pow){ pivotTurn(degrees, Math.abs(pow));
}
public void backwardsPivotTurn(double degrees){
backwardPivotTurn(degrees,-1);
}
public void backwardPivotTurn(double degrees, double pow){pivotTurn(degrees, -Math.abs(pow));}
public void stop(){
leftDrive.stop();
rightDrive.stop();
}
public void fullStop(){
leftDrive.fullStop();
rightDrive.fullStop();
}
//Timers
public void waitForCompletion() throws InterruptedException{
leftDrive.waitForCompletion();
rightDrive.waitForCompletion();
}
//Helpper Private methods
}