OCCRA
Go to Post What a great organization! - HoltDan [more]
Home
Go Back   Chief Delphi > FIRST > General Forum
CD-Events   CD-Media   CD-Spy   FRC-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 03-12-2012, 09:20 PM
KeyFalcon KeyFalcon is offline
Registered User
FRC #4185 (Fanastic Falcons)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Fairfield
Posts: 5
KeyFalcon is an unknown quantity at this point
Joystick Trigger and Button C++ Programming

Hello. I am on a Rookie team and I am a Rookie programmer. I have no idea how to program the buttons on the joystick. I just need help programming the buttons for our robot's shooter motor and intake motor. Any help would be appreciated.

Thank you!
Code:
/**
 * This is a demo program showing the use of the RobotBase class.
 * The SimpleRobot class is the base of a robot application that will automatically call your
 * Autonomous and OperatorControl methods at the right time as controlled by the switches on
 * the driver station or the field controls.
 */ 
class RobotDemo : public SimpleRobot
{
	Victor (victora);
	Victor (victorb);
	Victor (victorc);
	Victor (victord);
	RobotDrive myRobot; // robot drive system
    Joystick rightstick;
    
 public:
	RobotDemo(void):
		victora (1),
		victorb (2),
		victorc (3),
		victord (4),
		myRobot(victora,victorb,victorc,victord),	// these must be initialized in the same order
		rightstick(2)		// as they are declared above.
	    
	{
		myRobot.SetExpiration(0.1);
	}

	/**
	 * Drive left & right motors for 2 seconds then stop
	 */
	void Autonomous(void)
	{
		myRobot.SetSafetyEnabled(false);
		myRobot.Drive(0.0, 0.5); 	// drive forwards half speed
		Wait(10.0); 				//    for 2 seconds
		myRobot.Drive(0.0, 0.0); 	// stop robot
	}

	/**
	 * Runs the motors with arcade steering. 
	 */
	void OperatorControl(void)
	{
		myRobot.SetSafetyEnabled(true);
		while (IsOperatorControl())
		{
			myRobot.ArcadeDrive(rightstick); // drive with arcade style (use right stick)
			Wait(0.005);				// wait for a motor update time
		}
	}
};

START_ROBOT_CLASS(RobotDemo);
Reply With Quote
  #2   Spotlight this post!  
Unread 03-12-2012, 09:50 PM
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: 7,816
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
Send a message via AIM to Alan Anderson
Re: Joystick Trigger and Button C++ Programming

Can you be a little more detailed about what you want? What exactly do you want the motors to do when you press a button, and when you release the button? Which buttons do you want to use? Be as specific as you can.
Reply With Quote
  #3   Spotlight this post!  
Unread 03-12-2012, 10:06 PM
KeyFalcon KeyFalcon is offline
Registered User
FRC #4185 (Fanastic Falcons)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Fairfield
Posts: 5
KeyFalcon is an unknown quantity at this point
Re: Joystick Trigger and Button C++ Programming

I want the motors to run when I press it, and stop when I release it. I also wanted to use number 6 and 7 buttons.
Reply With Quote
  #4   Spotlight this post!  
Unread 03-12-2012, 10:22 PM
Gigakaiser's Avatar
Gigakaiser Gigakaiser is offline
Registered User
AKA: Brandon Hjelstrom
FRC #0987 (High Rollers)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Las Vegas
Posts: 65
Gigakaiser has a spectacular aura aboutGigakaiser has a spectacular aura about
Lightbulb Re: Joystick Trigger and Button C++ Programming

