Using Talon closed loop position mode

Hi

We are using motion profiling to move elevator to position, but then want to hold position once there.

We are setting the Talon into ControlMode.Position, using this code:


        double curPosn = mTalon.getSelectedSensorPosition(0);
        mTalon.set(ControlMode.Position, curPosn);

The talon seems to be holding, but we can move the elevator away from this point and it does not go back.

Have we misunderstood the Position mode, or are we doing soemthing incorrect?

Regards

David

Have you tuned the PID constants? It won’t apply any gain to reduce the error from that position if your PID constants are zero.

The Talon SRX Software Reference Manual has a guide on tuning position PID. You should also get a little bit of theoretical background on PID before you jump into it. The FRC-PDR site has a good intro here.

Assuming that this code is called in some forum of periodic loop, your code is repeatedly setting the target position at whatever the current position is, meaning that there is never any error calculated. You need to set one position that you calculate as your target, store it as a variable, and don’t change it until you want to move again.

1 Like

Thanks for the responses

@nick - yes, we have been playing with kP, other params are 0. Possible we have not moved kP far enough - will be more adventurous tomorrow.

@soundfx - good thought, but the code is only being called once, when the motion profile is completed. We are attempting to switch form motion profile mode to hold position mode. Should we in fact be calling the set repeatedly?

We are using the Talon Magic Motion feature to get our elevator to a position. I’m pretty sure we have the P and K set to .2 and I and D set to 0 and it seems to work pretty well. We have a CIM with a 25:1 versaplanetary gearbox moving it.

@rlance - thanks for the reply

Does the system hold position once it reaches it?

The issue we are concerned with is holding the position of the elevator steady once the target position is reached.

Does the last point in your motion profile have isLast set to true? Setting isLast to true will make the Talon hold the final point (the point marked isLast) until you tell it not to.

That is interesting - did not realize that. Yes, we have it marked as isLast.

Following the examples on GitHub, we had been changing the mode of the talon at the end of the profile. So do you just leave it alone?

We will test this later today.

Have you looked at the Talon self-test mode to determine if it is in fact in position mode, what error it is seeing, and what, if at all, output it is giving?

You mean via the web interface? No had not tried that - will do so. Thanks

So your understanding is that it should maintain position against disturbance, without us repeatedly calling?

Yes, it holds the position. It is possible that our elevator weight or gearing or friction helps with that because when power is cut to the system it lowers on its own at a fairly slow pace.

Thanks - will let you know how we go

My team is trying to use Talon SRX and manetic Encoder to control the scissor lift in a position close loop. The encoder can send the position correctly through the smart dashboard and the talon can drive normally as well. But the set(ControlMode.position, targetPosition) function will not move.

/*
		 * Scissor lift on POV levels POV 0: loweest (pick up, vault running) POV 90:
		 * switch level POV 180: scale (highest 6ft) POV 270: climb
		 */
		if (operator.getPOV() == 0) {
			leftScissor.set(ControlMode.Position, 0);
			SmartDashboard.putString("Scissor Lift", "Ground Level");
		} else if (operator.getPOV() == 90) {
			leftScissor.set(ControlMode.Position, SWITCH * 4096.0);
			SmartDashboard.putString("Scissor Lift", "Switch Level");
		} else if (operator.getPOV() == 180) {
			leftScissor.set(ControlMode.Position, SCALE * 4096.0);
			SmartDashboard.putString("Scissor Lift", "Scale Level");
		} else if (operator.getPOV() == 270) {
			leftScissor.set(ControlMode.Position, CLIMB * 4096.0);
			SmartDashboard.putString("Scissor Lift", "Climb Level");
		}

I’m having the same problem. Have you figured out why?

Can you submit your code in a GitHub repo?

Did you follow the CTRE steps exactly to bring up your CAN, TalonSRX and Sensor phase calibration?

If so, when you try to set the position do the Talon LEDs blink in any certain way? Red, Green, alternating red?