Java Help

Hello guys, I’m looking for some help on how to properly do setpoints and PID and the like. Currently, I’m using a fairly long if/else statement and it’s fairly jittery (which I’m aware just going to a setpoint style system won’t immediately fix), and it’s quite difficult to logically think through all of the “x == true && y == true && u.get(); > 120” and I’m hoping to remedy that with PID, alas I know literally 0 about it. Any help is much appreciated

Code here: https://github.com/BenFRC5147/5147-2019-Competition-Project/blob/9af82952c77485dd4596336aa8f4342ee0ae6e95/src/main/java/frc/robot/Robot.java#L192

I would suggest you to use the Ctre library since you are using Talon SRX’s. You can find closed loop position code here https://github.com/CrossTheRoadElec/Phoenix-Examples-Languages/blob/master/Java/PositionClosedLoop/src/main/java/frc/robot/Robot.java

Are there any examples with talon closed loop being used with a potentiometer? It appears the some of the references in the SRX’s software reference manual don’t work anymore, such as

motorController.setFeedBackDevice(FeedbackDevice.AnalogPotentiometer);

Also, to use this would I not have to wire the Pot to the SRX itself?

Looking at your code, you have effectively implemented a feedback controller already, with a piecewise-defined transfer function from position to command.

Here’s the way to start thinking about PID in your case:

  1. Send appropriate P/I/D gains to the Talon.
  2. Use joystick/operator buttons to calculate a “desired” position for each dart.
  3. Pass that desired position to the SRX’s
  4. Let the SRX do the work of commanding motor output to get to your desired position.

Start with having a fundamental understanding of what PID control is and why/when it works well: https://frc-pdr.readthedocs.io/en/latest/control/pid_control.html

After that, CTRE has some docs on using PID with their products: https://phoenix-documentation.readthedocs.io/en/latest/ch16_ClosedLoop.html

Finally, there is some example code from CTRE: https://github.com/CrossTheRoadElec/Phoenix-Examples-Languages/tree/master/Java/PositionClosedLoop

Yes, I posted CTRE’s example to help Benjamin.

How would I wire the potentiometer to the Talon? which data port pins? Or would I need to use one of the breakout boards?

I’ve never used the breakout boards, but a potentiometer should work with it. We usually just use the Mag Encoders.

We’ve used a couple different type of breakout boards, yes you’ll probably want one. https://www.ctr-electronics.com/Talon%20SRX%20User’s%20Guide.pdf has the wiring diagram on page 18 for hooking up a potentiometer. I’ve never tried to read it in software though, so I’m not sure what units or function calls are needed to “hook it up” as the input to the PID.

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