Go to Post If by hazardous you mean thinking about robots 24/7, waking up at 2am in the morning to jot some ideas down, completely losing your social life, and staring at a computer until your eyes hurt, then yeah! :D - looneylin [more]
Home
Go Back   Chief Delphi > FIRST > General Forum
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 11-02-2014, 21:45
aweso_meme aweso_meme is offline
Registered User
FRC #4687
 
Join Date: Feb 2014
Location: Minnesota
Posts: 20
aweso_meme is an unknown quantity at this point
Exclamation Rookie Java FRC programming buttons

Hello all,

I have run into some trouble while attempting to hook up pneumatics to the robot. This is my first time programming for FRC, and the first time my team is developing code. I will paste my code below, but first a description of the problem. The robot does drive. All wires are hooked up to where they should be. However, whenever I pull the trigger on the joystick (Logitech Attack 3), the code does not perform. A solenoid is supposed to trigger rapidly on and off, but the solenoid does not trigger on and off in practice. I am using the basic layout for my code.
Without further ado, here is my code (I do my brackets differently than most):

package edu.wpi.first.wpilibj.templates;
//import statements

public class RobotCode extends simpleRobot {

private RobotDrive drivetrain;
private Joystick driveStick;
Solenoid solenoid;
Trigger jButton;
int j = 0; // standard int which will be used in a for loop.

public void initMethod()
{
// Initialization code goes here
drivetrain = new RobotDrive(1,2,3,4);
driveStick = new Joystick(1);
solenoid = new Solenoid(1);
}
public void autonomous() { }


public void operatorControl()
{
while (true && isOperatorControl() && isEnabled())
{
drivetrain.arcadeDrive(driveStick);
Timer.delay(0.001);
if (driveStick.getTrigger() == true)
{
for (j=0 ; j<3 ; j++)
{
solenoid.set(true);
Timer.delay(0.1);
solenoid.set(false);
Timer.delay(0.1);
} //End For Loop
} // End if Statement
} // End While Statement
} // End Method


public void test() { }
}//END CODE

Thank you for your help. For your reference, I have coded in Java before and am currently in AP Computer Science.
Reply With Quote
  #2   Spotlight this post!  
Unread 11-02-2014, 22:53
tStano tStano is offline
Registered User
AKA: Sparks
no team
Team Role: Electrical
 
Join Date: Jan 2014
Rookie Year: 2012
Location: Madison, WI
Posts: 177
tStano will become famous soon enough
Re: Rookie Java FRC programming buttons

It appears that you have not initialized your button. You initialized the joystick but you need to initialize the button as well. Thats my best guess.

Also, If this is a pneumatic solenoid and you're expecting it to go in and out; it wont; you'll need a second solenoid object for the retract. If its an electrical or single action solenoid, ignore this bit, I have no experience in those areas.

Last edited by tStano : 11-02-2014 at 23:19. Reason: Addded bit about solenoids
Reply With Quote
  #3   Spotlight this post!  
Unread 12-02-2014, 00:39
Domenic Rodriguez's Avatar
Domenic Rodriguez Domenic Rodriguez is offline
Registered User
FRC #0316 (LuNaTeCs)
Team Role: College Student
 
Join Date: Sep 2010
Rookie Year: 2011
Location: Grove City, PA
Posts: 213
Domenic Rodriguez has a spectacular aura aboutDomenic Rodriguez has a spectacular aura aboutDomenic Rodriguez has a spectacular aura about
Re: Rookie Java FRC programming buttons

