Created
March 21, 2025 01:47
-
-
Save yabberyabber/33d0b93900e07a25ae24f64a511eb530 to your computer and use it in GitHub Desktop.
Task sequence for MotorDraw branch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The eventual goal here is to have a gradle task to automatically calcualte power draw for every | |
motor after every match. The sequence will look like this: | |
- After a match, the robot comes back into pit | |
- The pit programmer runs `./gradlew fetch-and-analyze-log` | |
- That task downlaods the latest match log | |
- That task scans through the match log and, for every motor, calculates the power draw in watt-hours, amp-hours, and volt-hours | |
Example output might look like this: | |
``` | |
Motor draw from match E12 | |
Conveyor | |
32 Watt-Hours | |
301 Stator Amp-Hours | |
32 Supply Amp-Hours | |
102 Volt-Hours | |
Mod0 drive | |
300 Watt-Hours | |
2000 Stator Amp-Hours | |
1002 Supply Amp-Hours | |
4000 Volt-Hours | |
Mod0 Steer | |
blah blah blah | |
``` | |
This is a big pull so we're going to break it up into smaller steps, starting with the original MotorDraw.java | |
which just prints out every logged metric. | |
### Filter on name | |
Eventually we're going to be looking for many motors but for now let's focus on the conveyor. | |
Patch MotorDraw so that, instead of printing out everything that was logged during the whole match, we | |
just print out when /Robot/robot/claw/conveyorMotor/Stator Current or /Robot/robot/claw/conveyorMotor/Voltage | |
was logged. You will check the `data.name` attribute for this. | |
### Sum them up | |
Instead of just printing out the log lines, let's do some math with them. We're going to sum up all | |
of the conveyor stator current and voltage samples and print the sum at the end. We no longer care about | |
individual entries --- just the sum that we get at the end. | |
Note that this data gets logged every 20ms so we need to account for that. Your code is going to need to | |
multiple every sample by `0.02` to correct for that. Units are tricky business. You'll end up with something | |
like this: | |
``` | |
double totalAmpSeconds = 0.0; // declare once at the top | |
for (DataLogRecord record : reader) { | |
// blah blah blah skip the metadata records | |
if (record.name.equals("/Robot/robot/claw/conveyorMotor/Supply Current") { | |
totalAmpSeconds += record.getDouble() * 0.02; | |
} | |
} | |
system.out.println("Total AmpSeconds: ", totalAmpSeconds) | |
``` | |
### More unit conversion | |
AmpSeconds and VoltSeconds aren't common units --- let's turn those into AmpHours and VoltHours by dividing by 3600. | |
### Also track WattHours | |
WattHours is probably the most important thing to calculate here. The wattage any any moment in time is the | |
voltage multiplied by the amperage. Note that we need to multiple the voltage by the wattage for every point | |
and add up those products. This is very different from multiplying totalAmpSeconds by totalVoltSeconds. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment