Go to Post Robotic Football now thats something I would build 6 weeks for. - Nikkocharger [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 29-01-2016, 14:31
Sky Captain's Avatar
Sky Captain Sky Captain is offline
Lead Software Mentor
AKA: Will
FRC #0386 (Voltage)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2006
Location: Virginia
Posts: 18
Sky Captain is an unknown quantity at this point
Send a message via AIM to Sky Captain
Joystick Pneumatic Triggering

Hi all,

We're working on a method that when we hit a button on the joystick, we want 2 pneumatic cylinders to fire forward and stay forward until we hit the same button again at which point the cylinders will retract. So far however all we get is the cylinders to fire once and not retract. I'm sure we're pretty close, but just missing something small. We're using a boolean to make sure that we don't try to fire forward if they are already forward. Are we using everything correctly? Here's our pseudo code. All of this code is in the teleop periodic method.
Code:
boolean status = false;

if(joystick.getRawButton(3))
{
     if(status == false)
     {  
           solenoid.kforward();
           status = true;
     }
     else
     {
           solenoid.kreverse();
           status = false;
     }
}
__________________
When in doubt, check the documentation.

Last edited by Sky Captain : 29-01-2016 at 20:01. Reason: Fixing code formatting
Reply With Quote
  #2   Spotlight this post!  
Unread 29-01-2016, 15:09
fovea1959's Avatar
fovea1959 fovea1959 is offline
Herder of programmers
AKA: Doug Wegscheid
FRC #3620 (The Average Joes)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2011
Location: St Joseph
Posts: 325
fovea1959 will become famous soon enough
Re: Joystick Pneumatic Triggering

I think your code will flip the valve back and forth as long as the button is held down. Do you need to detect when the button first goes down, and only execute your logic then?

Untested code:
Code:
// run once
boolean status = false;
boolean buttonWasDown = false;

// run inside operator control loop, or teleopPeriodic, or whatever

boolean buttonIsDown = joystick.getRawButton(3);

if(buttonIsDown && !buttonWasDown)
{
     if(!status)
     {  
           solenoid.kforward();
           status = true;
     }
     else
     {
           solenoid.kreverse();
           status = false;
     }
}
buttonWasDown = buttonIsDown;
Reply With Quote
  #3   Spotlight this post!  
Unread 29-01-2016, 15:14
fovea1959's Avatar
fovea1959 fovea1959 is offline
Herder of programmers
AKA: Doug Wegscheid
FRC #3620 (The Average Joes)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2011
Location: St Joseph
Posts: 325
fovea1959 will become famous soon enough
Re: Joystick Pneumatic Triggering

oh!!!!!! you want the code that looks at the button to be in teleopPeriodic; if it's in teleopInit, the button will only get checked once at the beginning of teleop, and never again.
Reply With Quote
  #4   Spotlight this post!  
Unread 29-01-2016, 20:02
Sky Captain's Avatar
Sky Captain Sky Captain is offline
Lead Software Mentor
AKA: Will
FRC #0386 (Voltage)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2006
Location: Virginia
Posts: 18
Sky Captain is an unknown quantity at this point
Send a message via AIM to Sky Captain
Re: Joystick Pneumatic Triggering

My fault, we do have the code in teleop periodic. I'll give your example code a try and let you know how it works. Thanks.
__________________
When in doubt, check the documentation.
Reply With Quote
  #5   Spotlight this post!  
Unread 01-02-2016, 09:19
CjDace CjDace is offline
Registered User
FRC #4284
 
Join Date: Jan 2016
Location: Cincinnati, Ohio
Posts: 10
CjDace is an unknown quantity at this point
Re: Joystick Pneumatic Triggering

Hey! our team is trying to do basically the same thing and our code is hitting an error on the "kreverse/kforward" when we try to get our solenoid object do them. we used the code provided above so instead of that i will provide the declaration
Code:
public class Robot extends IterativeRobot {
	    /**
	     * This function is run when the robot is first started up and should be
	     * used for any initialization code.
	     * 
	     */  RobotDrive myDrive, catcherDrive;
	    	Joystick moveStick;
	    	Gyro scotbot;
	    	Solenoid S;
	    	
	    public void robotInit() {
	    	Talon TalLF = new Talon(0);
	    	Talon TalLR = new Talon(1);
	    	Talon TalRF = new Talon(2);
	    	Talon TalRR = new Talon(3);
	    	Talon TalCatcher = new Talon(4);
	    	Talon TalCatcher1 = new Talon(5);
	    	myDrive =  new RobotDrive(TalLF,TalLR,TalRF,TalRR);
	    	moveStick = new Joystick(0);
	    	catcherDrive = new RobotDrive(TalCatcher, TalCatcher1);
	    	scotbot = new ADXRS450_Gyro();
	    	Compressor c = new Compressor(0);
	    	Solenoid S = new Solenoid(1);
	    	
	    }
Is there something very obvious that im missing?
Reply With Quote
  #6   Spotlight this post!  
Unread 02-02-2016, 08:57
fovea1959's Avatar
fovea1959 fovea1959 is offline
Herder of programmers
AKA: Doug Wegscheid
FRC #3620 (The Average Joes)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2011
Location: St Joseph
Posts: 325
fovea1959 will become famous soon enough
Re: Joystick Pneumatic Triggering

Can you post the error text, and describe when it happens?
Reply With Quote
  #7   Spotlight this post!  
Unread 02-02-2016, 18:18
JacobD's Avatar
JacobD JacobD is offline
Registered User
AKA: Jacob
FRC #1672 (Mahwah Robo T-Birds)
Team Role: Leadership
 
Join Date: Jan 2015
Rookie Year: 2013
Location: New Jersey
Posts: 90
JacobD is an unknown quantity at this point
Re: Joystick Pneumatic Triggering

Quote:
Originally Posted by CjDace View Post
Hey! our team is trying to do basically the same thing and our code is hitting an error on the "kreverse/kforward" when we try to get our solenoid object do them. we used the code provided above so instead of that i will provide the declaration
Code:
public class Robot extends IterativeRobot {
	    /**
	     * This function is run when the robot is first started up and should be
	     * used for any initialization code.
	     * 
	     */  RobotDrive myDrive, catcherDrive;
	    	Joystick moveStick;
	    	Gyro scotbot;
	    	Solenoid S;
	    	
	    public void robotInit() {
	    	Talon TalLF = new Talon(0);
	    	Talon TalLR = new Talon(1);
	    	Talon TalRF = new Talon(2);
	    	Talon TalRR = new Talon(3);
	    	Talon TalCatcher = new Talon(4);
	    	Talon TalCatcher1 = new Talon(5);
	    	myDrive =  new RobotDrive(TalLF,TalLR,TalRF,TalRR);
	    	moveStick = new Joystick(0);
	    	catcherDrive = new RobotDrive(TalCatcher, TalCatcher1);
	    	scotbot = new ADXRS450_Gyro();
	    	Compressor c = new Compressor(0);
	    	Solenoid S = new Solenoid(1);
	    	
	    }
Is there something very obvious that im missing?
Yes, remember to recognize the scope of your object references. If you declare in robotInit():
Code:
Solenoid S = new Solenoid(1);
That object reference "S" only exists inside of the method robotInit(). So, put this code under public class robot {
Code:
Solenoid S;
and change your code in robotInit() to:
Code:
 S = new Solenoid(1);
Hint*** Do this for all objects ***
__________________
2013-2014: Electrical, Mechanical
2014-2017: Team Captain
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 18:51.

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