Go to Post Who would think 130 points would be a losing score! - Chris Fultz [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 Rating: Thread Rating: 5 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 02-06-2012, 20:12
2185Bilal's Avatar
2185Bilal 2185Bilal is offline
Driver, Ld. Programmer, Electrical
AKA: Bilal Majeed
FRC #2185 (Ramazoidz)
Team Role: Programmer
 
Join Date: Feb 2012
Rookie Year: 2011
Location: Toronto, Canada
Posts: 110
2185Bilal will become famous soon enough
Smile Java Robot Template

Hey,

We just switched from Labview Programming to Java.

And i have a question:

Which template is the best to program or wat are the benefits and disadvantages

by templates i mean the java robot templates (ie Simple Robot Template, iterative robot template, command based template)

Thanks very much
__________________
RAMAZOIDZ

2009 Toronto West Regional - Regional Winners
2009 Waterloo Regional - Regional Winners
Reply With Quote
  #2   Spotlight this post!  
Unread 02-06-2012, 21:48
AlexD744 AlexD744 is offline
Registered User
FRC #0744 (744 Shark Attack)
Team Role: Alumni
 
Join Date: Jan 2009
Rookie Year: 2008
Location: Ft. Lauderdale, FL
Posts: 639
AlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond reputeAlexD744 has a reputation beyond repute
Re: Java Robot Template

I've had experience with both the iterative template and the command-based template. I've only glossed over the simple template. However, I would say that the command-based template was extremely easy to use once you got the hang of it. It was a weird switch from iterative, but it made autonomous programming go so much faster with the addParallel and addSequential commands. WaitCommand was also really handy to have, instead of having to creat your own. However, I would practice with it before using it in season, just because it's different and takes a little getting used to. At least it did for me.

As far as iterative goes, it's not too different from command based, except there's a lot more grunt work involved in creating autonomous, including a state machine. However, it's still doable and a great template. And I guess to be fair, the command based template has a lot more grunt work in creating classes, but I found that easier than creating a state machine.

I don't know much about simple robot.

If you haven't you should peruse some of the documentation that FIRST has, including the cookbook and the getting started guide.
__________________
www.sharkattack744.com
Reply With Quote
  #3   Spotlight this post!  
Unread 03-06-2012, 09:54
2185Bilal's Avatar
2185Bilal 2185Bilal is offline
Driver, Ld. Programmer, Electrical
AKA: Bilal Majeed
FRC #2185 (Ramazoidz)
Team Role: Programmer
 
Join Date: Feb 2012
Rookie Year: 2011
Location: Toronto, Canada
Posts: 110
2185Bilal will become famous soon enough
Cool Re: Java Robot Template

Thank u, I want to learn the iterative robot template, but i cant find any manuals or reference guides to learn from. Would some one plz help me and suggesting Any documentation
__________________
RAMAZOIDZ

2009 Toronto West Regional - Regional Winners
2009 Waterloo Regional - Regional Winners
Reply With Quote
  #4   Spotlight this post!  
Unread 03-06-2012, 10:36
Mr. Lim Mr. Lim is offline
Registered User
AKA: Mr. Lim
no team
Team Role: Leadership
 
Join Date: Jan 2004
Rookie Year: 1998
Location: Toronto, Ontario
Posts: 1,125
Mr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond repute
Re: Java Robot Template

I would start at this link:

http://firstforge.wpi.edu/sf/docman/..._documentation

Starting with this document:
Java Getting Started guide

Then this one:
WPI Robotics Library Users Guide

Lastly, this one:
2012 WPILib Cookbook

Good luck!

If you have any questions, just post here!
__________________
In life, what you give, you keep. What you fail to give, you lose forever...
Reply With Quote
  #5   Spotlight this post!  
Unread 03-06-2012, 15:37
2185Bilal's Avatar
2185Bilal 2185Bilal is offline
Driver, Ld. Programmer, Electrical
AKA: Bilal Majeed
FRC #2185 (Ramazoidz)
Team Role: Programmer
 
Join Date: Feb 2012
Rookie Year: 2011
Location: Toronto, Canada
Posts: 110
2185Bilal will become famous soon enough
Post Re: Java Robot Template

Thank very much...

So I have decided to use the Iterative Robot Template.

But I have a question:
I created a new method with this code:
Code:
public void shooter () 
{

}
Now how do i call this method in the telopInit() method

Thanks in advance
__________________
RAMAZOIDZ

2009 Toronto West Regional - Regional Winners
2009 Waterloo Regional - Regional Winners
Reply With Quote
  #6   Spotlight this post!  
Unread 03-06-2012, 19:02
Djur's Avatar
Djur Djur is offline
WPILib
AKA: Sam Carlberg
no team
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2009
Location: Massachusetts
Posts: 182
Djur will become famous soon enough
Re: Java Robot Template

You would be better off creating a new class for the "Shooter" object and have that contain such methods as "shoot()" and "aim()". For example:

Code:
public class Shooter {

    public Shooter() {
        //initialization code goes here
    }

    public void shoot() {
        //code goes here
    }

    public void aim() {
        //code goes here
    }

}
Then in your main class:
Code:
public class Main extends RobotMain {

    Shooter shooter;

    public void robotInit() {
        shooter = new Shooter();
    }

    public void teleopPeriodic() {
        shooter.aim();
        shooter.shoot();
    }

}
Calling a method in teleopInit() is not recommended because it is only called once, when the robot enters teleop period. You would be better off calling it in teleopPeriodic, which updates about every 50 ms, or in teleopContinuous, which updates as fast as possible.

You should also take a look at the Java tutorials Oracle has on their website to learn the basics of Java.
__________________
WPILib dev (RobotBuilder, SmartDashboard, GRIP)

Last edited by Djur : 03-06-2012 at 19:54. Reason: Oracle tutorials
Reply With Quote
  #7   Spotlight this post!  
Unread 03-06-2012, 21:11
2185Bilal's Avatar
2185Bilal 2185Bilal is offline
Driver, Ld. Programmer, Electrical
AKA: Bilal Majeed
FRC #2185 (Ramazoidz)
Team Role: Programmer
 
Join Date: Feb 2012
Rookie Year: 2011
Location: Toronto, Canada
Posts: 110
2185Bilal will become famous soon enough
Re: Java Robot Template

Thanks you very much

Now i have one more question how do i set the speed of a motor with a joystick

This is what i have right now:

Code:
package bilal.robotics.code;

import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Joystick.ButtonType;


public class Shooter 
{
    Jaguar shooter = new Jaguar(5);
    
    Joystick controller = new Joystick(2);
    
    final int buttonA = 1;
    
       
    
    public Shooter()
    {
        
    }
    
    public void shoot(){
        if(controller.getRawButton(buttonA)) {
            shooter.set();
        }
    }
    
}
I want the shooter motor to run according to the value of axis Y on the joystick when button A is pressed
__________________
RAMAZOIDZ

2009 Toronto West Regional - Regional Winners
2009 Waterloo Regional - Regional Winners
Reply With Quote
  #8   Spotlight this post!  
Unread 03-06-2012, 21:44
Djur's Avatar
Djur Djur is offline
WPILib
AKA: Sam Carlberg
no team
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2009
Location: Massachusetts
Posts: 182
Djur will become famous soon enough
Re: Java Robot Template

Well, you would need to define a "setSpeed()" method, something like this:
Code:
public void setSpeed(double speed) {
    shooterJaguar.set(speed);
}
I would recommend that you change the name of your jaguar to something like "shooterJag" or at least not "shooter" which is the name of your class - it could get confusing.

Now, on to your question. The Joystick class has getX(), getY(), and getZ() methods that return values between -1 and 1 based on the Joystick's movement on those axes. A simple way to do it would be
Code:
setSpeed(controller.getY());
but it would spin the shooter backwards if you moved the joystick backwards on the y-axis. A good way to do this would be
Code:
setSpeed(Math.abs(controller.getY()));
or

Code:
setSpeed(controller.getY() < 0 ? 0 : controller.getY());
The first snippet spins the shooter no matter what value the joystick is sending out -- if it goes into the negative range, it just uses the absolute value as if you were moving it in the positive range.

The second snippet will only spin the shooter if the joystick is in the positive range. If it is returning values that are less than zero, it will set the shooter speed to zero, else it will use the value that it's giving.

Also, you should have an else statement in your "shoot()" method that resets the speed to zero because Jaguars will keep running at the last speed they have been set to. If you don't have this, it will keep spinning at the speed it had been set to when you take your finger off of buttonA. It's really easy to do this -- just add this to the end of the if statement in the "shoot()" method.

Code:
} else {
    setSpeed(0);
}
So your class would look something like this:

