Log in

View Full Version : Passing a motor as an argument in a function


Chief Pride
07-02-2009, 09:27
Hello, I am trying to pass a speed controller (victor) as an BYREF argument in a function and set its value, however, the motor wont turn on and I get no errors. Here is what it looks like:


void SpecialControl(SpeedController &Motor); /* prototype */
class Robot : public SimpleRobot
{
Victor InitialMotor;
public:
Robot(void): // these must be initialized in the same order
InitialMotor(1)
{
GetWatchdog().SetExpiration(0.1);
}



void OperatorControl(void)
{
GetWatchdog().SetEnabled(true);
SpecialControl(InitialMotor);
}
};

void SpecialControl(SpeedController &Motor)
{
Motor.Set(1);
}

Thanks in advance.

Redneck
09-02-2009, 01:07
Give this a shot:

void SpecialControl(SpeedController *Motor); /* prototype */
class Robot : public SimpleRobot
{
Victor *InitialMotor;
public:
Robot(void)
{
InitialMotor = new Victor(1);
GetWatchdog().SetExpiration(0.1);
}


void OperatorControl(void)
{
GetWatchdog().SetEnabled(true);
SpecialControl(InitialMotor);
}
};

void SpecialControl(SpeedController *Motor)
{
Motor->Set(1);
}

Chief Pride
09-02-2009, 12:45
I have tried that, and it gives me these errors:
error: cannot convert `Victor' to `SpeedController*' for argument `1' to `void SpecialControl(SpeedController*)'

Thanks in advance.

Alan Anderson
09-02-2009, 14:25
Look carefully at this line, and make sure you didn't leave out anything.
Victor *InitialMotor;

Chief Pride
09-02-2009, 19:53
Ah, finally, that compiles... I will see if it runs on the robot tomorrow. Thanks so much...