Encoder Sensing#
To make Optical Shaft Encoder blocks appear in VEXcode V5, a 3-Wire Shaft Encoder must be configured in the Devices window.
For more information, refer to these articles:
Set Shaft Encoder Position#
The Set Shaft Encoder Position block is used to set the Shaft Encoder’s position to the given value.
set [EncoderC v] position to (0) degrees
Choose which Shaft Encoder to use.
In this example, the Shaft Encoder will print its starting position, set its position to 90 degrees, and then print the new position.
when started :: hat events
print ([EncoderC v] position in [degrees v]) on [Brain v] ◀ and set cursor to next row
set [EncoderC v] position to (90) degrees
print ([EncoderC v] position in [degrees v]) on [Brain v] ◀ and set cursor to next row
Shaft Encoder Position#
The Shaft Encoder Position block is used to report the distance the Shaft Encoder has rotated.
([EncoderC v] position in [degrees v])
Choose which Shaft Encoder to use.
Choose which unit to report in: degrees or turns.
In this example, the Shaft Encoder will print its starting position, set its position to 90 degrees, and then print the new position.
when started :: hat events
print ([EncoderC v] position in [degrees v]) on [Brain v] ◀ and set cursor to next row
set [EncoderC v] position to (90) degrees
print ([EncoderC v] position in [degrees v]) on [Brain v] ◀ and set cursor to next row
Shaft Encoder Velocity#
The Shaft Encoder Velocity block is used to report the current velocity of a Shaft Encoder.
([EncoderC v] velocity in [dps v])
Choose which Shaft Encoder to use.
Choose which unit to report in: degrees per second (dps) or rotations per minute (rpm).