-
Notifications
You must be signed in to change notification settings - Fork 6
/
W_DL_OpMode_IMU_v05.java
154 lines (103 loc) · 5.79 KB
/
W_DL_OpMode_IMU_v05.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
This sample OpMode demonstrates using the Datalogger class, which allows
FTC OpModes to log data to a CSV file, for direct import to Excel or Google Sheets.
This OpMode collects and writes the data to a log file in the RC device folder
FIRST/java/src/Datalogs. Specify the filename in this OpMode code.
Further info is available here:
https://github.com/WestsideRobotics/FTC-Datalogging/wiki
The source of data here is the IMU contained in the REV Control Hub and most
REV Expansion Hubs. Two fields are logged: Count (index number of each reading)
and Heading (Z-angle in degrees).
In the CSV/spreadsheet, these two columns are preceded by two default columns:
"Time" shows # of seconds since the datalogging class was instantiated, and
"d ms" shows # of milliseconds since the last data reading.
1/4/2022
This v05 calls Datalogger v05, which supports downloading from OnBot Java,
instead of file transfer via USB cable or wireless Android Debug Bridge (adb).
v04 called Datalogger v04, which inserts the timestamp at the beginning of
a completed line, just before writing the line to the datalog file. Previously
the timestamp was inserted at the beginning of a new line, after writing
the last completed line. Neither method records the exact moment of data
capture, but this method has less time lag and relates to the current
line rather than the previous line.
The v02 version added logging data on a **timed interval**, greater than the
average cycle time of the unregulated while() loop -- observed to be 8-10 ms in v01.
Notes:
1. Do not run this OpMode while the RC device is connected via USB cable
(in file transfer/MTP mode) to a Windows laptop. The datalog file
will be created, but no data will be logged to the file.
It's OK to run this OpMode while the RC device is connected wirelessly
via Android Debug Bridge (adb) to a Windows laptop.
2. The first values of "Time" and "d ms" will be the same.
Credit to Olavi Kamppari, who shared a more advanced version dated 9/9/2015.
*/
package org.firstinspires.ftc.teamcode;
import com.qualcomm.robotcore.eventloop.opmode.Autonomous;
import com.qualcomm.robotcore.util.ElapsedTime;
import com.qualcomm.robotcore.eventloop.opmode.LinearOpMode;
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 com.qualcomm.hardware.bosch.BNO055IMU; // IMU used in REV Hubs
@Autonomous(name = "DataLog IMU v05", group = "Datalogging")
public class W_DL_OpMode_IMU_v05 extends LinearOpMode {
// Declare members.
BNO055IMU imu;
BNO055IMU.Parameters imuParameters;
Orientation angles;
W_Datalogger_v05 imuDL; // edit name to Datalogger, or the name you used
double myHeading;
int readCount = 0;
String datalogFilename = "myDatalog_005"; // modify name for each run
ElapsedTime dataTimer; // timer object
int logInterval = 50; // target interval in milliseconds
@Override
public void runOpMode() {
// Get device from robot Configuration.
imu = hardwareMap.get(BNO055IMU.class, "imu");
// Initialize parameters and IMU.
imuParameters = new BNO055IMU.Parameters();
imuParameters.angleUnit = BNO055IMU.AngleUnit.DEGREES;
imuParameters.loggingEnabled = false;
imu.initialize(imuParameters);
// Instantiate Datalogger class. Edit name as needed.
imuDL = new W_Datalogger_v05(datalogFilename);
// Instantiate datalog timer.
dataTimer = new ElapsedTime(ElapsedTime.Resolution.MILLISECONDS);
// Name the fields (column labels) generated by this OpMode.
imuDL.addField("Count");
imuDL.addField("IMU Heading Angle");
imuDL.firstLine(); // end first line (row)
telemetry.addData("Datalogging Sample -- IMU Heading", "Touch START to continue...");
telemetry.update();
waitForStart();
// Reset timer for datalogging interval.
dataTimer.reset();
// Optional to reset log timers (columns 1 & 2) as data collection begins.
//imuDL.resetTime();
while (opModeIsActive()) {
if (dataTimer.time() > logInterval) {
angles = imu.getAngularOrientation(AxesReference.INTRINSIC, AxesOrder.ZYX, AngleUnit.DEGREES);
myHeading = angles.firstAngle; // store Z-angle or heading
readCount ++;
// Populate the fields to be logged. Must appear in the same order
// as the column headings, to ensure data is logged to the intended
// field name.
imuDL.addField(readCount);
imuDL.addField(myHeading);
imuDL.newLine(); // end the current set of readings
// Show live telemetry on the Driver Station screen.
telemetry.addData("Count", readCount);
telemetry.addData("myHeading", "%.1f", myHeading);
// Show IMU system status and calibration status.
telemetry.addLine();
telemetry.addData("IMU status", imu.getSystemStatus().toShortString());
telemetry.addData("IMU calibration status", imu.getCalibrationStatus().toString());
telemetry.update();
dataTimer.reset(); // start the interval timer again
} // end if(timer)
} // end main while() loop
imuDL.closeDataLogger(); // close Datalogger when finished
} // end runOpMode()
} // end class