Motion Magic not working in Teleop but works in Test

So we set up The talon’s motion magic with the WPI_TalonSRX objects on our drive motors and we had the same motion magic configurations for teleop and test. There was an if statement in both of the periodics that when we pressed a button on our controller it would set the motors to go forward 10 feet. For some reason we don’t understand why it only works in test mode and not teleop.
Is there any reason for this problem to happen?
It looks like the talons are outputting something because i see them flashing green but it only flashes for a split second and then it goes back to neutral but it working only in test mode is confusing me.

Sorry i meant to post. This is my robot class and my drive class.

You will likely have to post your code to get an accurate answer.

I can’t speak much on why your code would work in test mode and not teleop, but I do have a few questions / suggestions.

I have never used WPILib TalonSRX/VictorSPX objects. Is there a specific reason you are using them over the official CTRE libraries?

In both MotionMagicFeet and MotionMagicTurn you are resetting the sensor position, as well as calling several motor controller settings to be changed upon each iteration of the loop.

In terms of your controller logic, I would change it. All of your mechanisms are controlled in one if block; this means that you can only control one thing at a time.

This may be your intent, but if not I would create separate if blocks for each mechanism.

Furthermore, you may want to make sure that when you release the button, nothing happens.

Example of both:

if (buttonA) {
} else {

if (buttonB) {
} else if (buttonY) {
} else {

The WPI_TalonSRX is a wrapper for the TalonSRX class which allows it to be used with WPILib objects such as DifferentialDrive. WPI_TalonSRX is actually a part of the Phoenix (CTRE) API not WPILib.

1 Like

Have you tried using the same button in both teleop and test mode to remove that source of variability?

I would suggest just putting drive.MotionMagicFeet(10); as the only method in both teleopPeriodic and testPeriodic (ie comment everything else out). That will eliminate all other variables of other if statements running.

I also agree that you shouldn’t be configuring the motor controllers every 20ms as part of the main loop, try moving these into your config or init method. It also appears you are calling leftTalon.setSelectedSensorPosition(0,0,timeout); in your main loop. I don’t believe you want to do this as it will keep setting your encoder value to 0, preventing closed loop control from functioning correctly.

im pretty sure i call the main configurations in the init methods, i had to use follow mode on the victors because when i did motion magic the victors werent following like they were supposed to so it may be a small bug in my code.

The main idea of it is to test this method being called just once to be used for some autonomous command so im not trying to loop the method im trying to only call it a single time. Ill try commenting everything else out and see what happens tomorrow.

No, but that is something i will also try

Currently your teleopPeriodic and your testPeriodic controls are different.

Is there a reason for that?

One of the first things I would do is to eliminate the difference between the two if that is truly your point of comparison.

If you want to be sure, create a library method called robotPeriodic(), and have both teleopPeriodic() and testPeriodic() call it and be done.

Well i tested my code on an old robot and made a brand new constructor for my drive class and turns out it works well so there is either something with my code or the robot we made. I’m going to assume its my code. Probably something in my original constructor is messing with it. I’ll test this code as well when we unbag. Thanks for the help!

Well build season is over and we gave up on motion magic but the good news is i figured out the problem. After commenting out specific lines of code turns out the creation of the differential drive object had a dead band which was interfering with the motor controller output for motion magic. Thanks again for the help!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.