Code doesn't work and no one can figure out why

Howdy!

I’m trying to implement the swerve drive kinematics library for our swerve bot. A fun challenge, except I’ve reached a roadblock. When i try to deploy the code to the robot, everything goes fine from the computer side, and VSCode says it deployed to the robot correctly, with only a warning about the gyro board. When you try to connect to the robot however, it says that there is no code running, and seems to restart every 6-8 seconds, based on the log files. VSCode shows no errors in the file, and our older code that doesn’t use the Swerve Drive Kinematics library deploys and functions just fine.

Here’s a link to my github repo with the current src folder, the last few logs from the driver station, the most recent RIOLog json, and a screengrab of the console after deploying.

If you have any insight into what is happening, please don’t hesitate to reach out.

Thanks,
Salem (1977)

So you’re crashing with the reboot loop.

I’m wondering if its because of an uncaught errror trying to open your navX…

Are you sure about your port here?

	AHRS ahrs{frc::SerialPort::Port::kUSB1};

Looks like that object shouldn’t be null when you pass it down into your drivetrain class. I’d check that in the debugger and make sure your AHRS class is coming up correctly.

I’m assuming the CPP version of WPILIB supports this as well, I’d put a few breakpoints and then instead of ‘deploy’ use ‘debug’. It’ll probably stop you on a segmentation fault somewhere.

Could be, how would i go about diagnosing and fixing this? I just confirmed the navx is correctly wired and on.

edited my response

There’s a “Debug Robot Code” menu option. Do that. :slight_smile:

This deploys a debug built (instead of a release build) to the robot, and you will get better info back when there’s a crash. Post the output here if it doesn’t point you right at the problem. A debug build is typically larger and may not be optimized as much, but it has options turned on that result in better diagnostic info when something goes wrong.

1 Like
GNU gdb (GDB) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-w64-mingw32 --target=arm-nilrt-linux-gnueabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word".
Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
=cmd-param-changed,param="pagination",value="off"
0xb6ed5840 in ?? ()
[New Thread 4544.4547]
[New Thread 4544.4548]
[New Thread 4544.4549]
[New Thread 4544.4550]
[New Thread 4544.4551]
[New Thread 4544.4552]
[New Thread 4544.4553]
[New Thread 4544.4554]
[New Thread 4544.4555]

