-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimedMotor.java
More file actions
56 lines (48 loc) · 1.54 KB
/
Copy pathTimedMotor.java
File metadata and controls
56 lines (48 loc) · 1.54 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
package com.walnuthillseagles.walnutlibrary;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.hardware.DcMotor;
/**
* Created by Yan Vologzhanin on 1/2/2016.
*/
public class TimedMotor extends LinearMotor implements Runnable, Auto {
public static final int MSECSINSEC = 1000;
public static final int NSECSINSEC = 1000000;
private int numMSecs;
private Thread runner;
public TimedMotor(DcMotor myMotor, String name,boolean encoderCheck, boolean isReversed){
super(myMotor, name, encoderCheck,isReversed);
numMSecs = 0;
}
//Seconds precise up to three decimal places
//@ENSURE(Seconds > 0)
public void operate(double seconds, double mySpeedLimit){
numMSecs = (int) (seconds*MSECSINSEC);
speedLimit = mySpeedLimit * orientation;
//Start parrallel Process
runner = new Thread(this);
runner.start();
}
public void operate(double seconds){
if(seconds < 0)
this.operate(seconds,-1);
else
this.operate(seconds, 1);
}
public void run(){
this.setPower(speedLimit);
try{
synchronized (this){
this.wait(numMSecs);
}
}
catch(InterruptedException e){
Thread.currentThread().interrupt();
}
finally {
fullStop();
}
}
public void waitForCompletion() throws InterruptedException{
runner.join();
}
}