Speed Controller Declaration is Crashing Code

So for the last couple of days whenever I have tried deploying robot code it would deploy successfully, but the driverstation says no robot code. I researched what this meant and found out that somewhere in my code is crashing. I have determined this area to be in my Chassis subsystem when I declare my motors.

The area that is crashing is below.

(The Header File)

class Chassis : public frc::Subsystem {
private:
	// It's desirable that everything possible under private except
	// for methods that implement subsystem capabilities
	VictorSP* m_frontLeftSP;
//	VictorSP* m_rearLeftSP;
//	VictorSP* m_frontRightSP;
//	VictorSP* m_rearRightSP;
	//RobotDrive* m_robotDrive;

(The CPP File)

Chassis::Chassis() : frc::Subsystem("Chassis") {
	m_frontLeftSP = new VictorSP(0);
//	m_rearLeftSP = new VictorSP(1);
//	m_frontRightSP = new VictorSP(2);
//	m_rearRightSP = new VictorSP(3);

//	m_robotDrive = new RobotDrive(m_frontLeftSP, m_rearLeftSP,
//			m_frontRightSP, m_rearRightSP);

}

Everything is commented out because I was trying to find where it was crashing.

If the first commented line (m_rearLeftSP) is crashing it, it’s likely that you are allocating another PWM motor controller on the same channel (1) somewhere else.

In my RobotMap file all I have is:

constexpr int FRONT_LEFT_MOTOR = 0;
constexpr int REAR_LEFT_MOTOR = 1;
constexpr int FRONT_RIGHT_MOTOR = 2;
constexpr int REAR_RIGHT_MOTOR = 3;
constexpr int CLIMBER = 4;

Also I had the port number in the subsystem because I thought that would change something. Before they were set to the names above.

If it’s a null ptr error, i would recommend switching from raw pointers to shared_ptr instead. That way you don’t lose your pointer and get some memory leaks.

Okay thanks. Also I decided to try robot builder, and that uses shared_ptr so I’ll let you know how that goes when I can.

So I uploaded the code and still had no robot code on the driverstation. I checked the logs and they came out to this:

********** Robot program starting **********
Warning 1 Joystick Button missing, check if all controllers are plugged in
Joystick Button missing, check if all controllers are plugged in
âž” Launching «’/home/lvuser/FRCUserProgram’»

********** Robot program starting **********
Warning 1 Joystick Button missing, check if all controllers are plugged in
Joystick Button missing, check if all controllers are plugged in
âž” Launching «’/home/lvuser/FRCUserProgram’»

********** Robot program starting **********
Warning 1 Joystick Button missing, check if all controllers are plugged in
Joystick Button missing, check if all controllers are plugged in
âž” Launching «’/home/lvuser/FRCUserProgram’»

I’m not worried about the joystick error but the fact that it is repeating. Is it suppose to do that? Or is it because the second controller isn’t plugged in that it is repeating?

It will repeat normally I believe, but in this case it is actually only printing once for each time your code starts.

The NI code on the roboRIO has a mechanism that is attempting to restart your code when it crashes. Your code is then crashing again so you will see those code start messages repeat over and over.

The roborio watchdog reboots the robot code when it crashes. Try and launch with debug mode and add some breakpoints. It will tell you the state of variables and you can find your null ptr.

Also do you have the code on GitHub. It’s hard to help without all of the code.

Thanks.

No I don’t sorry but I can try to upload it real quick.

https://github.com/GLevis/Robot-Code

The “plzcodework” file is the original file.
The “robot code” file is the robot builder file.

In plzcodework the motor declarations are commented out but that is from when I was looking for the crashing point.

At a quick glance it looks like you are trying to add an object to the smartdashboard chooser but you haven’t created the chooser object yet.

Also, I don’t think that is the issue. But where are you creating an instance of CommandBase? Isn’t that where you init your subsystems.

Sorry I can’t be of much help

Where is that at? And which project are you in?

Robot builder doesn’t generate command base. But if you look in the Robot.cpp class, under RobotInit you can see chassis.reset(new Chassis()); which I assume is initializing it.

So I don’t see why it wouldn’t work. Maybe you could add prints to your files and see how far it gets

It should go RobotMap->Robot->Chassis->Oi->Command

I can’t really do that because the driverstation says “no robot code”.

GavinL,

It looks to me you are getting bit by a change done this year in the C++ WPILIB library. It’s important to not construct motor controllers until after the WPILIB/HAL library initializes.

Running a fresh copy of RobotBuilder reveals that the generated code specifically constructs motor controllers inside RobotMap::init(), which is called well after HAL_Initialize(0) (inside the START_ROBOT_CLASS macro).

But your chassis constructor is called on program-bootup. Delay your motor controller construction or cleanly RobotBuild another project.

This is also covered in section 16.36 of the Talon SRX Software Reference Manual.

Okay, I will try that today. Thanks!

It didn’t work but I am going to switch to sample robot for this year.