Go to Post No really though, a robot game with rules similar to Risk. This would combine FIRST, Battlebots, and US Government... - Betty_Krocker [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 22-03-2012, 10:32
Team1605 Team1605 is offline
Registered User
FRC #1605
 
Join Date: Feb 2012
Location: toronto
Posts: 30
Team1605 is an unknown quantity at this point
Help !!!!

i need serious help how can i get the buttons to work on my joystick how do i program it ??? here is my code is it correct ??

Code:
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.                             */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project.                                                               */
/*----------------------------------------------------------------------------*/

package edu.wpi.first.wpilibj.templates;


import edu.wpi.first.wpilibj.Joystick.AxisType;
import edu.wpi.first.wpilibj.*;

/**
 * The VM is configured to automatically run this class, and to call the
 * functions corresponding to each mode, as described in the SimpleRobot
 * documentation. If you change the name of this class or the package after
 * creating this project, you must also update the manifest file in the resource
 * directory.
 */
public class Team1605 extends SimpleRobot {
    
    
    Joystick stickDriverLeft = new Joystick(1);
    Joystick stickDriverRight = new Joystick(2);
    
    
    Jaguar leftMotor = new Jaguar(2);
    Jaguar rightMotor = new Jaguar(1);
    Jaguar shooterMotor1 = new Jaguar(3);
    Jaguar shooterMotor2 = new Jaguar(4);
    Jaguar gatherMotor1 = new Jaguar(5);
    Jaguar gatherMotor2 = new Jaguar (6);
    
    RobotDrive robotDrive = new RobotDrive(leftMotor,rightMotor);
    Shooter shooter = new Shooter(shooterMotor1,shooterMotor2);
    Gatherer gatherer = new Gatherer(gatherMotor1, gatherMotor2);
    
    final int TRIGGER_NUMBER = 1;
    final int GATHER_START_BUTTON = 2;
    final int GATHER_STOP_BUTTON = 3;
    
    
    /**
     * This function is called once each time the robot enters autonomous mode.
     */
    public void autonomous() {
        
    }

    /**
     * This function is called once each time the robot enters operator control.
     */
    public void OperatorControl() {
        while(isOperatorControl() && isEnabled())
    {
        
        robotDrive.tankDrive(stickDriverLeft.getAxis(AxisType.kY), stickDriverRight.getAxis(AxisType.kY));
        
        
        if(stickDriverRight.getRawButton(TRIGGER_NUMBER)) {
           shooter.set(1);
        }
        else {
            shooter.set(0);
        }
        
        
        if(stickDriverRight.getRawButton(GATHER_START_BUTTON)) {
            gatherer.set(1);
        }
        else if(stickDriverRight.getRawButton(GATHER_STOP_BUTTON)) {
            gatherer.set(0);
        }
        Timer.delay(.01);
    }

    }
}
Reply With Quote
  #2   Spotlight this post!  
Unread 22-03-2012, 13:02
2869Robotics 2869Robotics is offline
Registered User
FRC #2869
 
Join Date: Jan 2012
Location: Bethpage
Posts: 18
2869Robotics is an unknown quantity at this point
Re: Help !!!!

The way that you have your trigger set up. As long as you hold the trigger down the shooter will be set at 1 but if you let go of the trigger it will be set back at 0. Do you want the trigger to toggle the shooter on and off?
Reply With Quote
  #3   Spotlight this post!  
Unread 28-03-2012, 13:37
NS_Radication's Avatar
NS_Radication NS_Radication is offline
Student
AKA: Marco Schoener
FRC #1369 (Minotaur)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2009
Location: Tampa
Posts: 88
NS_Radication is an unknown quantity at this point
Re: Help !!!!

Can someone posta code for a toggle button or for an array of buttons that can change speeds with a press, not held down? This would be very help!

Thank you and Happy Competition!
__________________
Team 1369
Senior
Head Programmer (Java)
Head Electrician
Reply With Quote
  #4   Spotlight this post!  
Unread 28-03-2012, 15:23
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: Help !!!!

Both toggle and cycle buttons are based on a button "press" instead of just being held down. To detect when a button is pressed:
Code:
// outside the "checking" loop
boolean prevState = false;

// inside checking loop; can be within continuous or periodic
boolean currentState = joy.getRawButton(DESIRED_BUTTON);
if(currentState && !prevState) {
    // Button DESIRED_BUTTON is newly pressed
    // Do stuff here
}
prevState = currentState;
To do a toggle, have an extra boolean (e.g. tracking), then when the button is pressed:
Code:
tracking = !tracking;
To do a cycle, have an int (e.g. basketChoice) and do this on button pressed:
Code:
basketChoice = (basketChoice+1)%NUM_CHOICES;
Reply With Quote
  #5   Spotlight this post!  
Unread 28-03-2012, 15:52
Team1605 Team1605 is offline
Registered User
FRC #1605
 
Join Date: Feb 2012
Location: toronto
Posts: 30
Team1605 is an unknown quantity at this point
Re: Help !!!!

i need help. in tank drive one of my wheels keep spinning and the other responds properly with one joystick.MY SHOOTER GATHERER AND BRIDGE HAND WORK. how can i fix this. this is my code :

Code:
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.                             */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project.                                                               */
/*----------------------------------------------------------------------------*/

package edu.wpi.first.wpilibj.templates;


import edu.wpi.first.wpilibj.Joystick.AxisType;
import edu.wpi.first.wpilibj.*;

/**
 * The VM is configured to automatically run this class, and to call the
 * functions corresponding to each mode, as described in the SimpleRobot
 * documentation. If you change the name of this class or the package after
 * creating this project, you must also update the manifest file in the resource
 * directory.
 */
public class Team1605 extends SimpleRobot {
    
    
    Joystick stickDriverLeft = new Joystick(1);
    Joystick stickDriverRight = new Joystick(2);
    
    
    Jaguar leftMotor = new Jaguar(2);
    Jaguar rightMotor = new Jaguar(1);
    Jaguar shooterMotor1 = new Jaguar(3);
    Jaguar shooterMotor2 = new Jaguar(4);
    Jaguar gatherMotor1 = new Jaguar(5);
    Jaguar gatherMotor2 = new Jaguar (6);
    Victor bridgeHandMotor = new Victor(7);
    RobotDrive robotDrive = new RobotDrive(leftMotor,rightMotor);
    Shooter shooter = new Shooter(shooterMotor1,shooterMotor2);
    Gatherer gatherer = new Gatherer(gatherMotor1, gatherMotor2);
    BridgeHand bridgeHand = newBridgHand(bridgeHandMotor);
    
    
    
    /**
     * This function is called once each time the robot enters autonomous mode.
     */
    public void autonomous() {
        
    }

    /**
     * This function is called once each time the robot enters operator control.
     */
    public void OperatorControl() {
        while(isOperatorControl() && isEnabled())
    {
        
        robotDrive.tankDrive(stickDriverLeft.getAxis(Joystick.AxisType.kY), stickDriverRight.getAxis(Joystick.AxisType.kY));
        
        
        if(stickDriverRight.getButton(Joystick.AxisType.kTrigger)) {
           shooter.set(1);
        }
        else {
            shooter.set(0);
        }
        
        
        if(stickDriverLeft.getButton(Joystick.ButtonType.kTrigger)) {
            gatherer.set(1);
        }
        else {
            gatherer.set(0);
        }
            bridgeHand.set(stickDriverRight.getAxis(Joystick.AxisType.kX));
        
Timer.delay(.01);
    }

    }
}
Reply With Quote
  #6   Spotlight this post!  
Unread 28-03-2012, 23:59
NS_Radication's Avatar
NS_Radication NS_Radication is offline
Student
AKA: Marco Schoener
FRC #1369 (Minotaur)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2009
Location: Tampa
Posts: 88
NS_Radication is an unknown quantity at this point
Re: Help !!!!

Quote:
Originally Posted by Ginto8 View Post
To do a cycle, have an int (e.g. basketChoice) and do this on button pressed:
Code:
basketChoice = (basketChoice+1)%NUM_CHOICES;
What can this do? Could this be used to add a ball count to the robot.
__________________
Team 1369
Senior
Head Programmer (Java)
Head Electrician
Reply With Quote
  #7   Spotlight this post!  
Unread 29-03-2012, 10:20
Ginto8's Avatar
Ginto8 Ginto8 is offline
Programming Lead
AKA: Joe Doyle
FRC #2729 (Storm)
Team Role: Programmer
 
Join Date: Oct 2010
Rookie Year: 2010
Location: Marlton, NJ
Posts: 174
Ginto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of lightGinto8 is a glorious beacon of light
Re: Help !!!!

Quote:
Originally Posted by NS_Radication View Post
What can this do? Could this be used to add a ball count to the robot.
This is called modular arithmetic. You probably don't want to use that particular method for counting balls, because if, for example, your NUM_CHOICES were 3, then as balls enter the count would go 0,1,2,0,1,2, instead of 0,1,2,3,4 as they entered and 4,3,2,1,0 as they left.
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 11:41.

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