Go to Post And we had to walk both ways to the venue from our hotel! Uphill! Barefoot over broken glass! - IMDWalrus [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 16-01-2016, 10:25
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
  #2   Spotlight this post!  
Unread 16-01-2016, 11:02
Kevin Sevcik's Avatar
Kevin Sevcik Kevin Sevcik is offline
(Insert witty comment here)
FRC #0057 (The Leopards)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Houston, Texas
Posts: 3,685
Kevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond reputeKevin Sevcik has a reputation beyond repute
Send a message via AIM to Kevin Sevcik Send a message via Yahoo to Kevin Sevcik
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.
__________________
The difficult we do today; the impossible we do tomorrow. Miracles by appointment only.

Lone Star Regional Troubleshooter
Reply With Quote
  #3   Spotlight this post!  
Unread 16-01-2016, 13:50
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,572
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
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.
Reply With Quote
  #4   Spotlight this post!  
Unread 16-01-2016, 16:26
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
Re: Command Based Code Crashes without Errors

Quote:
Originally Posted by Kevin Sevcik View Post
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...
Reply With Quote
  #5   Spotlight this post!  
Unread 16-01-2016, 16:27
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
Re: Command Based Code Crashes without Errors

Quote:
Originally Posted by Joe Ross View Post
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!!
Reply With Quote
  #6   Spotlight this post!  
Unread 18-01-2016, 17:33
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
Re: Command Based Code Crashes without Errors

Quote:
Originally Posted by Joe Ross View Post
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!
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 13:56.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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