Skip to content

Commit

Permalink
replaced motor.getPosition() with motor.getCurrentPosition() in sampl…
Browse files Browse the repository at this point in the history
…e code
  • Loading branch information
Srinikal authored Oct 17, 2023
1 parent adec367 commit af646b1
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions source/docs/software/tutorials/bulk-reads.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ This is the simplest mode to use that utilizes bulk reads; a new bulk read is do

while (opModeIsActive()) {
// Will run one bulk read per cycle; however, if e.g.
// frontLeftMotor.getPosition() was called again,
// frontLeftMotor.getCurrentPosition() was called again,
// a new bulk read would be issued
int frontLeftEncoderPos = frontLeftMotor.getPosition();
int frontRightEncoderPos = frontRightMotor.getPosition();
int backLeftEncoderPos = backLeftMotor.getPosition();
int backRightEncoderPos = backRightMotor.getPosition();
int frontLeftEncoderPos = frontLeftMotor.getCurrentPosition();
int frontRightEncoderPos = frontRightMotor.getCurrentPosition();
int backLeftEncoderPos = backLeftMotor.getCurrentPosition();
int backRightEncoderPos = backRightMotor.getCurrentPosition();
}

However, this can be problematic, if the same hardware read is called more than once in a given loop; an example of this ::
Expand All @@ -53,9 +53,9 @@ However, this can be problematic, if the same hardware read is called more than

while (opModeIsActive()) {
// Will run two bulk read per cycles,
// as frontLeftMotor.getPosition() is called twice
int frontLeftEncoderPos = frontLeftMotor.getPosition();
int frontLeftEncoderPos2 = frontLeftMotor.getPosition();
// as frontLeftMotor.getCurrentPosition() is called twice
int frontLeftEncoderPos = frontLeftMotor.getCurrentPosition();
int frontLeftEncoderPos2 = frontLeftMotor.getCurrentPosition();
}

Overall, this is recommended, as it is very unlikely to mess anything up and can give significant performance improvements for little effort. On the user side, one does not need to manually flush the bulk read cache; however, this means you lose some control.
Expand All @@ -73,15 +73,15 @@ In manual mode the cache for bulk reads is only reset once manually reset. This

while (opModeIsActive()) {
// Will run one bulk read per cycle,
// even as frontLeftMotor.getPosition() is called twice
// even as frontLeftMotor.getCurrentPosition() is called twice
// because the caches are being handled manually and cleared
// once a loop
for (LynxModule hub : allHubs) {
hub.clearBulkCache();
}

int frontLeftEncoderPos = frontLeftMotor.getPosition();
int frontLeftEncoderPos2 = frontLeftMotor.getPosition();
int frontLeftEncoderPos = frontLeftMotor.getCurrentPosition();
int frontLeftEncoderPos2 = frontLeftMotor.getCurrentPosition();
}

.. warning:: When in ``MANUAL`` mode, if the cache is not cleared appropriately, stale values will be returned. For that reason, if you are not quite sure what you are doing, we recommend ``AUTO`` mode; while ``MANUAL`` mode can have some performance improvements if ``AUTO`` mode is not used optimally, it has less room for catastrophic error.
Expand Down

0 comments on commit af646b1

Please sign in to comment.