Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Initializing and Using Buttons to Control Victor Motor Controllers (http://www.chiefdelphi.com/forums/showthread.php?t=115258)

austpet1230 21-03-2013 21:47

Initializing and Using Buttons to Control Victor Motor Controllers
 
Hello everyone, I have made a thing to use buttons 4 & 5 to control the servo motor to our Axis camera. The servos are connected to the PWM channels and we just need to program the motor. Would the following code work to accomplish our task?

Code:

#include "WPILib.h"

class RobotDemo : public SimpleRobot
{
        RobotDrive myRobot; // robot drive system
        Joystick stickRight, stickLeft; // only joystick
        Victor (victora);
        Victor (victorb);
        Victor (victorc);
        Victor (victord);

public:
        RobotDemo(void):
                myRobot(victora, victorb),        // these must be initialized in the same order
                stickRight(1),                // as they are declared above.
                stickLeft(2),
                victora (1),
                victorb (2),
                victorc (3),
                victord (4)
        {
                myRobot.SetExpiration(0.1);
        }

        /**
        * Drive left & right motors for 2 seconds then stop
        */
        void Autonomous(void)
        {
                myRobot.SetSafetyEnabled(false);
                while (IsAutonomous()) //drive commands continuously loop
        {
                myRobot.Drive(-0.5, 0.0);        // drive forwards half speed
                Wait(2.0);                        // for 2 seconds
                myRobot.Drive(0.0, -0.5);  // Turn
                Wait(1.0);                                        // for 1 second
                myRobot.Drive(0.0, -0.5);  // Turn again
                Wait(1.0);                  // for 1 second
                }
        }

        /**
        * Runs the motors with arcade steering.
        */
        void OperatorControl(void)
        {
                myRobot.SetSafetyEnabled(true);
                while (IsOperatorControl())
                {
                        myRobot.ArcadeDrive(stickRight); // drive with arcade style (use right stick)
                        Wait(0.005);                                // wait for a motor update time
                        if ((stickRight->GetRawButton(4) == 1))
                        {
                                Intakevictorc->Set(.7f);
                        }
                        else if (stickRight->GetRawButton(4) == 0)
                        {
                                Intakevictorc->Set(0.0f);
                        }
                       
                        if ((stickRight->GetRawButton(5) == 1))
                        {
                                Intakevictord->Set(-.7f);
                        }
                        else if (stickRight->GetRawButton(5) == 0)
                        {
                                Intakevictord->Set(0.0f);
                        }
                }
        }
       
        /**
        * Runs during test mode
        */
        void Test() {

        }
};

START_ROBOT_CLASS(RobotDemo);

Thanks for your help!

Alan Anderson 21-03-2013 23:31

Re: Initializing and Using Buttons to Control Victor Motor Controllers
 
You titled your note with "Victor Motor Controllers", but you asked about "the servo motor". I don't see any servos in your code. What are you really trying to control?

Why do you have parentheses around the names of your Victor objects when you declare them?

You declared "victorc" and "victord", but you're trying to set "Intakevictorc" and "Intakevictord".

If you fix the names to match, your code will run motor C on PWM 3 forward when you press button 4, and motor D on PWM 4 backward when you press button 5. It never runs those motors in the other direction.

austpet1230 22-03-2013 16:52

Re: Initializing and Using Buttons to Control Victor Motor Controllers
 
Sorry, I meant to ask about the servo motors not the victor motors. If one were trying to initialize and use the servo motors would it be initialized like this (initializing two servos):

Code:

class RobotDemo : public SimpleRobot
{
        RobotDrive myRobot; // robot drive system
        Joystick stickRight, stickLeft; // only joystick
        Servo (servoa); //Initialize servo 1 (or a)
        Servo (servob);  //Initialize servo 2 (or b)

and if this is correct, then how would one go about programming these to buttons? Could this code work?

Code:

//Example code
if ((stickRight->GetRawButton(4) == 1))
        {
                servoa->Set(.7f);
        }
else if (stickRight->GetRawButton(4) == 0)
        {
                servoa->Set(0.0f);
        }

Thank you for your help.


All times are GMT -5. The time now is 12:49.

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