Examples

Use-Case

This example program demonstrates how to use the AndyMark FRC Hex Bore Encoder in an FRC robot program. It initializes the encoder from the robot’s configuration and continuously reads position data while the robot is enabled. The program can report the encoder’s absolute position through multiple output options — CAN, PWM, and analog — so teams can choose the interface that best fits their robot wiring and control system. It also shows how the encoder’s zero/reset button can be used to set the current shaft position as 0 (useful for quickly re-indexing mechanisms like arms, turrets, or elevators during setup). The measured position values are then displayed on the Driver Station in real time, allowing users to verify the encoder is installed correctly, confirm direction/offset behavior, and troubleshoot signal integrity or mechanical alignment. This example is useful for quick bring-up and testing, and it can be used without needing in-depth programming knowledge.

Code Example

To use this encoder via CAN, you must first install the AndyMark vendor libraries. Instructions can be found here

View Device API for a comprehensive list of commands

import com.andymark.jni.AM_CAN_HexBoreEncoder;
import com.andymark.jni.AM_CAN_HexBoreEncoder.AM_EncoderStatus;
import com.andymark.jni.AM_CAN_HexBoreEncoder.AM_Encoder_Telemetry;

//Initialize Device
//The device's default CAN is 0. Change it using AndyMark CAN interface utility
AM_CAN_HexBoreEncoder hexEncoder = new AM_CAN_HexBoreEncoder(0);
//Reset Report Period to the default of 10ms
hexEncoder.resetReportPeriod();

//This will set the 0 of the encoder to the current position
hexEncoder.setZeroHere();

//All data the HexBore Encoder provides can be retrieved by using these two lines
AM_Encoder_Telemetry telemetryData = hexEncoder.getTelemetry();
AM_EncoderStatus statusData = hexEncoder.getStatus();

//Retrieves position and velocity in terms of degrees and degrees per second
double degrees = hexEncoder.getAngleDegrees();
double degreesPerSec = hexEncoder.getVelocityDegPerSec();
SmartDashboard.putNumber("angleDegrees", degrees);
SmartDashboard.putNumber("Velocity (DegPerSec)", degreesPerSec);

Last updated

Was this helpful?