Go to Post Dang! The 2008 game piece was supposed to be a secret. - dlavery [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #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
  #2   Spotlight this post!  
Unread 21-03-2013, 23:31
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,113
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
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.
Reply With Quote
  #3   Spotlight this post!  
Unread 22-03-2013, 16:52
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
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.
__________________
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 : 23-03-2013 at 10:16.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 14:35.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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