Code:
package bilal.robotics.code;

import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Joystick.ButtonType;


public class Shooter {

    Jaguar shooterJaguar = new Jaguar(5);
    
    Joystick controller = new Joystick(2);
    
    final int buttonA = 1;
    
    public Shooter() {
        
    }

    public void setSpeed(double speed) {
        shooterJaguar.set(speed);
    }
    
    public void shoot() {
        if(controller.getRawButton(buttonA)) {
            setSpeed(controller.getY() < 0 ? 0 : controller.getY());
        } else {
            setSpeed(0);
        }
    }
    
}
__________________
WPILib dev (RobotBuilder, SmartDashboard, GRIP)
Reply With Quote
  #9   Spotlight this post!  
Unread 06-06-2012, 22:23
2185Bilal's Avatar
2185Bilal 2185Bilal is offline
Driver, Ld. Programmer, Electrical
AKA: Bilal Majeed
FRC #2185 (Ramazoidz)
Team Role: Programmer
 
Join Date: Feb 2012
Rookie Year: 2011
Location: Toronto, Canada
Posts: 110
2185Bilal will become famous soon enough
Cool Re: Java Robot Template

Thank you very much

Would you please help with my other thread, named "Code and Deployment Help". No one has seemed to have answered it.
__________________
RAMAZOIDZ

2009 Toronto West Regional - Regional Winners
2009 Waterloo Regional - Regional Winners
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 13: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