How to program encoders for elevator using Java

Hello,
I am a relatively new programmer for FRC and I want to know how to program the elevator of a robot to reach a certain height using encoders with TalonSRXs. I tried researching about encoders along with PIDControllers and such in order to do this; however, I am still stumped on how to incorporate these into code and the logic behind them. If anyone can show me code on how their team was able to accomplish this, it would be greatly appreciated!

As I understand it, the basic problem: Create a mechanism, sensor system, and software to cause an elevator to move between preset heights.

There’s multiple parts to a complete answer.

FIrst, I would take some time to understand how closed-loop control algorithms work. Understanding the why will make the how much easier to work with.

The super short version:
An encoder will measure the actual position of the elevator.
The driver will provide a desired position for the elevator.
If you subtract these two position numbers, you get the error in position.
The motor command is produced by some math on error and desired.
For correctly-designed math, over time, the actual position will approach the desired position.

Here’s a longer version, Part 1, Part 2, Part 3, Part 4, and Part 5. For instant gratification skip straight to Part 5, it covers a mechanical scenario similar to the one I think you care most about.

Secondly: pick an appropriate combination of motor, motor controller, sensor, gearbox, etc. to achieve your goal. There’s a lot of possible right answers here.

Two possible examples:

Here’s our 2018 elevator control code. It used a Spark, miniCim, versaplanetary gearbox (with encoder slice), limit switches at the upper and lower mechanical travel limits, and supported both open and closed loop control. The control algorithm was bang-bang, rather than PID.

Here’s the Talon SRX’s example code for closed-loop position control. In particular, here is the line where the SRX is configured to use an encoder as the feedback (actual position-measuring) device.

1 Like

Thank you for your fast response! I’ll let you know if I have any more questions

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.