Blinking Magenta on Spark Maxes

This is Elijah from Team 1831. We are having trouble with our sparks on the code side of things we believe because they are blinking magenta. We can’t find the error as to why they won’t get a signal from the roboRio. They all show up on the Canbus including the Rio when we plug into them using the REV software. The link below is for the repository. Our first competition is this thursday any help is appreciated.

Generally blinking magenta means they are configured for brushless motors and have no signal. This should only really happen in disabled mode and they should swap to a solid magenta in enabled. (Status LED Patterns - SPARK MAX) Are you sure the CAN IDs are all set up properly in your code?

1 Like

So we tried enabling and even when enabled they stay blinking and we just tested all the CAN IDs and they all show up and are referenced in code. However, we are quite new to programming in C++ as our old Programming Mentor retired.

Do we have to add something to the Robot.cpp to allow the rio to interact to with the sparks while enabled. Or is that already in there.

We started with the Timed Robot Example or template and then built off from there.

Hey there Elijah,

You do need to interact with the sparkMAX’s via your robot code. Currently, you have nothing in your code that would cause you to control a motor.

Take a look at the [WPILib documentation[(Creating your Benchtop Test Program (C++/Java) — FIRST Robotics Competition documentation) as a starting point. Presently, from the code you linked on GitHub above, you have no motors declared at all.

To clarify: is the code on github what is running on your robot, exactly as-is? Or is there some other code running on the robot that is not posted on GitHub? You above state that

which to me reads that you have referenced the motors in code. But in the code you have linked above, you have not referenced any motors at all.

We have at least the CAN IDs listed in code in the constants and those IDs are then used in other places

There are motor controllers defined in their C++ header files. Unsure if it’s correct or not, never worked with WPILibC++/REVLib before.

1 Like

From what I can tell, it looks like the CANSparkMax objects are indeed being created correctly, but they don’t seem to be used anywhere.

Elijah, take a look at the WPILib documentation, linked above (but again here: Creating your Benchtop Test Program (C++/Java) — FIRST Robotics Competition documentation)

Further, take a look at the WPILib example projects: WPILib Example Projects — FIRST Robotics Competition documentation

Is this how you correctly set a key bind for a controller.

These are the declarations of that command. The sparks should be connected to these commands that we put in LifterExtender.cpp and .h which are under the src tab not the Code tab in our repository.

WhenPressed and WhenReleased are deprecated: they’ll work, but they’ll be removed next year. They should be replaced with OnTrue and OnFalse. Docs article here: Binding Commands to Triggers — FIRST Robotics Competition documentation

But before that, you’re not calling ConfigureButtonBindings(), so the bindings are never set up: the code that should be calling it is higher in the screenshot, commented out.

You’re trying to go from nothing to C++ command-based, which is a very big step, especially in two days. Your project is a mix of timed-based and command-based; I’d recommend sticking to timed-based for now.
I strongly recommend following the 0-Robot docs tutorial, in whatever language you have the most knowledge (if you have C++ knowledge then ok, otherwise Java is strongly recommended – C++ bites): Introduction — FIRST Robotics Competition documentation

Are the SparkMax motor controllers on your robot wired over PWM or CAN? PWM is much simpler, and the docs show it exactly with the PWMSparkMax class. With CAN, you can still use simple set() calls on CANSparkMax objects.

Ok I fixed the WhenPressed and WhenReleased. Also does the
void RobotContainer::ConfigureButtonBindings() {
frc2::JoystickButton(&m_driverController, frc::XboxController::Button::kLeftBumper)
Does that not call out the button bindings. Also what is the difference between command-based programming and timed-based. Finally, our sparks are all wired over the Canbus.

That code does set up the button bindings, but that code never gets executed because you’ve commented out the code that calls it.

Command-based is more declarative. Timed is iterative, and much simpler.
Which is why I strongly recommend using timed in your situation rather than figuring out the complexities of command-based.
All the RobotContainer stuff, Commands, Subsystems, all that – all that is command-based stuff.

Follow the 0-Robot tutorial I’ve linked above. Don’t mess with command-based.

When i bring it back into the code it throws errors. I have some experience with java and at this point want to switch over. Also the original problem of the magenta blinking sparks is still occurring.

So why aren’t you using Java? It’s very late to switch, but as there doesn’t seem to be anything functional written yet, it’s not a bad idea to switch if you can quickly get some basic done in Java based on the 0-Robot tutorial I linked above.