CTRE Motion Magic Example help

I’m not sure what the behavior of the CTRE Motion Magic Phoenix- Labview examples should be. We tuned all of the variables described in the software manual and can get the motors to reliably stop at the desired position when we press and hold button 0 to engage motion magic and pull the joystick to full power until it reaches the desired position.

However, if we reset the encoder to zero and try again the motor drives backward a little and stops before we apply power.

The joystick does not command the system in power when motion magic is engaged. The joystick is an analog source of positions. Is the joystick value at rest maybe slightly negative. So when button 0 is pressed the command position is not zero but something else.

We use Motion magic to position our lift. Using Java

Ok so in the Java example


/* Motion Magic - 4096 ticks/rev * 10 Rotations in either direction */
double targetPos = leftYstick * 4096 * 10.0;
_talon.set(ControlMode.MotionMagic, targetPos);

That is the system will travel -10 to 10 encoder rotations. So even if the joystick is floating at .05 you would get a half rotation.


-2046 ticks = -.05 * 4096 ticks/rev * 10.0 revs

(-2046 ticks) / (4096 ticks/rev) = -.5 revs

I posted Here an excel spreadsheet the formulas used in the java section of the SRX guide.

That helps. I think I get the logic now. The spreadsheet was also really helpful. I got the robot to react perfectly using the CTRE example. However, I’m having trouble implementing it in our team’s code. It acts like a PID closed loop without the benefit of Motion Magics ramp up/ramp down. I’ve attached a picture of our code. Any thoughts?

Also, in Section 12.6.3 where did the value 1023 come from in calculating f-gain?




As we explore your troubles it may help to know what your trying to do.

1 Like

We have always run our auto routines using encoder values alone. For example, drive forward 600000 encoder ticks and stop. As you know this is not very reliable. We would like to use Motion Magic to be more accurate and eliminate wheel spin at the beginning of auto.

I have propped the wheels off the ground of our 2018 practice robot. I am only driving the left side drive wheels. I am using it as a test base to learn Motion Magic.

In the attached program I want to drive to 600000 encoder counts with a smooth ramp up to eliminate wheel slip and a smoother ramp down to help achieve the target of 600000 encoder ticks.

At this time the robot completes the goal using the CTRE example, but it doesn’t accelerate slowly as it does when we use the CTRE example.

I don’t believe Motion Magic is a good application for drivetrains. I suppose it would and will work but Motion Profiling seem to be what teams use in this situation.

Also, in Section 12.6.3 where did the value 1023 come from in calculating f-gain?
Looks like either I have the chapter references wrong or they where shifted from an older manual when I created this. Looks like its 12.6.4 now. The 1023 are the native units the SRX would get if set to 100% output. I’m can follow Labview somewhat and promises I will likely now at least install it on a PC soon to look at the samples. Could you try to set a crazy hi Max Acceleration to make sure things are working?

Since I don’t have Labview can you post a screen shot of the sample VI?

I’ve attached pictures of the CTRE example.

I looked at motion profiling… it’s a little beyond me at this time. But, i’m up to an off-season challenge.








? So the labview sample doesn’t use the joystick to command a variable distance to goto but instead gets the encoder ticks from the number box on the UI? Or is the UI displaying the( joystick value × encoder counts per rev × 10)
After that…
The question now is what is different when you run the sample that works and your modified code. Are you selecting different encoder type ie ctremagencoder vs quad…