Go to Post Yeah, that's a hardware problem. Definitely something to blame the electricals for. Programmers just work there. - EricH [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 09-01-2013, 13:11
Bryscus's Avatar
Bryscus Bryscus is offline
EE, CpE
AKA: Bryce B.
FRC #0180 (SPAM)
Team Role: Engineer
 
Join Date: Jan 2009
Rookie Year: 1999
Location: Jupiter, FL
Posts: 173
Bryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud of
Cannot allocate an object of type 'Command'

Guys,

I think I understand why this is throwing an error, but I am looking for the correct way to do this. In Brad Miller's last Robot Builder video on youtube he writes the following java code:

Code:
autonomousCommand = (Command) autonomousModes->GetSelected();
Unfortunately, if you write the same code in C++ you get the following error:

C:/WindRiver/workspace/TestProject/Robot.cpp: In member function `virtual void Robot::AutonomousInit()':
C:/WindRiver/workspace/TestProject/Robot.cpp:40: error: cannot allocate an object of type `Command'
C:/WindRiver/workspace/TestProject/Robot.cpp:40: error: because the following virtual functions are abstract:
C:/WindRiver/vxworks-6.3/target/h/WPILib/Commands/Command.h:79: error: virtual void Command::Initialize()
C:/WindRiver/vxworks-6.3/target/h/WPILib/Commands/Command.h:84: error: virtual void Command::Execute()
C:/WindRiver/vxworks-6.3/target/h/WPILib/Commands/Command.h:95: error: virtual bool Command::IsFinished()
C:/WindRiver/vxworks-6.3/target/h/WPILib/Commands/Command.h:101: error: virtual void Command::End()
C:/WindRiver/vxworks-6.3/target/h/WPILib/Commands/Command.h:114: error: virtual void Command::Interrupted()
C:\WindRiver\vxworks-6.3\host\x86-win32\bin\make.exe: *** [CommandBasedRobotTemplate/Debug/Objects/TestProject/Robot.o] Error 1

The idea is to cast to the "Command" type in order to be able to set autonomousCommand equal to the output of a SelectableChooser object (which is set by the user clicking on the desired command on the Smartdashboard) - which is then the command that gets run in autonomous.

Any thoughts? Thanks in advance.

- Bryce

P.S. Here's the complete code in Robot.cpp

Code:
void Robot::RobotInit() {
	RobotMap::init();
	// BEGIN AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS
	driveTrain = new DriveTrain();
	elevator = new Elevator();
	wrist = new Wrist();
	claw = new Claw();
    // END AUTOGENERATED CODE, SOURCE=ROBOTBUILDER ID=CONSTRUCTORS
	// This MUST be here. If the OI creates Commands (which it very likely
	// will), constructing it during the construction of CommandBase (from
	// which commands extend), subsystems are not guaranteed to be
	// yet. Thus, their requires() statements may grab null pointers. Bad
	// news. Don't move it.
	oi = new OI();
	lw = LiveWindow::GetInstance();
	// instantiate the command used for the autonomous period
	autonomousModes = new SendableChooser();
	autonomousModes->AddDefault("Deliver Cylinder", new DeliverCylinder());
	autonomousModes->AddObject("Awesome Autonomous", new AutonomousCommand());
	smartDashboard->PutData("Autonomous Modes", autonomousModes);
  }
	
void Robot::AutonomousInit() {
	autonomousCommand = (Command) autonomousModes->GetSelected();
	if (autonomousCommand != NULL) autonomousCommand->Start();
	
}
__________________
The opulence of the front office decor varies inversely with the fundamental solvency of the firm.

Last edited by Bryscus : 09-01-2013 at 14:24.
  #2   Spotlight this post!  
Unread 09-01-2013, 15:00
Bryce Paputa's Avatar
Bryce Paputa Bryce Paputa is offline
FF TSL: Frog Farce
FRC #0503 (Frog Force)
Team Role: Alumni
 
Join Date: Jan 2012
Rookie Year: 2008
Location: Novi Michigan
Posts: 454
Bryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond repute
Re: Cannot allocate an object of type 'Command'

You can't cast to Command class because it is an abstract class and therefore cannot have any instances. Try casting to CommandBase
  #3   Spotlight this post!  
Unread 09-01-2013, 15:20
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 592
BradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant future
Re: Cannot allocate an object of type 'Command'

There's a new example of doing this in C++ at the bottom of this page:

http://wpilib.screenstepslive.com/s/...smartdashboard

Brad
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
  #4   Spotlight this post!  
Unread 09-01-2013, 16:29
Bryscus's Avatar
Bryscus Bryscus is offline
EE, CpE
AKA: Bryce B.
FRC #0180 (SPAM)
Team Role: Engineer
 
Join Date: Jan 2009
Rookie Year: 1999
Location: Jupiter, FL
Posts: 173
Bryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud of
Re: Cannot allocate an object of type 'Command'

Thanks Brad. Just missing a *. I could have sworn that I tried that, but obviously not...

- Bryce
__________________
The opulence of the front office decor varies inversely with the fundamental solvency of the firm.
Closed Thread


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 02:21.

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