Can TalonSRX Motion Magic

Our team is looking to use PID with one of our talons, and from what we’ve researched Motion Magic is the simplest option. Our problem is that we don’t seem to know exactly how to use the motion magic capabilities of the SRX. We tried out the following code but to no avail.

self.talon.configMotionAcceleration(self.talon.getQuadraturePosition(), 0)
self.talon.configMotionCruiseVelocity(self.talon.getQuadraturePosition(), 0)

#some thing to run the motor
self.talon.set(self.talon.ControlMode.MotionMagicArc, ctre.wpi_talonsrx.MotionMagicArc.PercentOutput, 1)

This obviously doesn’t work, but does anybody here have experience using motion magic with the CAN TalonSRX? What worked for you?

Thanks in advance.

Unfortunately, I’ve not used Motion Magic myself personally, but in theory the Python API should be really close to the Java API (and if it’s not, please file a bug on github highlighting the discrepancy!).

You can find the CTRE SRX examples at . If you have specific pieces that you’re finding difficult to translate, please let me know.

“Not working” is a very large class of things. Please expand on the behavior you’re seeing and your expected behavior.

However I see a few problems right away.

  1. You should be passing one of FeedbackDevice depending on what sensor you’re using into configSelectedFeedbackSensor.

  2. What do you expect to happen by feeding the current position of the sensor into configMotionAcceleration and configMotionCruiseVelocity? You should be giving these methods numbers related to the physical properties of your robot, not the current position of its wheels.

  3. talon.set() takes a ControlMode (which you should be using MotionMagic, not MotionMagicArc probably) and a demand, which for MotionMagic is the distance you want to travel.

If you’re interested, we used motion magic last year. Our code uses the old API, with different methods and units, but you may be able to get a general sense of what needs to happen. Please do not just copy this code, as it plain does not work any more.

Other than that I highly recommend reading the documentation as Dustin suggested. Read through the Motion Magic section of the Software Reference Manual, then check out the examples.

I put together one of the examples from the CTRE projects, but it doesn’t function properly in simulation yet (though perhaps it works on a real robot?).

If you want to take a look, check out the magic-example branch on the robotpy-ctre project. Once I get the sim issues fixed, we’ll push it to master too.

The motion magic example has been pushed to master, and it even works in simulation now! :slight_smile:

Thanks for all the effort you put into this. For someone still learning Git, would you mind expanding on the easiest way for us to view the example? Thanks for the help.