Optical Shaft Encoder Programming Help

I am planning to use the optical shaft encoder to travel accurate distances and make accurate turns during autonomous this year. I have no idea how to program the shaft encoder and was wondering if anyone has any code I could use for this sensor.

You’re talking integrated motor encoder external quad encoder?

external quad encoder, sorry

Here’s a topic you could read which might help you:

What you’re asking for is generally know as odometry. It’s present in FRC and VRC, you can look for others code and adapt it.

If you’re using an external quad encoder, don’t do it. It is a waste of ports. Instead, use the IME (integrated motor encoder). They serve the same purpose as an external encoder given that there is minimal wheel slippage. External quad encoders were primarily for v4 in which they were necessary to track the robot’s position. If you move your robot at a slow rate, the wheel slippage will be minimal. You can also use a gyro to account for any variances in the robot’s orientation.

You’re going to want to learn how to create a very simple yet effective P-Loop and you’ll be golden for autonomous. What @meepmeepme suggested is for advanced programming and I would not dive into that very difficult road for autonomous especially for novice programmers. If you have any questions, feel free to ask. I can further explain why you don’t need external quad encoders as well. Don’t just use a sensor because another team used it without knowing WHY.

I am very familiar with the integrated motor encoder. And I think you’re right that I should just use those for now. Besides, I am low on ports with potentiometers and limit switches anyway. Thanks for the help!

No problem. Also important to note, after P-loops, the next step is PD controllers and then PID. You’ll get more and more accurate after each iterative phase in coding. Slew rate control will effectively eliminate start up wheel slippage while the P(ID) controller will eliminate deceleration slippage.