-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Datalogging
This Part 1 tutorial shows how to use a handy new FTC Datalogging tool: run a sample OpMode and chart its data.
Although aimed at OnBot Java users, these instructions allow Android Studio programmers to use the same Java code.
Datalogging can be made available to FTC Blocks users, by creating myBlocks in OnBot Java. MyBlocks are covered in a separate tutorial at the FTC Wiki here.
This tutorial is Part 1 of a 4-part series on FTC Datalogging. After running the sample OpMode and charting its data, see the end of this page for a link to Part 2: customizing the sample OpMode.
Many thanks to @Windwoes for developing this valuable tool.
Two Java files are provided here:
-
Datalogger.java is the Java class that handles all details of storing the robot data in a datalog file. A typical user will not need to review or edit this file. Its internal code is not described in this tutorial.
-
ConceptDatalogger.java is the sample OpMode that's run from the Driver Station as usual. It specifies and collects the robot data to be logged and ultimately charted. The OpMode uses, or calls, commands/methods provided in the Datalogger class. This is the file that can be edited by the user.
This tutorial shows how to run ConceptDatalogger "as is". Part 2 of this series shows how to customize the sample OpMode, to collect other robot data.
Attach a 12V robot battery and power switch to a Control Hub, and turn it on.
Or use an Expansion Hub with RC phone, and open the RC app -- later you will change one line of code from "Control Hub" to (for example) "Expansion Hub 1".
On a paired Driver Station device, open Configure Robot and verify that the active configuration contains "imu" on the Hub's I2C Bus 0. It's normally there by default. Any other hardware (motors, servos, sensors) may be present and configured, but are not used in this example.
That's it! The sample OpMode needs only this simple 'robot'. If your Hub is already mounted on a complete robot -- leave it there!
The data to be logged and charted will be generated from 4 sources:
-
Inertial Measurement Unit (IMU) built into the Hub
-
battery voltage detector in the Hub's controller
-
text codes created by the user
-
loop counter, generated by the running OpMode
The IMU is a physical sensor defined in the HardwareMap, like other sensors you might use later for Datalogging. The other 3 sources are examples of data generated by the SDK/controller, the user, and the user's code, respectively.
Use one of the following 3 ways to transfer the two provided files to the Control Hub or RC phone, to appear in OnBot Java.
For all 3 methods, first connect the laptop to the internet, and open this link in a new Chrome browser tab: Datalogger.java.
Sept. 2022 Update: For FTC SDK 8.0 or higher, change line 29 from this:
import org.firstinspires.ftc.robotcore.internal.opmode.OpModeManagerImpl;
to this:
import com.qualcomm.robotcore.eventloop.opmode.OpModeManagerImpl;
Method 1
Click the Raw
button at the right side, to open a page with raw text. Right-click anywhere and choose "Save as...". Change the "Save as type" from "Text Document" to "All Files". Navigate to the laptop's Downloads folder, then click the Save
button.
-
Next, do the same steps for this file ConceptDatalogger.java.
-
Now connect the laptop to the robot via Wi-Fi, as usual. In the Chrome browser, open OnBot Java. Click the Upload Files icon (green circle, below), to upload both Java files to the OBJ 'teamcode' folder (yellow oval, below).
Method 2
Click the icon for "Copy raw contents", located to the right of Raw
and Blame
. In a plain text editor (a good choice is Notepad++), open a New file. Paste the clipboard's stored code into that file, and save as Datalogger.java in the laptop's Downloads folder.
-
Next, do the same steps for this file ConceptDatalogger.java; save as ConceptDatalogger.java.
-
Now connect the laptop to the robot via Wi-Fi, as usual. In the Chrome browser, open OnBot Java. Click the Upload Files icon (green circle, below), to upload both Java files to the OBJ 'teamcode' folder (yellow oval, below).
Method 3
Click the icon for "Copy raw contents", located to the right of Raw
and Blame
. Now connect the laptop to the robot via Wi-Fi, as usual. In the Chrome browser, open OnBot Java. Click the large plus-sign to create a new file named Datalogger.java. Empty/delete all its contents, then right-click and Paste the clipboard's stored code into that file.
- Next, connect the laptop again to the internet. Do the same steps for this file ConceptDatalogger.java; name the new OBJ file ConceptDatalogger.java.
After completing one of the above methods, both files appear in OnBot Java and are stored on the RC device (Control Hub or RC phone).
If using an Expansion Hub with RC phone, change Line 40 in ConceptDatalogging.java from "Control Hub" to "Expansion Hub 1" (or other configured name for that Hub).
Click the wrench icon "Build Everything", wait for the message "Build Successful". Now the compiled versions of these files are also stored on the RC device.
-
On the Driver Station (DS), select the TeleOp OpMode listed as "Concept Datalogger v01".
-
With the Hub at rest, touch INIT on the DS screen.
-
When ready, touch the START arrow, then begin physically moving the Hub by hand.
-
Without disturbing its power or USB connections, carefully rotate the Hub clockwise or counter-clockwise, and tilt the Hub left-to-right, and top-to-bottom.
-
If your Hub is mounted on a complete robot, carefully rotate and tilt the entire robot.
-
Observe the live telemetry of IMU rotation angles on the DS screen. Do this for 5-10 seconds, then touch the STOP square on the DS screen.
-
Data collection is done! Click the Chrome browser's Refresh icon (curved arrow) to see the new log file listed in OnBot Java at the left side. The file "datalog_01.txt" is now stored in the RC device folder FIRST/java/src/Datalogs.
-
Optional to click the name "datalog_01.txt" to examine its contents in OnBot Java. The format is 'comma-separated values' or CSV, with headings in Row 1, followed by data rows.
Right-click on "datalog_01.txt" and choose Download -- then pause to read the next step.
During the download dialog, change the file extension from .txt
to .csv
. (If needed, change the "Save as type" from "Text Document" to "All Files".) This change allows the file to be automatically recognized and imported by spreadsheet programs. Navigate to the target folder on the laptop, and click "Save".
The downloaded CSV filename may appear at the bottom of the browser window.
On the laptop, double-click the CSV filename to automatically open it in the default spreadsheet program such as Microsoft Excel (if installed). Or, right-click and choose "Open with...", then choose Excel.
If you will do charting on a separate computer, first transfer the "datalog_01.csv" file from the laptop to that computer.
The file will open in Excel, showing the 7 columns and many rows of data. Click on any column heading (the letter, not the label) to select its data for charting. While pressing SHIFT
, click to select a range of columns (e.g. D - E - F). While pressing CTRL
, click to select multiple single columns (e.g. D and F).
Click the top menu item "Insert", circled above in yellow. Then click on the icon for charts (see green arrow). Then click the basic 2-D Line style, circled in blue.
This will insert a simple line graph of the selected data, as shown below.
That's it! You have successfully stored and charted data from an FTC robot.
-
If you "Save As..." Excel format, your original CSV file will not be affected.
-
Excel locks any open file. After charting and review, close Excel or the open CSV file as needed.
Excel offers many more data evaluation features, beyond the scope of this tutorial. You are encouraged to learn and explore those features, ultimately providing a better understanding of robot performance. This may help you with troubleshooting, optimization and robot design.
Connect the laptop to the internet. In a new Chrome browser tab, type "sheets.google.com". Then click the large plus sign in the lower right corner, as shown below.
This creates and opens a new untitled spreadsheet. As shown below in yellow, click "File", then "Import". Then click "Upload".
Drag the "datalog_01.csv" file from Windows Explorer to the rectangle shown, or click the blue "Select a file..." box to manually find and select the CSV data file.
For this example, the default settings are good, as shown by the yellow check-marks below. Click "Import data".
The file will open in Sheets, showing the 7 columns and many rows of data. Click on any column heading (the letter, not the label) to select its data for charting. While pressing SHIFT
, click to select a range of columns (e.g. D - E - F). While pressing CTRL
, click to select multiple single columns (e.g. D and F).
As shown below, click "Insert", then "Chart". This will insert a simple line graph of the selected data, as shown below.
That's it! You have successfully stored and charted data from an FTC robot.
At top left, type a filename to replace "Untitled spreadsheet". There's no "save" button; Sheets changes are automatically saved online.
Google Sheets offers many more data evaluation features, beyond the scope of this tutorial. You are encouraged to learn and explore those features, ultimately providing a better understanding of robot performance. This may help you with troubleshooting, optimization and robot design.
You will generally create multiple datalogs, which need different filenames. Here are two ways.
-
Recommended In OnBot Java, click on "ConceptDatalogger.java" to view its Java code. At line 43, change "datalog_01" to "datalog_02". Then click the wrench icon "Build Everything", wait for the message "Build Successful".
-
Alternate In OnBot Java, always Rename the latest datalog file. For example, right-click and Rename "datalog_01.txt" to "IMU angles - run 01.txt". After the next run, you will Rename "datalog_01.txt" to "IMU angles - run 02.txt".
Now re-run the OpMode:
-
On the Driver Station, select the OpMode again, still listed as "Concept Datalogger v01".
-
With the Hub at rest, touch INIT.
-
When ready, touch Start.
-
Manually move the Hub (or full robot) for 5-10 seconds, then touch Stop.
Now download and chart the new datalog:
-
Refresh the Chrome browser
-
Download the datalog, changing the file extension from
.txt
to.csv
.
-Open the datalog in Excel or Sheets
- Click the column headings, Insert a line graph
Now you have another set of charted robot data. Save and name the spreadsheet.
Repeat this a few times, until the process seems familiar. This will help with the next stage, customizing the OpMode to log your own data.
The sample OpMode logged data from other sources besides the IMU. Column B shows a text code based on user action, Column C shows a loop count generated by the running OpMode, and Column G shows battery voltage from the REV Hub.
For this data, you can experiment with other charting and reporting tools in your spreadsheet software (e.g. Microsoft Excel or Google Sheets). These alternate display methods are also considered Datalogging.
The next tutorial in this series shows how to collect data from motors, servos and sensors.
Teams using OnBot Java can use Datalogging to investigate problems and improve robot performance. Android Studio programmers can use all the same Java code described above. MyBlocks created in OnBot Java can make Datalogging available to teams using FTC Blocks.
FTC students will benefit from this valuable skill, widely used in professional fields such as engineering, scientific research, medicine, social media and marketing, business management, and many more.
You are encouraged to submit and describe other examples that worked for you.
========
This is Part 1 of a 4-part series on FTC Datalogging.
Part 2 shows how to customize the sample OpMode to log other robot data of your choice.
Part 3 shows Android Studio users how to transfer datalog files from the RC device to a computer. (This isn't needed with OnBot Java, where datalogs appear on-screen for easy Download.)
Part 4 describes the inner workings of a different, much simpler Datalogging class. It's strictly a Java learning exercise, showing basic steps to log robot data on the RC device. It does not require familiarity with Parts 1 and 2.
Questions, comments and corrections to [email protected]
-
TensorFlow 2023-2024