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

  1. Import the CANSense Library

    • import com.vertos.encoder.CANSense; - Allows communication with the Vertos Encoder over CAN.

  2. Declare the Encoder Instance

    • private CANSense sensor1; - Creates an instance of CANSense to interact with the encoder.

  3. Initialize the Encoder

    • sensor1 = new CANSense(0, false); - Instantiates the encoder with CAN ID 0 and debug mode disabled.

  4. Read Encoder Data Periodically

    • sensor1.update; - Fetches the latest data from the CAN bus.

    • long position = sensor1.getSingleTurnRotations(); - Retrieves the current angle between 0 and 1.0.

  5. Output Encoder Data

    • System.out.println("Encoder Position: " + position); - Prints the encoder's position to the console for monitoring.

Main.java

Last updated