Need CAN Basics!

Hey guys, I have absolutely no idea where to start with coding CAN. Could somebody give me the basics of how to code CAN in java? I couldn’t find where to start.

What are you trying to do specifically? You don’t “code CAN”, you can code devices that use CAN to communicate though. What devices and what vendor are you trying to use. For example: the Spark Max from REV Robotics can use CAN to be controlled.

You simply connect the device to the CAN bus and depending on vendor, CTR Electronics (CTRE) you use their Phoenix Tuner application, or for REV Robotics you use their REV Hardware Client to assign a CAN id to the device.

Creating your Test Drivetrain Program (C++/Java) — FIRST Robotics Competition documentation (

Take a look at this and see if it is helpful to you. It has some examples.

1 Like

More from our good friend the WPILib documentation

1 Like

Great, this is what I needed! Thanks. Also, how could you get the “position” of the motor from its encoder using CAN? Specifically from the Falcon 500 motor?

1 Like

You can find that stuff out of the falcon 500 here: Overview (CTRE Phoenix Java 5.30.4)

I wasn’t able to find specifically how to get position. I was able to find sparkmax position but im not sure how to navigate the talon documentation.

So first you need to figure out which API you’re using, if you are using v5 or Pro I recommend you upgrade to v6, you can then use the below link to check out the documentation, API and examples:

Examples Specific to what you’re looking for if using v5:

1 Like

As of 2023 you would do this:

// Declaration of the motor.
private final WPI_TalonFX motor = new WPI_TalonFX(1);

// Getting the position from the motor's encoder.
1 Like