Go to Post and as you can see, all rumor threads lead to silly, loads of silly - JaneYoung [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 02-06-2013, 09:17 PM
wickzam wickzam is offline
Registered User
FRC #4591
 
Join Date: Feb 2013
Location: Canada
Posts: 2
wickzam is an unknown quantity at this point
Help programming joystick buttons

Hello we are team number 4591 we are a rookie team. Our programming team consists of 2 people and we have just started programming a few months ago.

We have sucessfully made our robot move forward and backwards using two joysticks.

We need to move two motors at the same time while holding one button to go clockwise and holding another button to go counter clockwise.

We have tried everything we know, but nothing seemed to work. It would be very helpful if someone could give us an example of a code we can use to run the motors.





Here's what we have so far:
Code:
package edu.wpi.first.wpilibj.templates;

import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.buttons.Button;


public class RobotTemplate extends SimpleRobot{

      RobotDrive chassis= new RobotDrive(1, 2);
      Joystick leftStick= new Joystick(1);
      Joystick rightStick= new Joystick(2);
      
public void autonomus() {
      chassis.setSafetyEnabled(false);
      chassis.drive(-0.05, 0.0);
      Timer.delay(30.0);
      chassis.drive(0.0, 0.0);
}

      public void operatorControl() {
      chassis.setSafetyEnabled(true);  {
            chassis.tankDrive(leftStick, rightStick);
            Timer.delay(0.01);

     }
     }
     }
Reply With Quote
  #2   Spotlight this post!  
Unread 02-07-2013, 04:30 PM
The_Colonel The_Colonel is offline
Registered User
FRC #4456
 
Join Date: Feb 2013
Location: Washington, DC
Posts: 4
The_Colonel is an unknown quantity at this point
Re: Help programming joystick buttons

There is a function called getButton() that allows you to use the trigger and top button, and one called getRawButton() that works for the rest of the buttons by number. This page should help you get a complete understanding of the joystick, the buttons, and the rest of the code for the robot.

http://www.wbrobotics.com/javadoc/ed...ge_description
Reply With Quote
  #3   Spotlight this post!  
Unread 02-07-2013, 05:13 PM
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,547
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Help programming joystick buttons

You can use the getRawButton method of the joystick class to get whether a button is being pressed or not.
Reply With Quote
  #4   Spotlight this post!  
Unread 02-07-2013, 06:09 PM
wickzam wickzam is offline
Registered User
FRC #4591
 
Join Date: Feb 2013
Location: Canada
Posts: 2
wickzam is an unknown quantity at this point
Re: Help programming joystick buttons

Quote:
Originally Posted by Joe Ross View Post
You can use the getRawButton method of the joystick class to get whether a button is being pressed or not.
We tried to use getRawButton in our code but every time we use it there is a problem.
if you could show us an example of a code using getRawButton that would be very helpful.
Reply With Quote
  #5   Spotlight this post!  
Unread 02-07-2013, 06:32 PM
Arhowk's Avatar
Arhowk Arhowk is offline
FiM CSA
AKA: Jake Niman
FRC #1684 (The Chimeras) (5460 Mentor)
 
Join Date: Jan 2013
Rookie Year: 2013
Location: Lapeer
Posts: 542
Arhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to beholdArhowk is a splendid one to behold
Re: Help programming joystick buttons

Quote:
Originally Posted by wickzam View Post
We tried to use getRawButton in our code but every time we use it there is a problem.
if you could show us an example of a code using getRawButton that would be very helpful.
i dont get it. whats your problem

Joystick j = new Joystick(1);
JoystickButton a = new JoystickButton(j,1);
a.whileHeld(new YourCommand());

in command based or

Joystick j = new Joystick(1)
if(j.getRawButton(1)){
do stuff
}

in iterative. both will run when A is pressed
Reply With Quote
  #6   Spotlight this post!  
Unread 02-07-2013, 06:38 PM
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,547
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Help programming joystick buttons

Quote:
Originally Posted by wickzam View Post
We tried to use getRawButton in our code but every time we use it there is a problem.
What kind of problem?

Here is an example of using getRawButton to switch between tank drive and arcade drive when the trigger (button one) on the left joystick is pressed.

Code:
    public void operatorControl() {
        chassis.setSafetyEnabled(true);
        
        if (leftStick.getRawButton(1))
        {
            chassis.tankDrive(leftStick, rightStick);
            Timer.delay(0.01);
        }
        else 
        {
            chassis.arcadeDrive(leftStick);
        }
    }
Also, in your original code, your autonomous code won't run because autonomous is misspelled.
Reply With Quote
  #7   Spotlight this post!  
Unread 02-11-2013, 02:06 AM
arithehun arithehun is offline
Registered User
AKA: Ari Falkner
FRC #3024
Team Role: Programmer
 
Join Date: Feb 2011
Rookie Year: 2011
Location: Ashland, Oregon
Posts: 27
arithehun is an unknown quantity at this point
Re: Help programming joystick buttons

Have you heard about command based programming? It is a lot cleaner and will help you avoid creating hundreds (okay, not hundreds) of "else if" blocks and actually set up a polymorphic structure and abstracting your code. It's a specifically tailored design pattern. It's probably too late now, but it's something you should consider next year: http://firstforge.wpi.edu/sf/docman/...tation/doc1297

Last edited by arithehun : 02-11-2013 at 02:27 AM.
Reply With Quote
  #8   Spotlight this post!  
Unread 02-12-2013, 01:01 PM
omalleyj omalleyj is offline
Registered User
AKA: Jim O'Malley
FRC #1279 (Cold Fusion)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2008
Location: New Jersey
Posts: 132
omalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to beholdomalleyj is a splendid one to behold
Re: Help programming joystick buttons

Code:
      public void operatorControl() {
      chassis.setSafetyEnabled(true);  {
            chassis.tankDrive(leftStick, rightStick);
            Timer.delay(0.01);

     }
     }
A quick aside:
Because you are using SimpleRobot you need to put the teleop code in a loop, e.g.:
Code:
      public void operatorControl() {
         chassis.setSafetyEnabled(true);
         while (isOperatorControl && isEnabled() ){
            chassis.tankDrive(leftStick, rightStick);
            Timer.delay(0.01);
         }
      }
The above suggestions for button use are all good, so if they aren't working this might be part of the problem. If you just typed from memory and forgot, ignore this. You also had a superfluous set of braces after you SafetyEnabled, did you accidentally delete something?

Just noticed you have a 30s delay in autonomous. Autonomous mode is only 15s. Unless something changed this year operatorControl() won't be called until autonomous() exits. So you'll be waiting 15s after teleop starts to get control of the 'bot.

Last edited by omalleyj : 02-12-2013 at 01:07 PM. Reason: noticed autonomous delay
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 07:51 AM.

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