In your operator control loop, you can write something like this:
Code:
if ((rightstick->GetRawButton(6) == 1) && (rightstick->GetRawButton(7) == 0)) //if button 6 is pressed and button 7 is released
{
     //In this check you will either "set" your victors
             victora->Set(.7f);
     //Or use a myrobot function
             myrobot.drive(//set parameters);
}
else if((rightstick->GetRawButton(7) == 1) && (rightstick->GetRawButton(6) == 0)) //if button 7 is pressed and button 6 is released
{
      // "set" your victors
             victora->Set(-.7f);
     //Or use a myrobot function
             myrobot.drive(//set parameters);
}
else // if nothing is pressed set all victors to zero or use a myrobot.drive with 0.0f
{
// turn off everything
             victora->Set(0.0f);
     //Or use a myrobot function
             myrobot.drive(//set parameters to 0.0f);

}
This will make sure your victors are being set to zero if both buttons are pressed or released. Test your robot on blocks before trying to drive!
__________________
FRC Team 987 - It's not enough
Reply With Quote
  #5   Spotlight this post!  
Unread 03-12-2012, 10:26 PM
KeyFalcon KeyFalcon is offline
Registered User
FRC #4185 (Fanastic Falcons)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Fairfield
Posts: 5
KeyFalcon is an unknown quantity at this point
Re: Joystick Trigger and Button C++ Programming

Thank you!
Would this make it so that button 6 controls one motor, and button 7 controls the other one?
Reply With Quote
  #6   Spotlight this post!  
Unread 03-12-2012, 10:36 PM
Gigakaiser's Avatar
Gigakaiser Gigakaiser is offline
Registered User
AKA: Brandon Hjelstrom
FRC #0987 (High Rollers)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Las Vegas
Posts: 65
Gigakaiser has a spectacular aura aboutGigakaiser has a spectacular aura about
Re: Joystick Trigger and Button C++ Programming

Actually, that would reverse your victors per button (for an intake?) - pressing button 6 would set your victor to +.7, whilie pressing button 7 would set your victor to -.7.

If you want each button to turn on a different victor, write this:
Code:
//pressing 6 will turn on intake, releasing 6 will stop intake
if(rightstick->GetRawButton(6) == 1)
{
     Intakevictor->Set(.7f);
}
else if(rightstick->GetRawButton(6) == 0)
{
     Intakevictor->Set(0.0f);
}

//you can use this code again for your shooter wheel if you change the button to seven and the victor to your shooter wheel victor.
__________________
FRC Team 987 - It's not enough
Reply With Quote
  #7   Spotlight this post!  
Unread 03-12-2012, 10:40 PM
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: 7,816
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
Send a message via AIM to Alan Anderson
Re: Joystick Trigger and Button C++ Programming

Brandon posted example code that uses victora as a placeholder. You'll need to define the other two motors you want to control, initialize them appropriately, and set whichever one you want to run in the proper place in the code.

Are you actually using Victor speed controllers? As a rookie team, I'd expect you to have Jaguars. They have different responses to PWM signals, and you won't get the best results unless the programming matches the hardware.
Reply With Quote
  #8   Spotlight this post!  
Unread 03-12-2012, 10:54 PM
KeyFalcon KeyFalcon is offline
Registered User
FRC #4185 (Fanastic Falcons)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Fairfield
Posts: 5
KeyFalcon is an unknown quantity at this point
Re: Joystick Trigger and Button C++ Programming

Yes, we are using victors.
Also, I'm not sure where to paste the code. I understand it should be in the operator control loop, but I'm unsure where exactly.
Reply With Quote
  #9   Spotlight this post!  
Unread 03-12-2012, 10:59 PM
Gigakaiser's Avatar
Gigakaiser Gigakaiser is offline
Registered User
AKA: Brandon Hjelstrom
FRC #0987 (High Rollers)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Las Vegas
Posts: 65
Gigakaiser has a spectacular aura aboutGigakaiser has a spectacular aura about
Re: Joystick Trigger and Button C++ Programming

Paste the code in the "while(IsOperator)" loop. Any code pasted in that while loop will run for the duration of the match.
__________________
FRC Team 987 - It's not enough
Reply With Quote
  #10   Spotlight this post!  
Unread 03-12-2012, 11:12 PM
KeyFalcon KeyFalcon is offline
Registered User
FRC #4185 (Fanastic Falcons)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Fairfield
Posts: 5
KeyFalcon is an unknown quantity at this point
Re: Joystick Trigger and Button C++ Programming

Like this?
Code:
void OperatorControl(void)
	{
		myRobot.SetSafetyEnabled(true);
		while (IsOperatorControl())
		{
			myRobot.ArcadeDrive(rightstick); // drive with arcade style (use right stick)
			Wait(0.005);				// wait for a motor update time
			//pressing 6 will turn on intake, releasing 6 will stop intake
			if(rightstick->GetRawButton(6) == 1)
			{
			     Intakevictor->Set(.7f);
			}
			else if(rightstick->GetRawButton(6) == 0)
			{
			     Intakevictor->Set(0.0f);
			}
		}
	}
};

START_ROBOT_CLASS(RobotDemo);
Or Like this
Code:
void OperatorControl(void)
	{
		myRobot.SetSafetyEnabled(true);
		while (IsOperatorControl())
		{
			myRobot.ArcadeDrive(rightstick); // drive with arcade style (use right stick)
			Wait(0.005);				// wait for a motor update time
		}
		//pressing 6 will turn on intake, releasing 6 will stop intake
					if(rightstick->GetRawButton(6) == 1)
					{
					     Intakevictor->Set(.7f);
					}
					else if(rightstick->GetRawButton(6) == 0)
					{
					     Intakevictor->Set(0.0f);
					}
	}
};

START_ROBOT_CLASS(RobotDemo);
Reply With Quote
  #11   Spotlight this post!  
Unread 03-12-2012, 11:30 PM
Gigakaiser's Avatar
Gigakaiser Gigakaiser is offline
Registered User
AKA: Brandon Hjelstrom
FRC #0987 (High Rollers)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Las Vegas
Posts: 65
Gigakaiser has a spectacular aura aboutGigakaiser has a spectacular aura about
Re: Joystick Trigger and Button C++ Programming

Your first example is correct. Just check that you are using the correct victors.

- You should move the Wait(0.005); directly below
Code:
else if(rightstick->GetRawButton(6) == 0)
{
     Intakevictor->Set(0.0f);
}
__________________
FRC Team 987 - It's not enough
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 03:20 PM.

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


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