Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Command Based Code Crashes without Errors (http://www.chiefdelphi.com/forums/showthread.php?t=141845)

Blarry 01-16-2016 10:25 AM

Command Based Code Crashes without Errors
 
Hi, this is our first year using command base code and we are getting a weird error.

We wrote a simple drive train code and it crashes seconds after deploying (the comm light turns red and DS robot code indicator turns green then red). The weird part is, it didn't print anything to the DS, nor to the RioLog.

Here is our code:

Any advice is appreciated! Thank you!!

Robot.cpp
Code:

#include "WPILib.h"
#include "Commands/Command.h"
#include "Commands/DriveWithJoystick.h"
#include "CommandBase.h"

class Robot: public IterativeRobot
{
private:
        Command *autonomousCommand;
        LiveWindow *lw;


        void RobotInit()
        {
                CommandBase::init();
                autonomousCommand = new DriveWithJoystick();
                lw = LiveWindow::GetInstance();
                std::cout << "RobotInit" <<std::endl;
        }
       
        void DisabledPeriodic()
        {
                std::cout << "Disabled" <<std::endl;
                Scheduler::GetInstance()->Run();
        }

        void AutonomousInit()
        {
                if (autonomousCommand != NULL)
                        autonomousCommand->Start();
        }

        void AutonomousPeriodic()
        {
                Scheduler::GetInstance()->Run();
        }

        void TeleopInit()
        {
                // This makes sure that the autonomous stops running when
                // teleop starts running. If you want the autonomous to
                // continue until interrupted by another command, remove
                // this line or comment it out.
                if (autonomousCommand != NULL)
                        autonomousCommand->Cancel();
        }

        void TeleopPeriodic()
        {
                Scheduler::GetInstance()->Run();
        }

        void TestPeriodic()
        {
                lw->Run();
        }
};

START_ROBOT_CLASS(Robot);

OI.h
Code:

#ifndef OI_H
#define OI_H
#include "WPILib.h"

class OI
{
private:
        Joystick* joy;
public:
        OI();
        Joystick* GetJoy();
};

#endif

OI.cpp
Code:

#include "OI.h"

OI::OI()
{
        joy = new Joystick(0);
}

Joystick* OI::GetJoy(){
        return joy;
}

CommandtBase.h
Code:

#ifndef COMMAND_BASE_H
#define COMMAND_BASE_H

#include <string>
#include "Commands/Command.h"
#include "Subsystems/DriveTrain.h"
#include "OI.h"
#include "WPILib.h"

/**
 * The base for all commands. All atomic commands should subclass CommandBase.
 * CommandBase stores creates and stores each control system. To access a
 * subsystem elsewhere in your code in your code use CommandBase.examplesubsystem
 */
class CommandBase: public Command
{
public:
        CommandBase(char const *name);
        CommandBase();
        static void init();
        // Create a single static instance of all of your subsystems
        static DriveTrain *driveTrain;
        static OI *oi;
};

#endif

CommandBase.cpp
Code:

#include "CommandBase.h"
#include "Subsystems/DriveTrain.h"
#include "Commands/Scheduler.h"

// Initialize a single static instance of all of your subsystems to NULL
DriveTrain* CommandBase::driveTrain = NULL;
OI* CommandBase::oi = NULL;

CommandBase::CommandBase(char const *name) :
                Command(name)
{
}

CommandBase::CommandBase() :
                Command()
{

}

void CommandBase::init()
{
        // Create a single static instance of all of your subsystems. The following
        // line should be repeated for each subsystem in the project.
        driveTrain = new DriveTrain();
        oi = new OI();
}

DriveTrain.h
Code:

#ifndef EXAMPLE_SUBSYSTEM_H
#define EXAMPLE_SUBSYSTEM_H

#include "Commands/Subsystem.h"
#include "WPILib.h"

class DriveTrain: public Subsystem
{
private:
        RobotDrive* robot;
public:
        DriveTrain();
        void InitDefaultCommand();
        void Drive(Joystick* joy);
};

#endif

DriveTrain.cpp
Code:

#include "DriveTrain.h"
#include "Commands/DriveWithJoystick.h"

DriveTrain::DriveTrain() :
                Subsystem("DriveTrain")
{
        robot = new RobotDrive(new CANTalon(3), new CANTalon(4));
}

void DriveTrain::InitDefaultCommand()
{
        // Set the default command for a subsystem here.
        SetDefaultCommand(new DriveWithJoystick());
}

// Put methods for controlling this subsystem
// here. Call these from Commands.

void DriveTrain::Drive(Joystick* joy){
        robot->ArcadeDrive(joy);
}

DriveWithJoystick.h
Code:

#ifndef EXAMPLE_COMMAND_H
#define EXAMPLE_COMMAND_H

#include "../CommandBase.h"
#include "WPILib.h"

class DriveWithJoystick: public CommandBase
{
public:
        DriveWithJoystick();
        void Initialize();
        void Execute();
        bool IsFinished();
        void End();
        void Interrupted();
};

#endif

DriveWithJoystick.cpp
Code:

#include "DriveWithJoystick.h"


DriveWithJoystick::DriveWithJoystick()
{
        // Use Requires() here to declare subsystem dependencies
        Requires(CommandBase::driveTrain);
}

// Called just before this Command runs the first time
void DriveWithJoystick::Initialize()
{

}

// Called repeatedly when this Command is scheduled to run
void DriveWithJoystick::Execute()
{
        CommandBase::driveTrain->Drive(CommandBase::oi->GetJoy());
}

// Make this return true when this Command no longer needs to run execute()
bool DriveWithJoystick::IsFinished()
{
        return false;
}

// Called once after isFinished returns true
void DriveWithJoystick::End()
{

}

// Called when another command which requires one or more of the same
// subsystems is scheduled to run
void DriveWithJoystick::Interrupted()
{

}


Kevin Sevcik 01-16-2016 11:02 AM

Re: Command Based Code Crashes without Errors
 
I've seen this happen when things like uninitialized pointer errors, or fatal errors in constructors for the static classes. Something really early in the boot process that kills everything before driverstation stuff can happen. I usually catch it with NetConsole, which will give you all the output from the console, including vxWorks boot stuff. Here's the screensteps for it and RioLog:
http://wpilib.screenstepslive.com/s/...console-output
I haven't used RioLog before, but it sounds like it should give you the same level of output. You DO need enable Console Output in the Startup Settings on the home page of the roboRIO, though. If you do get the console output during the boot, there's going to be some sort of fatal error near the end that should hopefully make things a little more obvious.

Joe Ross 01-16-2016 01:50 PM

Re: Command Based Code Crashes without Errors
 
It looks like you're copying a template from previous years, and not creating it with this year's plugins. What happens if you create a new project with this year's plugins? Also note that the eclipse plugins release yesterday fixed several crashing problems.

Blarry 01-16-2016 04:26 PM

Re: Command Based Code Crashes without Errors
 
Quote:

Originally Posted by Kevin Sevcik (Post 1524773)
I've seen this happen when things like uninitialized pointer errors, or fatal errors in constructors for the static classes. Something really early in the boot process that kills everything before driverstation stuff can happen. I usually catch it with NetConsole, which will give you all the output from the console, including vxWorks boot stuff. Here's the screensteps for it and RioLog:
http://wpilib.screenstepslive.com/s/...console-output
I haven't used RioLog before, but it sounds like it should give you the same level of output. You DO need enable Console Output in the Startup Settings on the home page of the roboRIO, though. If you do get the console output during the boot, there's going to be some sort of fatal error near the end that should hopefully make things a little more obvious.

The console was enabled but still no luck...

Blarry 01-16-2016 04:27 PM

Re: Command Based Code Crashes without Errors
 
Quote:

Originally Posted by Joe Ross (Post 1524854)
It looks like you're copying a template from previous years, and not creating it with this year's plugins. What happens if you create a new project with this year's plugins? Also note that the eclipse plugins release yesterday fixed several crashing problems.

We'll try the new plugin and update you on Monday. Thank you!!

Blarry 01-18-2016 05:33 PM

Re: Command Based Code Crashes without Errors
 
Quote:

Originally Posted by Joe Ross (Post 1524854)
It looks like you're copying a template from previous years, and not creating it with this year's plugins. What happens if you create a new project with this year's plugins? Also note that the eclipse plugins release yesterday fixed several crashing problems.

It worked when we update the plugins! Thank you much!


All times are GMT -5. The time now is 09:12 AM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi