|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools |
Rating:
|
Display Modes |
|
#1
|
||||
|
||||
|
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 |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
||||
|
||||
|
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
![]() |
|
#4
|
||||
|
||||
|
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! |
|
#5
|
||||
|
||||
|
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 ()
{
}
Thanks in advance |
|
#6
|
||||
|
||||
|
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
}
}
Code:
public class Main extends RobotMain {
Shooter shooter;
public void robotInit() {
shooter = new Shooter();
}
public void teleopPeriodic() {
shooter.aim();
shooter.shoot();
}
}
You should also take a look at the Java tutorials Oracle has on their website to learn the basics of Java. Last edited by Djur : 03-06-2012 at 19:54. Reason: Oracle tutorials |
|
#7
|
||||
|
||||
|
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();
}
}
}
|
|
#8
|
||||
|
||||
|
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);
}
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()); Code:
setSpeed(Math.abs(controller.getY())); Code:
setSpeed(controller.getY() < 0 ? 0 : controller.getY()); 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);
}
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);
}
}
}
|
|
#9
|
||||
|
||||
|
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. ![]() |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|