Java Example
Introduction
This is a simple Java example demonstrating how to use the Vertos Encoder with the CANSense interface in an FRC robot project
Code Breakdown
Import the CANSense Library
import com.vertos.encoder.CANSense;
- Allows communication with the Vertos Encoder over CAN.
Declare the Encoder Instance
private CANSense sensor1;
- Creates an instance of CANSense to interact with the encoder.
Initialize the Encoder
sensor1 = new CANSense(0, false);
- Instantiates the encoder with CAN ID 0 and debug mode disabled.
Read Encoder Data Periodically
sensor1.readMultiTurnCounts();
- Fetches the latest multi-turn count from the encoder.long position = sensor1.getMultiTurnCounts();
- Retrieves the current position in multi-turn counts.
Output Encoder Data
System.out.println("Encoder Position: " + position);
- Prints the encoder's position to the console for monitoring.
Code
Last updated