View Single Post
  #1   Spotlight this post!  
Unread 01-16-2016, 10:25 AM
Blarry's Avatar
Blarry Blarry is offline
Lead Programmer
FRC #5024 (Raider Robotics)
Team Role: Programmer
 
Join Date: Jan 2016
Rookie Year: 2013
Location: London
Posts: 9
Blarry is an unknown quantity at this point
Question 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()
{

}
Reply With Quote