Controlling a motor from Periodic Tasks

I’m trying to send a “Setouput” command to a SparkMax in Periodic Tasks but it seems to react as if it sets the speed to the value I want then immedialy gets set back to zero then back to my speed and so one. So the motor “stutters”.

I control motors using Talons this way and it works fine.

Am I missing something?

Do you have SetOutputs for the same motor in more than a single place (one SetOutput will override the other)?

Do you have a motor Safety Enabled (if SetOutput isn’t called constantly, then the motor will stop)?

1 Like

Only setting output in Periodic Tasks inside a 50ms loop.
Safety Config is set to disabled.

If I disable the code in PT and just set the output in teleop the motor runs fine.

It’s almost as if, in the 50ms the loop is waiting to start again it sets the motor output to zero.

Your description sounds like it would behave if you didn’t have all the Teleop references to the Spark Max commented out while PT was running.

Perhaps try renaming the motor just in the Begin reference and in the Periodic Tasks loop, but just those two instances and nowhere else. That would tell you if there is a second reference to SetOutput that’s getting missed, or the name got used by accident in another place.

If you want to post a snippet of your Teleop and Periodic Task relevant sections, or a zip of your project I could run it here to give you a sanity check.

I would add onto this. If you’re ONLY using this motor in periodic tasks, don’t do anything with this motor in Begin. Don’t create a reference to it. Open it in periodic tasks, wire the reference into the correct While Loop. Perform your logic to control the loop within that 50ms loop.

By doing this, you’ll ensure nothing else has the ability to use this motor.

In teleop, you’ll want to use the reference because the Teleop VI is called frequently while the robot is running. It doesn’t make sense to open and close the motors lots of times. As the Periodic Tasks VI is only called the once, you can setup the motor here and use encapsulation to ensure it isn’t being used multiple times.

Are you able to share the project you’re working on so we can take a better look at the VIs you have and see if there’s anything obvious? As Mark said, the behavior you’re describing suggests you have multiple writes in your code. If it’s writing 0.5 in one place and 0 in another, we’d expect to see a stutter as the two locations race against each other to set those values. This is another reason I suggest encapsulation here.

Thanks for the input. Unfortunately with time running short I didn’t have time to debug this so I’ve moved to another strategy. I may revisit this between my events and if I still can’t figure it out I’ll post my code for some additional help.