Drive Motion magic trouble

My team is fairly new to motion magic and we’ve been having some major trouble. Our motion magic program is supposed to drive the robot forward in a straight line, but it jitters along the way. The robot stops when it gets to the set point but it just starts and stops to get there. I thought the problem was the fact that I had the two sides operating at the same time. However, just spinning one motor at a time to the set point did the same thing. The code can be found in the drive to distance motion magic command and all methods are in the drivetrain subsystem. The code

Any help would be appreciated as to why it isn’t working properly. We’ve been stuck on this for a while and desparatly need it working.

Is it possible that your open loop and closed loop drive commands are fighting each other? Perhaps put a quick print by each arcade/tank drive part of your code and make sure you are aren’t sending conflicting values to your motors. We found we were accidentally doing this during auton because our teleop code was also running…

1 Like

We can try this but I don’t believe that is the problem. I could be wrong, but I thought if the command requires the subsystem that command overrides the default command. This means I’m not trying to run both at the same time

You can verify whether it’s a scheduler conflict pretty easily by adding your subsystem to Shuffleboard (or Smartdashboard) and viewing which commands are scheduled for it.

SmartDashboard.putData(drivetrain_subsystem_object);

Then open Shuffleboard, and click on the SmartDashboard tab to watch the drivetrain schedule.

Secondarily, what you are doing at first glance seems close to what we do, but I’ll post our github link to our Drive Motion Magic command to give you a working comparison.

Ours works flawlessly.

Sorry I don’t have a ton of time to actually digest your whole code but at first glance it seemed like it was fine.

If you hard code the set point for motion magic rather than recalculating it each “frame” does it drive smooth?

(sorry nothing jumps out, just what I would do to get a sense of whether the PID needs tuning or is there something wrong with the logic)

i thought during auton only the code in autonperiodic() would run? I actually have the same problem, the robot would jitter during auton with pid. I use sparkmax neos so its the pid.setreference with motionmagic. If I comment out the differential drive code in teleop and not initialize the differential drive variable it would fix the issue, any ideas on how to fix the issue? We are new so we are throwing everything in timedbot. I tried only initialize the pid controllers in autoninit() and initialize the differential drive in teleopinit() but I wasn’t able to do it. Also I am just running these modes with the driver station(teleop vs auton mode).

We violated some of the command framework setup which is what has caused us to have to deal with it this way…

We created a flag on our Drive periodic function that lets us know whether we are in auton or not. Also, there was a previous post that showed the code for determining whether the robot was currently being controlled by the operator.

So, those are 2 not so elegant ways of handling it.

The recommended way, I believe, would be to utilizing different “Drive” commands and use them to control to subsystem, but given the students desire to refactor and crunch time we didn’t get all the way there…

In auton, both autonperiodic and robotperiodic run. The scheduler is in robotperiodic.

If you’re using the differential drive class from wpilib then you need to make sure you’re feeding the watchdog periodically, otherwise motor safety will kill your drive, then the pid will try to drive it again, and so on (jittery driving).

If you’re periodically calling a pid set in your periodic, then just make sure you are also calling drive.feed() to keep the motor safety from kicking in. (drive being the variable that represents your DifferentialDrive object)

Yea I do get a lot of warnings on our driver stations about loop over run 0.02s something from motorsafety. I have always just ignored it because it does not cause any visible issue on driving :joy: , I looked into this as well, how would I feed the watchdog periodically? or how would I disable motorsafety or even make it only check every 0.05s

Here’s how we do it.

Two options, feed the watchdog in the periodic or disable and re-enable motor safety.

I recommend the former.

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