Log in

View Full Version : Talon SRX Closed Loop


ram112358
30-01-2016, 01:11
I'm having some troubles getting a closed loop position control loop set up running on a talon SRX. I'm using Java and after searching on delphi and else where I can't seem to find a solution for my problems.

I'm trying to use the closed loop position control function that runs on the Talon SRX. I've read any documentation I can find on it and I'm certain that I have the encoder plugged in correctly to the breaker board. The code is currently set up to run off of half of our tank drive from last year to be sure there is no damage done to our lifter. We are using the new KOP router and the RoboRIO was flashed at the beginning of build season with the latest image and all the talons have the newest firmware as well.

With my code (attached) I can run the "lifter" off a joystick and watch the encoder value change as I do so. When I press the button to run my command that should run the pid functionality and through the RoboRIO web interface I can confirm that the Talon goes into closed loop position mode and that my PID values are actually sent to the Talon. However, when I push said button the "lifter" just runs full speed forward regardless of the relation between the value of the encoder and the set value.

Is there any insight you can give me into this or what's going on or resources where I can learn more about how to address this problem?

Thanks in advance for your help.

Link to zip of project: https://drive.google.com/file/d/0B320rMoBIwxrUUpmVmN0SWdnMlU/view?usp=sharing

jkoritzinsky
30-01-2016, 01:19
Are you sure the encoder is wired up correctly? This sounds like a runaway system, which would happen if you have your A and B channels swapped. That would cause the motor to move faster and faster away from the setpoint because it keeps trying to get closer but it is getting farther away.

ozrien
30-01-2016, 02:06
Talon SRX Software Reference Manual
http://www.ctr-electronics.com/talon-srx.html#product_tabs_technical_resources

Please read section 7.4 to make sure your sensor and motor is in-phase.
Use reverseSensor() if sensor and motor is not in-phase.

ram112358
30-01-2016, 15:00
I double checked and the encoder is wired in correctly and the are in-phase. I noticed that the pid button did the same thing regardless of whether or not the encoder is plugged in (but when it is plugged in I am able to access the value of the encoder through both the web interface and the smartdashboard)

ozrien
30-01-2016, 15:07
Grab a screenshot of the roboRIO-web-based config Self Test when the closed-loop is misbehaving. That will indicate what the Talon is doing and why.

Do a P-gain only closed loop to make debugging simpler (if you haven't already).

ram112358
30-01-2016, 17:13
Here's the screen shot you asked for. Would a P-gain only loop be setting a value (such as 0.1) to P and 0 for the rest of them? That is how it is set up currently.

ram112358
30-01-2016, 17:28
I also notice that the closed loop error value only seems to increase when I trigger the pid command, any thing else only seems to have no effect on that number.

ozrien
30-01-2016, 17:36
The selected Sensor Velocity (-439.57) is negative while the appliedThrottle is positive (100%).

This means the sensor and motor is NOT in-phase.

As a result, the ClosedLoopErr is moving away from zero the more the motor-drives.

Please look at Section 7.4 more closely, and use the reverseSensor() function to adjust the sensor direction so that positive drive moves the position in a positive direction. (Section 7.3).

ram112358
30-01-2016, 18:42
Ok turns out I accidentally posted that screenshot whike running code that had the reverseSensor() implemented, I knew that they were in-phase but I wanted to see what that function did on a whim and forgot I was running that version of the code. Another thing I realized was that I was setting the desired pid value to 1000 (a mentor and I didn't know that the encoder values are scaled) and so the whole time I was trying to run my code the robot was trying to reach an insanely high encoder value.

Thanks for all your help, we just need to figure out how the scaling works now.

Also, this is the code I was running, what I linked earlier was an archive of my projects (which you might have realized included this project)
https://drive.google.com/file/d/0B320rMoBIwxrWnpWN0dPN1hVZXM/view?usp=sharing

ozrien
01-02-2016, 02:51
Looking at the screenshot, you must have called ConfigEncoderCodesPerRev(360) because the CPR is updated in your self-test results. That means you are meeting the requirements in Section 17.2.1.

So that means setting soft limits, getting sensor velocity, getting/setting sensor position, and setting target position/velocity are all done in rotations/RPM and not native units. It's better explained in Section 17.2.2

If you don't call ConfigEncoderCodesPerRev() than everything goes back to native units (like last year - see Section 17.2 for details).