Spark MAX + NEO inverts direction every start up

I just started running into an issue after replacing a bad Spark MAX. The left side of the drivetrain inverts direction every start up.

I have code to flip one side of the drivetrain since the motors are facing the other direction, and it seems to flip every start up.

I also put a check in there that says if(!leftMaster.getInverted()) { leftMaster.setInverted(true); } but it still inverts it every time.

Has anyone run into the issue?

I don’t have my updated code pushed to git since I forgot, but I will do that tomorrow. Just checking to see if it’s a common issue and I’m missing something easy.

Are you using the DifferentialDrive class to drive the robot like this example? allwpilib/Robot.java at 26ff9371d93c3c6a84a4d76e8a1ec01b8d86d0c0 · wpilibsuite/allwpilib · GitHub

The DifferentialDrive.arcadeDrive()/DifferentialDrive.tankDrive() inverts the output automatically, so you shouldn’t need to invert the motors. Inverting the motors and using these functions will cause the behavior where one side is will always go the wrong way.

I am using differential drive.

However, it doesn’t always go the wrong way, which is confusing

Are you calling sparkmax.restoreFactoryDefaults() at startup?

So Spark Maxes have their own internal memory of what configuration they are set to. This can be set either through code or through the Rev Hardware Client. To avoid the internal Spark Maxes having a potentially different configuration, some teams will configure their motor controllers to factory reset and then set each setting in the subsystem constructor to avoid issues like this. (This also applies to CTRE smart motor controllers as well).

1 Like

No. Should I call that, then set all the parameters in code? Or is setting it using the Spark MAX utility just fine?

I will do that. I did not think to do that.

It is a good idea to always set the proper configuration in code.

Thanks!

Yeah you should – as Jdao said, they have their own internal memory, so it’s best to clear on startup and set the specific settings you want to ensure that there isn’t any unwanted behavior

1 Like

@heatblast016 @jdao Thanks for the advice. I forgot to upload again (it’s a pain since I have to hotspot since school blocks GIT), but that factory reset method seems to work!

Thanks!

1 Like

:smiley: glad to hear it!