From 266ed7d566106f486ebba4632fa94634e8034dd2 Mon Sep 17 00:00:00 2001 From: SriramKalki <79238833+SriramKalki@users.noreply.github.com> Date: Tue, 17 Oct 2023 17:01:07 -0500 Subject: [PATCH] replaced motor.getPosition() with motor.getCurrentPosition() in sample code (#401) --- source/docs/software/tutorials/bulk-reads.rst | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/source/docs/software/tutorials/bulk-reads.rst b/source/docs/software/tutorials/bulk-reads.rst index 25a48d23..f2bb96a4 100644 --- a/source/docs/software/tutorials/bulk-reads.rst +++ b/source/docs/software/tutorials/bulk-reads.rst @@ -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 :: @@ -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. @@ -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.