SPARK MAX Smart Motion not running motor

We’re having a weird issue with the SPARK MAX smart motion where we’ve tuned the PIDF values for velocity control and have it working pretty well, but when we try to command a move in smart motion mode, the motor does not move at all. To be clear, in velocity mode, if we command some RPM, the motor will spin at that RPM. This happens both through our code and through the REV Hardware Client. Yesterday when we were testing, it looked like the status light was solid magenta even after we commanded a position using the hardware client.

The code, in case it matters:

What are we missing?

1 Like

It looks like on initialization you are setting the max velocity and the max acceleration as 0 RPM, and I don’t see any location where this is set to anything higher.

We are setting these to non-zero values, the helper function doesn’t return current velocity/acceleration but instead converts a value to native units. My understanding is the second parameter is the slot ID? We did confirm that they are set in hardware client.

Yeah that’s right, was looking too quick… What is the value that you read back as being set in the REV Hardware Client?

Are you able to run Smart Motion from the client?

We can read the velocity as set to 8000 and the accel set to 80000.

If it wasn’t clear from the code, this is on our swerve azimuth NEO 550 motors, which are on a 53.3:1 ratio relative to the module. We’re also observing this on all of the azimuth motors we’ve tested so we think it probably is something wrong with our configuration.

When we try to run Smart Motion from the client, the applied output sits at 0 while the setpoint goes to whatever we target.

We’re trying to configure factory defaults and burn flash on boot, but we noticed that it appears that the client shows hardware limit switches as enabled on both forward and reverse as normally closed switches. We don’t have any limit switches and we definitely didn’t manually enable that, so that seems odd. But if we run in percent output mode (using the client) the motor spins, and velocity control mode worked fine from the client, so no idea if that is an actual problem.

Also, we noticed that we can get the motor to jitter in Smart Motion mode under some circumstances (I think what we tested was when we disable, turn the module like 90 degrees, and then reenable with the setpoint as 0), but this is the motor spinning back and forth by less than one rotation so the output is not observably changing.

EDIT: Ok so now the velocity control also appears to not work from the hardware client. We toggled the limit switches off and on and in both cases it no longer works. I’m not really sure what’s changed since this morning when we were tuning the velocity control PID using the client.

EDIT 2: At this point for some reason we also get an applied output of 0 when we use percent output mode set to any value on the hardware client, so it seems to be beyond a closed loop issue.

EDIT 3: So the only thing that seems to have changed between this morning when it was working through the hardware client and now is that we uploaded our working code to the robot. Before this we were using the hardware client without enabling the robot, and in those circumstances, percentage output and velocity control worked but smart motion did not. Now, without enabling the robot but with working code on the roboRIO, the hardware client seems to be unable to tell the SPARKs to do anything. We just realized this and tried to enable the robot but now the hardware client is unable to detect the device its connected to over USB.

EDIT 4 (last one for today): We were finally able to get the client to detect the SPARK MAX over USB while the robot was enabled, and it was still unable to get the motor to run even in percent output mode. We checked the wiring and all of the configuration variables in the client, and the only thing we could think of that could possible be the issue was the limit switch stuff, which we tried every combination of.

So one thing regarding enabling the robot while using the hardware client, the hardware client does not control the motors when a roboRIO is detected on the CAN bus. This is a state that is latched. Our documentation goes into this in a bit more detail, and we’ll be adding a few features to the client that help point out when this is the case. To get it to run, power down, remove the roboRIO from the chain, power on, test using the client.

Would it be possible for you to test using the Java Smart Motion example from our Github as is? That will help narrow down, as we directly test our examples, that will give parity with what we have on our side.

Regarding the limit switch, if this is triggered you will see the limit switch blink code. This is the case for hard or soft limits. You can also read back sticky faults in your code which will show if any limits have been activated since the last time you cleared the faults.

Ok, so with the Smart Motion example, it seems to work fine. We’re currently going through our code to find what we’re doing differently from the example.

By the way, I don’t think this addresses the issue we were having with the hardware client. Initially velocity control had worked but smart motion just jittered (so output was doing something but not correctly moving to the setpoint).

Ok, so if this comes up for anyone else, the three parameters that we set in our code just now, that were not set before, were the I Zone, the minimum smart motion velocity, and allowed closed loop error. We had not set these before because we thought they would all default to zero, which was okay for our purposes. To my knowledge this was the only relevant change that could have fixed our issues.

It’s still unclear what the issue was with the hardware client at first though, in the time when we had no code on our roboRIO. At that time it worked with velocity control but smart motion just output nothing or jittered.