We are trying to use CTRE Mag Encoders for our elevator to go to predetermined setpoints. The reason we chose Motion Magic is the acceleration/cruise velocity settings to prevent jerky motion. I have read the manual, and I am not sure what exactly is going on. When I hold my button to activate motion magic, the motor goes up to the setpoint and then zeroes, goes up again, zeroes. I have checked the limit switch and made sure that isn’t zeroing the encoder counters, I am not sure why it does this. Any help will be appreciated!
Hi @TheMrGerb;
A few suggestions to try and figure out where the problem is:
-
make sure you are looking at the tuner. the tuner is going to tell you what the motor controllers are seeing, and it is very very useful.
-
to make sure your zeroing code is not causing the issue, put it in a disable block for testing. If you still have the problem, then that block of code is not causing the issue. If you DO still have the problem, well, then that block of code is causing the issue, and you know you have an issue with the limit switches, how they are wired, etc.
-
if suggestion 2 doesn’t show you the issue, then i would wonder if the sensor is really being rezeroed, or if you are seeing a spike in closed loop error. What does your false conditional block state looko like for your motion magic set point look like? What values are you setting for PID?
I think holding the button for even a brief period will make the action reset and start again.
I’d suggest adding a bit of logic so a button press is only processed once, until you release and repress the button.
Thats what my first instinct was, but it was much too late to keep testing it. I will try this tomorrow, thank you!
I think you’ve done this but make sure your Talon and your encoder is “in phase”. i.e When you are putting positive input into the Talon (lights green) your encoder is going up and negative out put (red lights) encoder goes down.
I think your issue is defiantly in the code that is in the “False” section of your case statement. The code you have in “True” looks good.
Here is what I do. I have a robot global variable called “Elevator Seeking Position”.
The code you have in the “True” I have sitting in a 100 ms loop in Periodic tasks with the input to “Set” being the “Elevator Seeking Position”.
In teleop I just poll joystick buttons and based on how they are pressed set a position into “Elevator Seeking Position”. Just connect the joystick to a case, in the “True” put a new position into “Elevator Seeking Position” and in the “False” do nothing.
Even after the fixes you guys suggested, it still goes to position then goes on. I am posting my plot and self-test pages to see if you guys can see anything wrong there.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.