Thread 1 "frcUserProgram" hit Breakpoint 1, main () at C:\Users\eless\Desktop\Robotics\whiplash_offseason\src\main\cpp\Robot.cpp:49
49	int main() {
Loaded '/usr/local/frc/third-party/lib/libwpilibNewCommandsd.so'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libCTRE_Phoenix_WPI.so'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libCTRE_Phoenix.so'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libCTRE_PhoenixCCI.so'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libCTRE_PhoenixTools.so'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libwpilibcd.so'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libntcored.so'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libwpiHald.so'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libwpimathd.so'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libwpinetd.so'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libwpiutild.so'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/lib/libFRC_NetworkCommunication.so.23'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/lib/libRoboRIO_FRC_ChipObject.so.23'. Cannot find or open the symbol file.
Loaded '/usr/lib/arm-linux-gnueabi/libvisa.so'. Cannot find or open the symbol file.
Loaded '/usr/local/natinst/lib/libnirio_emb_can.so.21'. Cannot find or open the symbol file.
Loaded '/usr/lib/arm-linux-gnueabi/libNiFpgaLv.so.13'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libcameraserverd.so'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libcscored.so'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libapriltagd.so'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libopencv_arucod.so.4.6'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libopencv_calib3dd.so.4.6'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libopencv_cored.so.4.6'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libopencv_features2dd.so.4.6'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libopencv_flannd.so.4.6'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libopencv_gapid.so.4.6'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libopencv_highguid.so.4.6'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libopencv_imgcodecsd.so.4.6'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libopencv_imgprocd.so.4.6'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libopencv_mld.so.4.6'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libopencv_objdetectd.so.4.6'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libopencv_photod.so.4.6'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libopencv_stitchingd.so.4.6'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libopencv_videod.so.4.6'. Cannot find or open the symbol file.
Loaded '/usr/local/frc/third-party/lib/libopencv_videoiod.so.4.6'. Cannot find or open the symbol file.
Loaded '/lib/libdl.so.2'. Cannot find or open the symbol file.
Loaded '/usr/lib/libatomic.so.1'. Cannot find or open the symbol file.
Loaded '/usr/lib/libstdc++.so.6'. Cannot find or open the symbol file.
Loaded '/lib/libm.so.6'. Cannot find or open the symbol file.
Loaded '/lib/libgcc_s.so.1'. Cannot find or open the symbol file.
Loaded '/lib/libpthread.so.0'. Cannot find or open the symbol file.
Loaded '/lib/libc.so.6'. Cannot find or open the symbol file.
Loaded '/lib/ld-linux.so.3'. Cannot find or open the symbol file.
Loaded '/lib/librt.so.1'. Cannot find or open the symbol file.
Loaded '/usr/local/natinst/lib/libni_emb.so.6'. Cannot find or open the symbol file.
Loaded '/usr/lib/arm-linux-gnueabi/libNiFpga.so.13'. Cannot find or open the symbol file.
Loaded '/usr/lib/arm-linux-gnueabi/libNiRioSrv.so.13'. Cannot find or open the symbol file.
Loaded '/usr/local/natinst/lib/libni_rtlog.so.2'. Cannot find or open the symbol file.
Loaded '/usr/lib/arm-linux-gnueabi/libniriodevenum.so.1'. Cannot find or open the symbol file.
Loaded '/usr/lib/arm-linux-gnueabi/libniriosession.so.1'. Cannot find or open the symbol file.
[New Thread 4544.4556]
[New Thread 4544.4557]
[New Thread 4544.4558]
[New Thread 4544.4559]
[New Thread 4544.4560]
[New Thread 4544.4561]
[New Thread 4544.4562]
[New Thread 4544.4563]
[New Thread 4544.4564]
[New Thread 4544.4565]
[New Thread 4544.4566]
[New Thread 4544.4567]
[New Thread 4544.4568]
[New Thread 4544.4569]
[New Thread 4544.4570]
[New Thread 4544.4571]
[New Thread 4544.4572]

Thread 1 "frcUserProgram" received signal SIGSEGV, Segmentation fault.
0x0004a63c in Drivetrain::Drivetrain (this=0x77820 <frc::impl::RunRobot<Robot>(wpi::priority_mutex&, Robot**)::theRobot+928>, navx=...) at C:\Users\eless\Desktop\Robotics\whiplash_offseason\src\main\include/Drivetrain.h:16
16			Drivetrain(AHRS& navx){
Execute debugger commands using "-exec <command>", for example "-exec info registers" will list registers in use (when GDB is the debugger)

image
It shows a segmentation fault, which joemost predicted, but I don’t know how to go about fixing it.

2 Likes

you are trying to pass a pointer over your NAVX class to each swerve module (which Btw weird that each swerve module would reset it but whatever).

you’re already passing it in by reference.

If it were me I’d do something like this:

SwerveModule::SwerveModule(const int driveMotorID, const int angleMotorID, const int angleEncoderID, AHRS* pNavx)
: m_driveMotor{driveMotorID}, m_angleMotor{angleMotorID}, m_angleEncoder{angleEncoderID} {

ahrs = pNavx;
ahrs->Reset();

you originally use the & ampersand as an address operator to get your NavX object (whatever “ahrs” is) and give it to each of your swerve modules. Within your class you then use the address operator again to set your pointer. A double reference and you’d be referencing the address of a pointer.

1 Like
SwerveModule::SwerveModule (this=this@entry=0x84a30 <frc::impl::RunRobot<Robot>(wpi::priority_mutex&, Robot**)::theRobot+1184>, driveMotorID=driveMotorID@entry=0, angleMotorID=angleMotorID@entry=1, angleEncoderID=angleEncoderID@entry=2, pNavx=0x0) at C:\Users\eless\Desktop\Robotics\whiplash_offseason\src\main\cpp\SwerveModule.cpp:11
11	  	ahrs->Reset();

It still gives a segmentation fault in the same place after changing it to how you recommended

oh boy, yeah your derefencing into your swerve constructor

I would either make the AHRS class a singleton so you don’t have to worry about passing it around everywhere, or change the order of how do this.

DriveTrain gets supplied reference to the navX instance. Then have drivetrain call an init method on each swerve module which passes that in.

The way you have the header of your drivetrain class now, as soon as your program starts up each swerve module is going to call a function on that null pointer.

Depending on how you have connected your navX, you might want to switch to “frc::SPI::Port::kMXP” (instead of USB – see Selecting an Interface | navX-MXP). To be clear, this is separate from your current problem.

Given that you have “AHRS ahrs{frc::SerialPort::Port::kUSB1};” or “AHRS ahrs{frc::SPI::Port::kMXP};”, just do “ahrs.Reset();”. But, you have to careful to pass this around by reference, to avoid copying this object. You can pass it around as a pointer, but this requires some care.

Not sure this will help, as it introduces some more involved constructs (smart pointers, …), but Scrappy/DriveSubsystem.cpp at master · Jagwires7443/Scrappy · GitHub has C++ code that uses a navX for swerve. It might be worth checking out, but only as one reference – it’s not set up as a tutorial and could do with some more/better comments and cleanup.

Repo link to the changed code, I think I got it to work, changed the gyro to a singleton and removed the resets from each swerve module. Testing it using a simulation yields the desired results!

Thanks for your help!

Nice. Downside of Pointers. Super powerful but easy to find yourself in dereference/reference/whatever hell.

Yeah you would have seen that in simulator as well. We’ve actually gotten in the habit of launching simulation first if were about to push something major on to the robot (like brand new swerve drive code) and then pushing to the robot. Just feels like its easier to catch that way.

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