-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRRBotAutoReader.java
122 lines (105 loc) · 5.28 KB
/
RRBotAutoReader.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
import com.qualcomm.robotcore.eventloop.opmode.TeleOp;
import com.qualcomm.robotcore.hardware.DcMotor;
import com.qualcomm.robotcore.util.ElapsedTime;
import com.qualcomm.robotcore.util.Range;
import com.qualcomm.hardware.bosch.BNO055IMU;
import org.firstinspires.ftc.robotcore.external.navigation.AngleUnit;
import org.firstinspires.ftc.robotcore.external.navigation.AxesOrder;
import org.firstinspires.ftc.robotcore.external.navigation.AxesReference;
import org.firstinspires.ftc.robotcore.external.navigation.Orientation;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Locale;
@Autonomous(name="RRBotAutoReader")
@Disabled
public class RRBotAutoReader extends LinearOpMode{
// Declare OpMode members.
private ElapsedTime runtime = new ElapsedTime();
RRBotHardware robot = new RRBotHardware();
BufferedReader br;
private static boolean timerstart=false;
private static long curtime;
private static boolean switching=false;
//gyro variables
private BNO055IMU imu;
private Orientation angles;
//Motor Definitions
private final double COUNTS_PER_MOTOR_REV = 537.6; // Andymark 20:1 gearmotor
private final double DRIVE_GEAR_REDUCTION = 1.0; // This is < 1.0 if geared UP
private final double WHEEL_DIAMETER_INCHES = 4.0; // For figuring circumference
private final double COUNTS_PER_INCH = (COUNTS_PER_MOTOR_REV * DRIVE_GEAR_REDUCTION) / (WHEEL_DIAMETER_INCHES * 3.1415);
//construct drive class
RRBotMecanumDrive drive = new RRBotMecanumDrive(robot);
@Override
public void runOpMode() {
telemetry.addData("Status", "Initialized");
telemetry.update();
robot.init(hardwareMap);
try{
br = new BufferedReader(new FileReader(new File(RRBotRecorder.RECORD_FILE)));//MIGHT NEED TO FIX THIS FILENAME
}catch(FileNotFoundException e) {e.printStackTrace();}
// Send telemetry message to indicate successful Encoder reset
telemetry.addData("Path0", "Starting at %7d :%7d",
robot.rearRightMotor.getCurrentPosition(),
robot.rearLeftMotor.getCurrentPosition(),
robot.frontRightMotor.getCurrentPosition(),
robot.frontLeftMotor.getCurrentPosition());
telemetry.update();
// Wait for the game to start (driver presses PLAY)
waitForStart();
runtime.reset();
String curline;
// run until the end of the match (driver presses STOP)
try{
while (opModeIsActive() && (curline = br.readLine()) !=null) {
String[] values = curline.split(",");
float mult = Float.parseFloat(values[5]);
boolean fulldrive = !Boolean.parseBoolean(values[6]);
boolean apressed = Boolean.parseBoolean(values[4]);
float lx = Integer.parseInt(values[0]);
float ly = Integer.parseInt(values[1]);
float rx = Integer.parseInt(values[2]);
float ry = Integer.parseInt(values[3]);
mult = RRBotTeleop.map(mult, 0,1,RRBotTeleop.minspeed,RRBotTeleop.maxspeed);
drive.setMotorPower(-(rx)*mult, (ry)*mult, (lx)*mult, (ly)*mult, false);//if you change doFunction, make sure to also change it in RRBotAutoReader
if(switching){
if(System.currentTimeMillis()-curtime > 500){//time before applying reverse voltage to switch direction
robot.intakeMotorLeft.setPower(-1);//should be mleming out
robot.intakeMotorRight.setPower(-1);
switching=false;
}
}else {
if (apressed && !timerstart) {
timerstart = true;
curtime = System.currentTimeMillis();
} else if (timerstart) {
if (apressed) {
if (System.nanoTime() - curtime > 500) {//delay before holding A turns into spew mode
robot.intakeMotorLeft.setPower(0);
robot.intakeMotorRight.setPower(0);
switching = true;
curtime=System.currentTimeMillis();
}
} else {
if (robot.intakeMotorLeft.getPower() == 1 || robot.intakeMotorLeft.getPower() == -1) {
robot.intakeMotorLeft.setPower(0);
robot.intakeMotorRight.setPower(0);
} else if (robot.intakeMotorLeft.getPower() == 0) {
robot.intakeMotorLeft.setPower(1);//should be slurping in
robot.intakeMotorRight.setPower(1);
}
timerstart = false;
}
}
}
}
}catch(IOException e){e.printStackTrace();}
}
}