Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Passing a motor as an argument in a function (http://www.chiefdelphi.com/forums/showthread.php?t=73799)

Chief Pride 07-02-2009 09:27

Passing a motor as an argument in a function
 
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:

Code:

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

Re: Passing a motor as an argument in a function
 
Give this a shot:
Code:

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

Re: Passing a motor as an argument in a function
 
I have tried that, and it gives me these errors:
Quote:

error: cannot convert `Victor' to `SpeedController*' for argument `1' to `void SpecialControl(SpeedController*)'
Thanks in advance.

Alan Anderson 09-02-2009 14:25

Re: Passing a motor as an argument in a function
 
Look carefully at this line, and make sure you didn't leave out anything.
Code:

        Victor *InitialMotor;

Chief Pride 09-02-2009 19:53

Re: Passing a motor as an argument in a function
 
Ah, finally, that compiles... I will see if it runs on the robot tomorrow. Thanks so much...


All times are GMT -5. The time now is 02:50.

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