How to use Brake Mode and Limit Switches for TalonSRX


#1

Hello,
My team this year has an elevator system and if the elevator reaches the top position it begins to fall down due to gravity. In the Phoenix Tuner I made the Talons to Brake Mode. Is that all I have to do or do I need to add code. Also we have a limit switch at the bottom. So that when it hits the bottom I can clear all of the encoders, how would I add that in the code. I can’t find any examples online. Help is appreciated!

Thanks


#2

The brake mode will only slow the elevator but not stop it. You can command the Talon SRX to always give a constant amount of power to the elevator which needs to be equal to the weight of the elevator – use ArbitraryFeedforward for it.

To add the limit switch, use configForwardLimitSwitchSource or configForwardLimitSwitchSource (IIRC it depends on what port in the Talon SRX you insert the sensor). If this limit switch is pressed, the Talon SRX will automatically stop giving power.
To reset the encoders, we run an update() loop which calls setSelectedSensorPosition and resets the encoder to 0.

If you have additional questions please ask here.


#3

HI, I am facing the same problem as well. Rather than providing it with a constant power supply, I believe velocity PID should do the trick. Both methods should work.


#4

A velocity pid is not necessarily the right tool in this case. The elevator will slowly drift downward as the velocity tries to stay at zero. Position PID is a simple option, but motion magic is your best option.


#5

My mistake, I meant to stay position PID.


#6

Thanks for the replies. I also have one more concern. I recently accidentally changed the Start Up settings for the RoboRio by going to the 172.22.11.2 . On the Enable Secure Shell Server (sshd) I accidentally unchecked it and now I can no longer check it again. I check it and press save but it goes back to unchecked once I referesh it. Becuase of this I cant run code on the RoboRio anymore. Help would be greatly appreciated.


#7

configClearPositionOnLimitF / configClearPositionOnLimitR can be used to tell Talon/Victor to auto-zero the position register. Tuner also has the same configs for manual tweaking.

You want motion magic + arbFeedFwd.
This is a similar example

Re-image the RIO.

We had a customer run into this, and had to root-cause it ourselves. That checkbox is broken, once you uncheck sshd, no action will restore it. So don’t press it after you re-image.


#8

How do you use Motion Magic. I am reading all this PID stuff but getting quite confused. Could you perhaps show an example of it in C++. Like if I wanted it to go up 5000 and stay there what would I have to do.


#9

I don’t have a C++ example, but the API calls will be the same (but for Java). You need to configure the Talon with PID constants following the guide here.

Once you have the basics down, you can just use ControlMode.MotionMagic to set your elevator to a certain encoder value (e.g. 5000).

The problem in the OP was that once the elevator hit the target (say 5000 encoder ticks) then gravity was taking over. Which where the feed-forward constant comes in to play. You need to add in enough voltage input to maintain the elevator against gravity (some decimal number that you have calculated, or just observed empirically).

The linked example shows you how to add an auxillary feed forward term, and if you’re looking for more concrete code as to how to just use MotionMagic in general there are a lot of examples but feel free to browse through our Github to see a Java implementation. You’ll see the calibration values we derived, and the Talon configuration steps we use in the DriveTrain subsystem constructor as well as the DriveMM command class that drives our robot a certain distance using MotionMagic.


#10

Hi there, thanks for the reply. So if I am to calculate and find out what the P and I values are what would I do from there. Would I just do

ControlMode.MotionMagic(5000)??

Reply would be appreciated.


#11

Like I am reading about Closed Loop. Would that work for me. I have gone to the Phoenix Tuner and entered the P the I and the Feed Forward. Everything else to 0. What would I do from here to lets say get the elevator to go up 5000 ticks.


#12

Yes, but you need to configure the PIDF gains first.


#13

It’s really important you follow the CTRE instructions, don’t skip steps. If you got this far without doing all the bring-up procedures I would recommend you go back and confirm that you are properly setup.

Once you have properly brought up the Talons, and ensured the sensor phase is proper, then you need to start following the steps toward getting your MotionMagic calculated.

Note in the code in our Github that I linked for you, there are some magic constant values being assigned to the closed loop slot for our MM commands (kF, kP, kD, kI). You need to do the calculations, and then the tuning of those values before you need to worry about just setting the set points.

Once you have the values calculated according to those steps (don’t skip any of them), then you can just set the motors by calling talon.set(ControlMode.MotionMagic, set_point)


#14

Yes so I have gotten the values. Do I need to put them in code or can I just add them onto the Phoenix Tuner for both Talons used in the elevator. Also the talon.set(ControlMode.MotionMagic, 5000) is java right. For C++ would it be like talon->Set(ControlMode::MotionMagic, 5000) or something.


#15

Yes, for C++ it would indeed be ControlMode::MotionMagic instead.


#16

Thanks for all your help NewtonCrosby. It is a Snow Day here today so I havent been able to test the code but just to clarify. The P and I can be calculated and the Feed Forward all are entered into the Phoenix Tuner to both of the Talons used in the elevator. From there I use the ConrtrolMode::MotionMagic, 5000. To move up 5000 ticks using the PID values?


#17

I highly recommend to do so. If you replace the Talon SRX with another Talon SRX, you just need to re-deploy your code and all your configs will be updated in the new Talon SRX. If you don’t write the configuration in code, you’ll need to replace all constants by yourself in Phoenix Tuner.


#18

https://phoenix-documentation.readthedocs.io/en/latest/ch13_MC.html#configuration

Tuner can be used to get/set/export/import the configs.

However, it is highly recommended to ultimately set them via the software API . This way, in the event a device is replaced, you can rely on your software to properly configured the new device, without having to remember to use Tuner to apply the correct values.

A general recommendation is to:

  • Configure all devices during robot-bootup using the API,
  • Use Tuner to dial values quickly during testing/calibration.
  • Export the settings so they are not lost.
  • Update your software config values so that Tuner is no longer necessary.