View Single Post
  #1   Spotlight this post!  
Unread 21-03-2013, 21:47
austpet1230's Avatar
austpet1230 austpet1230 is offline
Registered User
FRC #4459 (Leotechs)
Team Role: Leadership
 
Join Date: Mar 2013
Rookie Year: 2011
Location: United States
Posts: 9
austpet1230 is an unknown quantity at this point
Question 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!
__________________
If you haven't found it yet, keep looking. Don't settle. As with all matters of the heart, you'll know when you find it. And, like any great relationship, it just gets better and better as the years roll on.
-Steve Jobs

R.I.P. Steve Jobs 1955 - 2011. The Greatest Innovator of all time.

Last edited by austpet1230 : 22-03-2013 at 05:00.
Reply With Quote