Class BulkReads
Without this, each encoder read is a separate message to the hub (about 2 ms each). With bulk reads, the first read in a loop gets everything from the hub in one message. This often doubles the loop speed.
Words used here: a "hub" is the Control Hub or Expansion Hub, the box the motors and
sensors plug into (the SDK calls it a LynxModule). An "encoder" counts how far a motor
has turned. The "cache" is the hub's saved copy of the last bulk read: reads use the saved
copy until it is cleared, so they are fast but only as new as the last bulk read.
// Easiest: one line in INIT. A new bulk read happens when you read any value a second time.
BulkReads.auto(hardwareMap);
// Fastest: you clear the cache yourself at the top of each loop.
List<LynxModule> hubs = BulkReads.manual(hardwareMap);
while (opModeIsActive()) {
BulkReads.clear(hubs);
...
}
Tutorial 06 (docs/tutorials/06-fast-clear-loop.md) shows this in a full program.
Docs: docs/modules/hardware.md-
Method Summary
Modifier and TypeMethodDescriptionstatic List<com.qualcomm.hardware.lynx.LynxModule> auto(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap) Turns on AUTO bulk reads on every hub.static voidClears the cached readings so the next read gets new values.static List<com.qualcomm.hardware.lynx.LynxModule> manual(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap) Turns on MANUAL bulk reads on every hub.
-
Method Details
-
auto
public static List<com.qualcomm.hardware.lynx.LynxModule> auto(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap) Turns on AUTO bulk reads on every hub. Safe default. Call once in INIT.In AUTO mode the hub does a fresh bulk read on its own when you read the same value a second time, so you can never get stuck with old readings.
- Parameters:
hardwareMap- the OpMode'shardwareMap- Returns:
- the list of hubs (you only need it if you later switch to
manual(com.qualcomm.robotcore.hardware.HardwareMap))
-
manual
public static List<com.qualcomm.hardware.lynx.LynxModule> manual(com.qualcomm.robotcore.hardware.HardwareMap hardwareMap) Turns on MANUAL bulk reads on every hub. You MUST callclear(java.util.List<com.qualcomm.hardware.lynx.LynxModule>)once per loop, or the readings never change.Why use it? It is the fastest: exactly one bulk read per hub per loop. The danger: if you forget
clear(java.util.List<com.qualcomm.hardware.lynx.LynxModule>), the robot keeps seeing the same old encoder and sensor numbers, so a lift would never "see" itself move.- Parameters:
hardwareMap- the OpMode'shardwareMap- Returns:
- the list of hubs: keep it and pass it to
clear(java.util.List<com.qualcomm.hardware.lynx.LynxModule>)every loop
-
clear
Clears the cached readings so the next read gets new values. Use withmanual(com.qualcomm.robotcore.hardware.HardwareMap). Call it once, at the top of every loop, before anything reads a sensor or encoder.- Parameters:
hubs- the list thatmanual(com.qualcomm.robotcore.hardware.HardwareMap)gave you
-