|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
||||
|
||||
|
Java, The Next Fronteir
Team 4085 enters the next generation of programming, Java, a complex and intricate language. One programmer beta testing the idea by re-writing our robots programming from labveiw to Java. One stepping stone this poor Programmer that knows little to nothing about to java to know, how to make buttons for joysticks.
Please aid me in my quest to program them all. (pokemon, hackers edition) 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;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Victor;
import edu.wpi.first.wpilibj.buttons.JoystickButton;
/**
* 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 Team4085Robot extends SimpleRobot {
RobotDrive Drive = new RobotDrive(1, 2);
Joystick leftStick = new Joystick(1);
Joystick rightStick = new Joystick(2);
Jaguar leftMotor = new Jaguar(1);
Jaguar rightMotor = new Jaguar(2);
Jaguar pickupMotor = new Jaguar(3);
Victor indexMotor = new Victor(4);
Jaguar shootingMotor = new Jaguar(5);
Jaguar armMotor = new Jaguar(6);
JoystickButton button1 = new JoystickButton(leftStick, 1);
/**
* This function is called once each time the robot enters autonomous mode.
*/
public void autonomous() {
for (int i = 0; i < 4; i++) {
Drive.drive(0.5, 0.0); // drive 50% forward speed with 0% turn
Timer.delay(2.0); // Wait 2 seconds
Drive.drive(0.0, 0.75); // drive 0% forward with 75% turn
Timer.delay(0.75); // wait for the 90 degree turn to complete
}
Drive.drive(0.0, 0.0); // drive 0% forward with 0% turn (stop)
}
/**
* This function is called once each time the robot enters operator control.
*/
public void operatorControl() {
while (isOperatorControl() && isEnabled()) // loop during enabled teleop mode
{
Drive.tankDrive(leftStick, rightStick); // drive with the joysticks
Timer.delay(0.005);
}
}
}
|
|
#2
|
||||
|
||||
|
Re: Java, The Next Fronteir
Here's some documentation, most of it you should already have seen before but if you haven't, you should look through it.
Quote:
With that out of the way, I noticed that you're using the SimpleRobot template instead of Command-based. That's not a problem, and the SimpleRobot template should work fine for a testbed robot with very few peripherals or complex commands, but if you try to use it for competition code it's going to get very messy very fast. The new "standard" template to use is the Command-based robot template. Essentially what this does does is instead of having one monolithic chunk of code, it splits it up into separate blocks which each handle a different task. It takes a bit more work to set up, but once you have it's much more manageable and you can add on new functions very quickly without re-writing much code. The 2nd link above and the Cookbook goes into that in a little bit more detail. Here's a series of video tutorials which cover it: http://www.youtube.com/watch?v=v0vt9yKLxUQ If you're going to be using Java code for a competition robot, I would definitely recommend that you go ahead and get familiar with the Command-based style beforehand. A very brief overview of how the C-b template works... Subsystems are primary robot components. The chassis, arms, shooters, etc. are all subsystems. Commands are specific actions taken by subsystems. ExtendArm, DriveStraight, DriveWithJoysticks, etc. are all commands. Now, whenever you need to do something, all you need to do is create a command to do it and you can call it as needed. You can also daisy-chain commands together to perform autonomous tasks without actually writing any new code, and you can call those same commands during teleop as well. All your code that handles the Chassis goes in one file, all the code that handles the shooter goes in another, all the code that handles the Operator Interface goes in another, and all the constants like port numbers and Jaguar IDs goes in another, so you're only ever really looking at one part of the robot at the time. Much easier to read, much easier to troubleshoot, and much easier to find what you need to change. I attached a screenshot of what some of our code looks like at the moment. Even though it looks like a lot, most of the commands only require a few lines of code, and they can do a heck of a lot. Our code, for instance, is able to switch between tank drive, arcade drive, kinect drive, etc with the press of a button on the dashboard, and all of that is achievable with less than 2 dozen lines of additional user-generated code more than what we would have needed anyway. Last edited by F22Rapture : 11-09-2012 at 22:05. |
|
#3
|
||||
|
||||
|
Re: Java, The Next Fronteir
Thank you so much you were major help to me!!!
I'm Very new to this and i'm preparing my self for this years competition by re writing our current robot, but this is major help i don't know how to thank you enough!! |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|