Go to Post Dang! And here I was getting all excited about finding out about the game!!! - dlavery [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
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 27-01-2013, 13:26
VikingRobotics's Avatar
VikingRobotics VikingRobotics is offline
Registered User
FRC #1989
 
Join Date: Jan 2013
Location: Vernon, NJ
Posts: 2
VikingRobotics is an unknown quantity at this point
Problem with Shooter Code for FRC

Salutations fellow programmers!
I'm the programmer for team 1989. This is my first year programming so I thought I'd reach out for a little help. Our team is going to have our shooter positioned at a fixed angle (36.8 degrees) and then we are going to vary the speed depending on our distance from the goals. I programmed 3 buttons on the attack 3 joystick for 3 different speeds but the motors for the shooter will only stay on when I am holding the button. I wanted to know if it is possible to program the buttons so that you push it once to turn the motors on and then push it again to turn them off. Nothing I've tried has worked so far. Here's the method I made for the shooter:

public void shooter()
{

final int button1 = 2;
final int button2 = 3;
final int button3 = 4;
double speed = 0;
if (leftstick.getRawButton(button1))//when button 2 is pressed motor moves at 30% of max speed
{
speed = 0.3;
}
if (leftstick.getRawButton(button2))//when button 3 is pressed motor moves at 60% of max speed
{
speed = 0.6;
}
if (leftstick.getRawButton(button3))//when button 4 is pressed motor moves at 90% of max speed
{
speed = 0.9;
}
Victor3.set(speed);
Victor4.set(speed);
}
Reply With Quote
  #2   Spotlight this post!  
Unread 27-01-2013, 13:43
markmcgary's Avatar
markmcgary markmcgary is offline
Software Mentor
FRC #4322 (Clockwork Oranges)
Team Role: Mentor
 
Join Date: Feb 2012
Rookie Year: 2012
Location: Fullerton, CA
Posts: 173
markmcgary is just really nicemarkmcgary is just really nicemarkmcgary is just really nicemarkmcgary is just really nicemarkmcgary is just really nice
Re: Problem with Shooter Code for FRC

Real quick. Change the scope of your 'speed' variable. It should probably be a class variable. Make sure you provide a button to set the 'speed' to zero.
Reply With Quote
  #3   Spotlight this post!  
Unread 27-01-2013, 22:40
AsianRookie AsianRookie is offline
Registered User
AKA: Steven/Tim
FRC #0321 (Robolancers)
Team Role: Programmer
 
Join Date: Oct 2012
Rookie Year: 2007
Location: Philadelphia
Posts: 31
AsianRookie is an unknown quantity at this point
Re: Problem with Shooter Code for FRC

Declare the speed variable only once, so outside the main loop. Also initialize it in robotInit(). Other than that, use a button to set it to 0 or something like that.
Reply With Quote
  #4   Spotlight this post!  
Unread 28-01-2013, 11:38
Bryce Paputa's Avatar
Bryce Paputa Bryce Paputa is offline
FF TSL: Frog Farce
FRC #0503 (Frog Force)
Team Role: Alumni
 
Join Date: Jan 2012
Rookie Year: 2008
Location: Novi Michigan
Posts: 454
Bryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond reputeBryce Paputa has a reputation beyond repute
Re: Problem with Shooter Code for FRC

It looks like you are only checking the buttons and setting the speed in the constructor, you probably want to put that into a loop. I would move all of the button and speed control stuff into a public method and call it from either a command or teleopPeriodic, depending on if you use command based robot or iterative robot. (If you use simple robot, just call it in a loop)
Reply With Quote
  #5   Spotlight this post!  
Unread 28-01-2013, 13:06
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,042
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Problem with Shooter Code for FRC

Quote:
Originally Posted by VikingRobotics View Post
I wanted to know if it is possible to program the buttons so that you push it once to turn the motors on and then push it again to turn them off
Try something like this:

Code:
button1now = leftstick.getRawButton(button1);
if (button1now && ! button1previous) {if (speed==0) speed=0.3; else speed=0.0;} 
button1previous = button1now;
... repeat for buttons 2 and 3.


Reply With Quote
  #6   Spotlight this post!  
Unread 28-01-2013, 13:13
VikingRobotics's Avatar
VikingRobotics VikingRobotics is offline
Registered User
FRC #1989
 
Join Date: Jan 2013
Location: Vernon, NJ
Posts: 2
VikingRobotics is an unknown quantity at this point
Re: Problem with Shooter Code for FRC

Thanks so much Ether. I will try it out next time I get to test the robot and let you guys know if I have any other issues. And I already called this method in the teleopPeriodic so that wasn't an issue.

Last edited by VikingRobotics : 28-01-2013 at 13:15.
Reply With Quote
  #7   Spotlight this post!  
Unread 28-01-2013, 15:03
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,042
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Problem with Shooter Code for FRC

Quote:
Originally Posted by VikingRobotics View Post
Thanks so much Ether. I will try it out next time I get to test the robot and let you guys know if I have any other issues. And I already called this method in the teleopPeriodic so that wasn't an issue.
If you want the other buttons (2 and 3) to be able to change the speed without having to press button1 to stop it first, then make a slight code change as follows:

Code:
button1now = leftstick.getRawButton(button1);
if (button1now && ! button1previous) {if (speed != 0.3) speed=0.3; else speed=0.0;} 
button1previous = button1now;
... repeat for buttons 2 and 3 (with their respective speeds of course)


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 10:08.

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