View Single Post
  #6   Spotlight this post!  
Unread 04-09-2009, 14:06
Jared Russell's Avatar
Jared Russell Jared Russell is online now
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,077
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Thumbs up Re: very basic code help

Quote:
Originally Posted by mikelowry View Post
Thanks for all the help so far. One more question.
We are using the simple robot template, and as far as I can tell, everything is right, but it wont build.

Code:
#include "WPILib.h"

RobotDrive myRobot(1,2);
Joystick leftStick(1);
Joystick rightStick(2);
class RobotDemo : public SimpleRobot 
{
	RobotDemo(void)
	{
		GetWatchdog().SetEnabled(false);
	}

	void Autonomous(void) 
	{
		GetWatchdog().SetEnabled(false);
		while(1)
		{
			for(int i = 0; i < 4; i++)
			{
				myRobot.TankDrive(0.5,-0.5);
				Wait(4);
				myRobot.TankDrive(0.5,0.5);
				Wait(2);
			}
			myRobot.TankDrive(0.0,0.0);
			Wait(4);
		}
	}
	
	void OperatorControl(void) 
	{
		while(1)
		{
			GetWatchdog().SetEnabled(false);
			while (IsOperatorControl()) 
			{
				myRobot.TankDrive(leftStick, rightStick);
				Wait(0.005);
			}
		}
	}
};
START_ROBOT_CLASS(RobotDemo);
we get the following errors at build:
"RobotDemo::RobotDemo()' is private" in reference to line 7
and
a nonspecific error at the very last line.

Can you tell what I need to do to fix it?
Your compiler is complaining because the START_ROBOT_CLASS macro attempts to instantiate an instance of your RobotDemo class. In order to instantiate a class, the class' constructor is called. You have a constructor for your RobotDemo class, but it is declared "private" by default. This means that outside entities (like the START_ROBOT_CLASS macro) cannot call the constructor, hence the error you are seeing. To fix the behavior, your constructor (and all of the other functions required to implement a SimpleRobot, like Autonomous and OperatorControl) need to be declared as "public".

To do this:

Code:
class RobotDemo : public SimpleRobot 
{
public:
	RobotDemo(void)
	{
		...
	};

        ... the rest of your functions here
};
START_ROBOT_CLASS(RobotDemo);
I believe that's the only error that prevents this code from compiling (although without trying to compile it myself I may have missed something).

Last edited by Jared Russell : 04-09-2009 at 14:09.
Reply With Quote