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…
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.
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…
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 , 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