How to display motor speed for PID Tuning

Hi guys. I’m trying to tune my PID system for my shooter and I want to use SmartDashboard to find the right values. However, in the PIDTestSystem, while I can change the values and see the result in the motor, I can’t see the speed of the motor. I put the PID type as Rate, but it still won’t show. Any ideas how I can view the speed of how fast the motor shaft is spinning? I can’t seem to write it to smartdashboard either.

You can see the current motor voltage set by your motor controller if you’re using CAN. Use the GetOutputVoltage method on your motor controller object and send it to SmartDashboard.

If you want to see actual speed, you’ll need an encoder on your drive. Then, you’ll need to periodically read the encoder and convert the value into rotations, degrees, or whatever you need. Then divide the amount that it has changed by the time since your last read the value (typically 1/50 sec if nothing is bogging down your program loop). That should give you the velocity.

I have an encoder on the motor shaft, but it won’t put the ReturnPIDInput value (which is supposed to be the value I need) to SmartDashboard. It just returns 0.000

You can read the speed controller values also. For instance, our team’s code does this in c++

SmartDashboard:: PutNumber(“Speed Controller 1”, speedController1->Get());

It’s not the true PID speed of the encoder but gives you a general idea what it’s doing.

Thanks for that tip. However, when I tried it it just gave me .5 the entire time, which was simply the set point value I was trying to achieve. I don’t think this estimate will work for me since I’m just trying to reach this setpoint though :frowning:

I worry that the smartdashboard values just aren’t updating as I go along and that’s why they all only give me 0…

Yeah, our bot uses some older non-CAN Talons so the fancy PID modes on yours probably don’t work the same way. I’m sure there is a way to get there but would have to check the wpilib to find out. Good luck!