-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRRBotRecorder.java
94 lines (79 loc) · 2.93 KB
/
RRBotRecorder.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
package org.firstinspires.ftc.teamcode;
import android.content.Context;
import com.qualcomm.robotcore.eventloop.opmode.Disabled;
import com.qualcomm.robotcore.eventloop.opmode.OpMode;
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 java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
@TeleOp(name="RRBotRecorder")
@Disabled
public class RRBotRecorder extends OpMode{
// Declare OpMode members.
public static final String RECORD_FILE = "teleop_rec.txt";
private ElapsedTime runtime = new ElapsedTime();
private static boolean startedRecording=false;
private static long curtime=-1;
BufferedWriter writer;
RRBotHardware robot = new RRBotHardware();
//construct drive class
RRBotMecanumDrive drive = new RRBotMecanumDrive(robot);
/*
* Code to run ONCE when the driver hits INIT
*/
@Override
public void init() {
telemetry.addData("Status", "Initializing");
robot.init(hardwareMap);
// Tell the driver that initialization is complete.
telemetry.addData("Status", "Initialized");
/*try{
telemetry.addData(">>","Writer initialized.");
}catch(IOException e){
telemetry.addData(">>",e.getMessage());
//telemetry.addData(">>", );
}*/
}
@Override
public void loop() {
DriveUpdate();
}
@Override
public void stop() {
try{
writer.close();
}catch(IOException e) {e.printStackTrace();}
}
public void DriveUpdate()
{
//if the robot is not driving automatically, set motor power to the manual drive algorithm based on gamepad inputs
if(!drive.getIsAutoMove())//CHECK TO SEE HOW MANY MILLIS BETWEEN EACH RUN OF THIS, SEE IF YOU NEED TO STANDARDIZE
{
//if(curtime!=-1 && System.currentTimeMillis()-curtime >=15){}
float leftx = gamepad1.left_stick_x;
float lefty = gamepad1.left_stick_y;
float rightx = -gamepad1.right_stick_x;
float righty = gamepad1.right_stick_y;
boolean a = gamepad1.a;
float gas = gamepad1.right_trigger;
boolean x = gamepad1.x;
if(!startedRecording && (leftx != 0 || lefty != 0 || rightx!= 0 || righty !=0) || a==true || gas!=0 || x==true){
telemetry.addData(">>","Started recording.");
telemetry.update();
startedRecording = true;
}else if(startedRecording){
String message = leftx+","+lefty+","+rightx+","+righty+","+a+","+gas+","+x;
try{
writer.append(message+"\n");
}catch (IOException e) {e.printStackTrace();}
}
}
else
{
drive.AutoMoveEndCheck();
}
}
}