Encoder for Java

Our robot is having problem about following a direct line. Therefore, we would like to use encoder. However, we are rookie team and we have a problem about how to code encoder for java. If you could help us, we would be greatfull.

What kind of drivebase are you using? Also what kind of encoder are you using?

The robot should drive fairly straight without an encoder. If it does not, it is very likely there is a mechanical issue such as an incorrect gearbox assembly, wheels rubbing on the chassis, or other unwanted sources of friction.

That said, encoders are still a good idea. Just make sure the electrical and mechanical teams have done their job correctly before trying to fix their mistakes in software.

Here is a link to the Java-based encoders tutorial.

Take a look at this example too. It has information about following a heading with a gyro. http://wpilib.screenstepslive.com/s/currentCS/m/java/l/599713-gyros-measuring-rotation-and-controlling-robot-driving-direction

I also want to get encoders for 2018. None of the example code I’ve found works, and the imports don’t work either (just like the Talons). I guess this has to do with the new framework for interfacing with sensors, but I didn’t find anything in the docs about encoders. Does anyone have example code for encoders for 2018?

Take a look at some of the example code for encoders here:
http://wpilib.screenstepslive.com/s/currentCS/m/java/l/599717-encoders-measuring-rotation-of-a-wheel-or-other-shaft

You can also create and deploy some examples from Eclipse. Just do File -> New -> Other -> WPILib Robot Java Development -> Example Robot Java Project. Those examples are hosted here: https://github.com/wpilibsuite/allwpilib/tree/master/wpilibjExamples/src/main/java/edu/wpi/first/wpilibj/examples

I fixed it!! Apparently you can’t import the encoder from anywhere but the Robot package. You can use a class like LakotaRobotics did for the encoder.

Here is their code (thank you to them): https://github.com/LakotaRobotics1038/2018Utilities