When using joysticks, I generally use the Joystick#getRawButton() method as opposed to the specialized methods. You might want to try using:
Code:
...
if (driveStick.getRawButton(1))  // '== true' is not necessary in an if statement for a boolean
{
...
You can use System.out.println() statements inside the if statement to help you track down the issue. That will show you if the issue is the Joystick button or the solenoid code.

You may have already done this, but you should check the lights on top of the solenoid module while the code runs to ensure that you indeed have a code issue.

Quote:
Originally Posted by tStano
It appears that you have not initialized your button. You initialized the joystick but you need to initialize the button as well. Thats my best guess.
Correct me if I'm wrong, but the Trigger and Button classes are for use with the Command Based robot patern. OP is using SimpleRobot as the base class, and thus shouldn't be using Buttons or Triggers.

(Protip: if you wrap your code in [code][/code] tags, it will format nicer.)
__________________

LuNaTeCs - Learning Under Nurturing Adults Teaching Engineering Concepts and Skills - Small and Mighty!

FRC 316 LuNaTeCs - Student (2011-2014), Lead Programmer (2011-2014), Team Captain (2013-2014), Operator (2013), Drive Coach (2014), Mentor (2015-????)
'11 Philly Regional Finalists, '13 Chestnut Hill Finalists, '13 Lenape Champions, '13 Archimedes Division, '14 Chestnut Hill Champions, '14 Lenape Champions
FTC 7071 EngiNerds - Founding Advisor (2013-2014) | FRC 5420 Velocity - Founding Advisor (2015)
Grove City College Class of '18, Electrical/Computer Engineering (B.S.E.E)

Reply With Quote
  #4   Spotlight this post!  
Unread 12-02-2014, 11:12
seg9585's Avatar
seg9585 seg9585 is offline
Registered User
AKA: Eric
FRC #4276 (Surf City Vikings)
Team Role: Engineer
 
Join Date: Feb 2006
Rookie Year: 2001
Location: Boeing (Seal Beach, CA)
Posts: 520
seg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond repute
Re: Rookie Java FRC programming buttons

Quote:
Originally Posted by DomenicR View Post
When using joysticks, I generally use the Joystick#getRawButton() method as opposed to the specialized methods.
According to the code above they are using the Joystick class, not Trigger (there is a "jButton" initialized but its not used). They are properly using the Joystick class. I will note that I have had trouble with the trigger in the past as well, and resort to just using buttons.

As a form of troubleshooting, why don't you use a Button instead to test and see if the Trigger is causing the issue?

In other news, I don't think the code you have there will do exactly what you want. When the trigger is pushed you will enter that for{} loop, but every 0.2001 seconds you will be re-entering that loop until the finger is taken off the trigger.
I assume you want to just toggle the valves 3 times and that's it when the button is pushed? If so, you'll need to add a little logic that checks whether the button has just been pressed. For example:

boolean triggered=false;

if(driveStick.getTrigger() && !triggered){
triggered=true;
for{} loop;}

else if(!driveStick.getTrigger()){
triggered=false;}

In other news, avoid using local for and while loops in SimpleRobot. While that loop is running, you will not get any Drive updates. For just 0.2 seconds maybe you can get away with it, but not good practice in general. Instead, you can either create a separate thread (See Thread class), or what I like to do is create a function that will track its own timing when called repeatedly and return a true or false boolean to indicate when it's done (use the Timer class)
__________________
My FIRST legacy:

Team 204 Student 2001, 2002 (Voorhees, NJ)
Team 1493 College Mentor 2006 - 2008 (Troy, NY)
Team 2150 Intern/Professional Mentor 2007, 2009 (Palos Verdes)
Team 4123 Lead Engineering Mentor 2012 (Bellflower, CA)
Team 4276 Engineering Mentor 2012-2016 (Huntington Beach, CA)

Last edited by seg9585 : 12-02-2014 at 11:16.
Reply With Quote
  #5   Spotlight this post!  
Unread 12-02-2014, 17:19
aweso_meme aweso_meme is offline
Registered User
FRC #4687
 
Join Date: Feb 2014
Location: Minnesota
Posts: 20
aweso_meme is an unknown quantity at this point
Exclamation Re: Rookie Java FRC programming buttons

So what would be the code for creating a Thread class?
Do I need to create a new class inside my current package, and then in the main class call Loop xyz = new Loop();, or do i need a certain constructor? Also, with xyz.start(); I read on the internet that these threads have precedence. Does this mean I can have the main class running at the same time or no?

EDIT: Also, If I do need to make a new class, what methods do I need to define and how do I call them in the tele-op method?

Thanks again.

Last edited by aweso_meme : 12-02-2014 at 17:22.
Reply With Quote
  #6   Spotlight this post!  
Unread 13-02-2014, 01:10
seg9585's Avatar
seg9585 seg9585 is offline
Registered User
AKA: Eric
FRC #4276 (Surf City Vikings)
Team Role: Engineer
 
Join Date: Feb 2006
Rookie Year: 2001
Location: Boeing (Seal Beach, CA)
Posts: 520
seg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond reputeseg9585 has a reputation beyond repute
Re: Rookie Java FRC programming buttons

Quote:
Originally Posted by aweso_meme View Post
So what would be the code for creating a Thread class?
Do I need to create a new class inside my current package, and then in the main class call Loop xyz = new Loop();, or do i need a certain constructor? Also, with xyz.start(); I read on the internet that these threads have precedence. Does this mean I can have the main class running at the same time or no?

EDIT: Also, If I do need to make a new class, what methods do I need to define and how do I call them in the tele-op method?

Thanks again.
You need to create a new Java file, with the name the same as your new class (this is the case for any class -- which you can call by adding to your project and creating an object of your new Class name.

For a "Thread" example:

class YourNewClass extends Thread {

YourNewClass(int x) {
//This is the constructor
}

public void run() {
//Put a while() loop in here
. . .
}
}

from your teleop class:

YourNewClass triggeraction = new YourNewClass();
triggeraction.setPriority(1); //The lower the priority, the thread will be executed last in the computing cycles. teleOp is top priority
triggeraction.run();

while(isEnabled()){....
__________________
My FIRST legacy:

Team 204 Student 2001, 2002 (Voorhees, NJ)
Team 1493 College Mentor 2006 - 2008 (Troy, NY)
Team 2150 Intern/Professional Mentor 2007, 2009 (Palos Verdes)
Team 4123 Lead Engineering Mentor 2012 (Bellflower, CA)
Team 4276 Engineering Mentor 2012-2016 (Huntington Beach, CA)
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:34.

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