Spark Max Segmentation Fault C++

Hello,
I am using the Spark Max libraries with Spark Max motor controllers to control my robot. After I instantiate a new Spark Max class, I get an error when using Set() that there is a “segmentation fault”. It does not matter where I call Set from and I cannot figure out where the issue is with the call. The person doing the wiring figured out their problems this morning and the wiring is correct, but this command will not call. Thank you.

Without code or github repository it is really hard to provide any meaningful help. If you could provide either of these, might be able to see what the issue is.

Joe

Thank you for responding Joe! This is my first year and I am the only one doing the programming, it has been hard to find resources. It should be straightforward to follow this from Robot, to Drivetrain, to Robotdrive and see where most of the calls are. Boommax is just a simple subclass of SparkMax used for setting a few variables in the constructor and the motortype to clean up the other code.
Delegate.h is not in used and will be used for controls later.
The naming conventions are inconsistent but you should be able to look it over.

https://drive.google.com/file/d/1Z4hvuXiB93BC-9WqsjPE9davRpz0HPcw/view?usp=sharing
Thank you so much for your time!

My bad. It was private. You can access it now!

Just did a quick scan and didn’t see anything obvious.

Three sort of silly questions:

  1. Did you verify the CAN IDs are set properly to match your code?
  2. You said any where you call the Set method it segment faults. Did you try calling set immediately after creating the SparkMax’s and that did a segment fault too?
  3. Is there a reason for splitting your subsystem across Drivetrain and TerminatorDrive? Both classes end up holding onto the SparkMax objects. I’m not seeing the point as you are just copying these between the classes, potentially allowing both to call the Set Method which can lead to a painful debugging situation where both actually do that and then the output to the motors aren’t what you are expecting.

Joe

  1. We did check this several times, but we have had some weird issues with seeing the IDs earlier. Someone else on the team does the wiring and electrical work, so I’ll get with him and try to be sure of this.
  2. Yes I did. This is the only reason it was ever called from the Drivetrain. This did result in a Segment Fault.
  3. No, not really. A lot of examples I looked at had a Drivetrain and then a TankDrive class, so when I began work on my teams code, we didn’t exactly want Tank drive. When I looked at creating a subclass of the drive class, I found that it included a bunch of unnecessary functions, so I decided to create my own implementation. The only reason it is still like this is because it was meant to copy the structure of an example. The only reason I named it TerminatorDrive is because I couldn’t think of a name with drive in it.

Since the segment fault happens immediately after creation, I’m guessing it wasn’t created correctly. I’d start with verifying the CAN IDs. You can do that using the REV Hardware Client (Navigating the REV Hardware Client - SPARK MAX). You can verify and update the firmware and the CAN IDs. You can even verify the wiring/motor is working using the run tab. Also what motors are you using? I see you are configured for brushed motors, so making sure that is correct is also needed.

Posting the full error message is sometimes helpful – a screenshot may be even better than cut-n-paste at times.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.