Examples
Use-Case
Code Example
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?