Quote:
Originally Posted by mikelowry
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).