Go to Post CD, you are crazy!!! - Tottanka [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 09-11-2012, 05:47 PM
4085's Avatar
4085 4085 is offline
Technical Difficulties
AKA: Sebastian Brosious
FRC #4085 (Technical Difficulties)
Team Role: Programmer
 
Join Date: Feb 2012
Rookie Year: 2012
Location: Reynoldsburg, Ohio
Posts: 14
4085 is an unknown quantity at this point
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);
        }   
    }
}
__________________
_______________________________________________

WE ARE...

Raiders!
Reply With Quote
  #2   Spotlight this post!  
Unread 09-11-2012, 09:40 PM
F22Rapture's Avatar
F22Rapture F22Rapture is offline
College Student, Mentor
AKA: Daniel A
FRC #3737 (4H Rotoraptors)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Goldsboro, NC
Posts: 476
F22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant futureF22Rapture has a brilliant future
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:
Java Starter Guide

http://firstforge.wpi.edu/sf/docman/...tation/doc1199


The starter guide uses the "Iterative Robot" style, but that's been replaced by the "Command-based" style which is a bit more flexible. Command-based splits up the program into Subsystems and Commands instead of having a monolithic block of code. This explains the Command-based model a little bit better.

https://dl.dropbox.com/u/27736599/FR...20Overview.pdf


This is the WPIlib robotics library users guide. WPIlib is the library FRC uses to interface with the various hardware and sensors. It gives a basic overview of all the different default methods which handle robot operation, the hardware and sensors and the functions available to interface with them, and describes some of that hardware.

http://www.wbrobotics.com/attachment...%20Guide. pdf


This is the "Programming Cookbook" which describes in-depth how the Command-based programming works with lots of code examples, and also goes into some of the user-side interface code like SmartDashboard

http://www.wbrobotics.com/attachment...ibCookbook.pdf


And the Javadoc for the WPIlib library, which you don't really need to read but it's there for reference:

http://www.wbrobotics.com/javadoc/in...e-summary.html

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.
Attached Thumbnails
Click image for larger version

Name:	Untitled.png
Views:	30
Size:	219.5 KB
ID:	12981  

Last edited by F22Rapture : 09-11-2012 at 10:05 PM.
Reply With Quote
  #3   Spotlight this post!  
Unread 09-12-2012, 09:39 AM
4085's Avatar
4085 4085 is offline
Technical Difficulties
AKA: Sebastian Brosious
FRC #4085 (Technical Difficulties)
Team Role: Programmer
 
Join Date: Feb 2012
Rookie Year: 2012
Location: Reynoldsburg, Ohio
Posts: 14
4085 is an unknown quantity at this point
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!!
__________________
_______________________________________________

WE ARE...

Raiders!
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:25 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