Go to Post FIRST competitions ARE holidays, or they should be at least. - Kel D [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 17-01-2012, 17:16
touchdownjesus4's Avatar
touchdownjesus4 touchdownjesus4 is offline
Registered User
AKA: Tyler Vonderhaar
FRC #4028 (Eagle Robotics)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Cincinnati, OH
Posts: 64
touchdownjesus4 is on a distinguished road
Simple Tankdrive with 4 CIMs

Hello all,

I'm part of a newbie team this year and after some research and long hours of watching videos I have a basic idea of the concepts of java programming, but I'm not quite sure how to actually write code that will be able to drive the robot.

My first task is to find out how to write the code using tank drive with 4 CIM motors. Our team is planning on using the two included joysticks for left and right motor control.

It seems like setting up the tank drive system is relatively easy (to experienced programmers) but I don't even know where to start. Can any of you offer any guidance as to how write the code for a tank drive system?

I have downloaded Netbeans and the FRC plugins so I think I am ready to start writing code. Any help would be greatly appreciated, thanks!
Reply With Quote
  #2   Spotlight this post!  
Unread 17-01-2012, 19:09
neal's Avatar
neal neal is offline
Neal
FRC #1777 (Viking Robotics)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2009
Location: United States
Posts: 56
neal is an unknown quantity at this point
Re: Simple Tankdrive with 4 CIMs

This might help. You probably need to start from 'Creating a new Project...' on page 9 since you're already installed everything.
Reply With Quote
  #3   Spotlight this post!  
Unread 17-01-2012, 19:12
Happy Birthday! Derschatten Derschatten is offline
Registered User
FRC #1203 (Pandemonium)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2003
Location: West Babylon
Posts: 31
Derschatten is an unknown quantity at this point
Re: Simple Tankdrive with 4 CIMs

I would suggest loading one of the FRC sample projects this will show you plus give you a good point to start changing code. This is done by going to File -> New Project -> Samples -> FRC Java -> then choose a project.

Also check out the below links.

Java CookBook
WPI Robotics Library Users Guide
Java Getting started
Brad Miller Videos
Java doc

If you need some detail help you can always PM me.
Reply With Quote
  #4   Spotlight this post!  
Unread 17-01-2012, 19:34
touchdownjesus4's Avatar
touchdownjesus4 touchdownjesus4 is offline
Registered User
AKA: Tyler Vonderhaar
FRC #4028 (Eagle Robotics)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Cincinnati, OH
Posts: 64
touchdownjesus4 is on a distinguished road
Re: Simple Tankdrive with 4 CIMs

Ok so I have read over all those documents and followed the getting started with Java guide to put together some code using simple robot template.

here is my code:

Quote:
package edu.wpi.first.wpilibj.templates;


import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SimpleRobot;


public class TankDrive extends SimpleRobot {

RobotDrive drive = new RobotDrive(1,2,3,4);
Joystick leftStick = new Joystick(1);
Joystick rightStick = new Joystick(2);


public void operatorControl()
{
while(isOperatorControl() && isEnabled())

{
drive.tankDrive(leftStick, rightStick);
}
}
}
I basically just copied the quick start guide...

Some questions:

1) is this code even going to do anything?
2) when you create the joystick objects and put (1) and (2) for ports, how does the computer know that joysticks are connected? Same for the motors, is just putting 1,2,3,4 for the 4 motors going to work? (I guess I just don't fully understand what ports we are connecting the motors and the joysticks to)
3) I think our team is planning on using the command based template when we code for the full robot, how do I implement this type of thing using the subsystem, command base, OI, and all of the different java files that go along with it? (It seems like the different parts need to be split up in order to work properly)

Last edited by touchdownjesus4 : 17-01-2012 at 19:45.
Reply With Quote
  #5   Spotlight this post!  
Unread 17-01-2012, 21:33
Happy Birthday! Derschatten Derschatten is offline
Registered User
FRC #1203 (Pandemonium)
Team Role: Mentor
 
Join Date: Jan 2008
Rookie Year: 2003
Location: West Babylon
Posts: 31
Derschatten is an unknown quantity at this point
Re: Simple Tankdrive with 4 CIMs

1) is this code even going to do anything? I am going to say yes. seem like no errors.
2) when you create the joystick objects and put (1) and (2) for ports, how does the computer know that joysticks are connected? You can see the Joystick and what port they are connected to by looking at the driverstation.
Same for the motors, is just putting 1,2,3,4 for the 4 motors going to work?Yes, this will work. These will be the PWM of the digtal side card. I would suggest doing this tho Jaguar LeftFront = new Jaguar(1); ...
3) I think our team is planning on using the command based template when we code for the full robot, how do I implement this type of thing using the subsystem, command base, OI, and all of the different java files that go along with it? I would watch the videos i linked.
Reply With Quote
  #6   Spotlight this post!  
Unread 17-01-2012, 21:47
touchdownjesus4's Avatar
touchdownjesus4 touchdownjesus4 is offline
Registered User
AKA: Tyler Vonderhaar
FRC #4028 (Eagle Robotics)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Cincinnati, OH
Posts: 64
touchdownjesus4 is on a distinguished road
Re: Simple Tankdrive with 4 CIMs

Quote:
Originally Posted by Derschatten View Post
1) is this code even going to do anything? I am going to say yes. seem like no errors.
2) when you create the joystick objects and put (1) and (2) for ports, how does the computer know that joysticks are connected? You can see the Joystick and what port they are connected to by looking at the driverstation.
Same for the motors, is just putting 1,2,3,4 for the 4 motors going to work?Yes, this will work. These will be the PWM of the digtal side card. I would suggest doing this tho Jaguar LeftFront = new Jaguar(1); ...
3) I think our team is planning on using the command based template when we code for the full robot, how do I implement this type of thing using the subsystem, command base, OI, and all of the different java files that go along with it? I would watch the videos i linked.
Thanks! So to deploy this to the robot I would connect the computer to the cRIO and then hit the "run" button? Will operator control be enabled automatically?

Last edited by touchdownjesus4 : 17-01-2012 at 21:52.
Reply With Quote
  #7   Spotlight this post!  
Unread 17-01-2012, 21:50
neal's Avatar
neal neal is offline
Neal
FRC #1777 (Viking Robotics)
Team Role: Mentor
 
Join Date: Jan 2012
Rookie Year: 2009
Location: United States
Posts: 56
neal is an unknown quantity at this point
Re: Simple Tankdrive with 4 CIMs

Everything looks right assuming you have 4 motors plugged to PWM 1,2,3,4 respectively to what RobotDrive method wants.

And like they said, you can always check and drag joysticks in the Driver Station.
Reply With Quote
  #8   Spotlight this post!  
Unread 17-01-2012, 21:55
touchdownjesus4's Avatar
touchdownjesus4 touchdownjesus4 is offline
Registered User
AKA: Tyler Vonderhaar
FRC #4028 (Eagle Robotics)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Cincinnati, OH
Posts: 64
touchdownjesus4 is on a distinguished road
Re: Simple Tankdrive with 4 CIMs

Quote:
Originally Posted by neal View Post
Everything looks right assuming you have 4 motors plugged to PWM 1,2,3,4 respectively to what RobotDrive method wants.

And like they said, you can always check and drag joysticks in the Driver Station.
Are ports 1/2 for the left motors and 3/4 for the right? Just making sure we set it up correctly
Reply With Quote
  #9   Spotlight this post!  
Unread 17-01-2012, 21:57
Robby Unruh's Avatar
Robby Unruh Robby Unruh is offline
*insert random dial-up tone here*
FRC #3266 (Robots R Us)
Team Role: Coach
 
Join Date: Feb 2010
Rookie Year: 2010
Location: Eaton, OH
Posts: 338
Robby Unruh will become famous soon enough
Re: Simple Tankdrive with 4 CIMs

Quote:
Originally Posted by touchdownjesus4 View Post
Are ports 1/2 for the left motors and 3/4 for the right? Just making sure we set it up correctly
(Front Left, Rear Left, Front Right, Rear Right) is the order. So, yes, that is correct.
__________________
[Robots R Us #3266]
2015: Georgia Southern Classic (Winners / Thanks 1319 & 1648!), Queen City
2014: Crossroads, Queen City
2013: Buckeye, Queen City, Crossroads
2012: Buckeye, Queen City

2011: Buckeye
2010: Buckeye
Reply With Quote
  #10   Spotlight this post!  
Unread 17-01-2012, 22:04
touchdownjesus4's Avatar
touchdownjesus4 touchdownjesus4 is offline
Registered User
AKA: Tyler Vonderhaar
FRC #4028 (Eagle Robotics)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Cincinnati, OH
Posts: 64
touchdownjesus4 is on a distinguished road
Re: Simple Tankdrive with 4 CIMs

Quote:
Originally Posted by Robby Unruh View Post
(Front Left, Rear Left, Front Right, Rear Right) is the order. So, yes, that is correct.
ok great, thanks
Reply With Quote
  #11   Spotlight this post!  
Unread 17-01-2012, 22:41
cgmv123's Avatar
cgmv123 cgmv123 is offline
FRC RI/FLL Field Manager
AKA: Max Vrany
FRC #1306 (BadgerBOTS)
Team Role: College Student
 
Join Date: Jan 2011
Rookie Year: 2011
Location: Madison, WI
Posts: 2,085
cgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond reputecgmv123 has a reputation beyond repute
Re: Simple Tankdrive with 4 CIMs

Quote:
Originally Posted by touchdownjesus4 View Post
Will operator control be enabled automatically?
No, you have to click enable in the Driver Station. This is for safety reasons, among other things.
__________________
BadgerBOTS Robotics|@team1306|Facebook: BadgerBOTS
2016 FIRST Championship Tesla Division | 2016 Wisconsin Regional Engineering Inspiration Award

2015 FIRST Championship Carson Division | 2015 Wisconsin Regional Chairman's Award

2013 FIRST Championship Curie Division | 2013 Wisconsin Regional Chairman's Award

2012 FIRST Championship Archimedes Division | 2012 Wisconsin Regional Engineering Inspiration Award, Woodie Flowers Finalist Award (Lead Mentor Ben Senson)

Reply With Quote
  #12   Spotlight this post!  
Unread 17-01-2012, 23:08
gixxy's Avatar
gixxy gixxy is offline
Programming and Arduino Mentor
AKA: Gustave Michel III
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Nov 2011
Rookie Year: 2012
Location: Ruston, LA
Posts: 207
gixxy is on a distinguished road
Re: Simple Tankdrive with 4 CIMs

Code for my test DriveTrain (although it has an arcade drive method as well.)

Code:
package edu.wpi.first.wpilibj.test;


import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.RobotDrive;

/**
 *
 * @author Gus Michel
 */
public class DriveTrain {
    private int LEFT_FRONT_JAG_PORT = 1;
    private int LEFT_BACK_JAG_PORT = 2;
    private int RIGHT_FRONT_JAG_PORT = 3;
    private int RIGHT_BACK_JAG_PORT = 4;
    private static DriveTrain instance = null;
    private Jaguar leftFront;
    private Jaguar leftBack;
    private Jaguar rightFront;
    private Jaguar rightBack;
    private RobotDrive robotDrive;
    
    private DriveTrain() {
        leftFront = new Jaguar(LEFT_FRONT_JAG_PORT);
        leftBack = new Jaguar(LEFT_BACK_JAG_PORT);
        rightFront = new Jaguar(RIGHT_FRONT_JAG_PORT);
        rightBack = new Jaguar(RIGHT_BACK_JAG_PORT);
        robotDrive = new RobotDrive(leftFront, leftBack, rightFront, rightBack);
    }
    
    public static DriveTrain getInstance() {
        if(instance == null) {
            instance = new DriveTrain();
        }
        return instance;
    }
    
    public void drive(double throttle, double turn) {
        robotDrive.drive(throttle, turn);
    }
    
    public void arcadeDrive(double throttle, double turn) {
        robotDrive.arcadeDrive(throttle, turn);
    }
    
    public void tankDrive(double left, double right) {
        robotDrive.tankDrive(left, right);
    }
    
    public double getLeftFrontSpeed() {
        return leftFront.getSpeed();
    }
    
    public double getLeftBackSpeed() {
        return leftBack.getSpeed();
    }
    
    public double getRightFrontSpeed() {
        return rightFront.getSpeed();
    }
    
    public double getRightBackSpeed() {
        return rightBack.getSpeed();
    }
    
    public void stop() {
        robotDrive.drive(0,0);
    }
}
Reply With Quote
  #13   Spotlight this post!  
Unread 18-01-2012, 19:25
touchdownjesus4's Avatar
touchdownjesus4 touchdownjesus4 is offline
Registered User
AKA: Tyler Vonderhaar
FRC #4028 (Eagle Robotics)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Cincinnati, OH
Posts: 64
touchdownjesus4 is on a distinguished road
Re: Simple Tankdrive with 4 CIMs

Ok so now that I think that the code I wrote will work, I want to put it in the command based template. I watched the videos that Brad Miller posted and I know how the template works but am not sure how to set it up to make the tank drive work.
Reply With Quote
  #14   Spotlight this post!  
Unread 18-01-2012, 20:36
Robby Unruh's Avatar
Robby Unruh Robby Unruh is offline
*insert random dial-up tone here*
FRC #3266 (Robots R Us)
Team Role: Coach
 
Join Date: Feb 2010
Rookie Year: 2010
Location: Eaton, OH
Posts: 338
Robby Unruh will become famous soon enough
Re: Simple Tankdrive with 4 CIMs

Quote:
Originally Posted by touchdownjesus4 View Post
Ok so now that I think that the code I wrote will work, I want to put it in the command based template. I watched the videos that Brad Miller posted and I know how the template works but am not sure how to set it up to make the tank drive work.
Take a look at the GearsBot Robot sample provided. (New Project -> Samples -> FRC Java -> GearsBot)

Interestingly enough, it's actually the same code from the video.

Just make sure you comment out this line in CommandBase.java:
Code:
Subsystem.registerDefaultCommands();

- offtopic edit -
I see you're from Cinci. Looking forward to competing with you guys at Queen City this year.
__________________
[Robots R Us #3266]
2015: Georgia Southern Classic (Winners / Thanks 1319 & 1648!), Queen City
2014: Crossroads, Queen City
2013: Buckeye, Queen City, Crossroads
2012: Buckeye, Queen City

2011: Buckeye
2010: Buckeye
Reply With Quote
  #15   Spotlight this post!  
Unread 18-01-2012, 20:46
touchdownjesus4's Avatar
touchdownjesus4 touchdownjesus4 is offline
Registered User
AKA: Tyler Vonderhaar
FRC #4028 (Eagle Robotics)
Team Role: Programmer
 
Join Date: Jan 2012
Rookie Year: 2012
Location: Cincinnati, OH
Posts: 64
touchdownjesus4 is on a distinguished road
Quote:
Originally Posted by Robby Unruh View Post
Take a look at the GearsBot Robot sample provided. (New Project -> Samples -> FRC Java -> GearsBot)

Interestingly enough, it's actually the same code from the video.

Just make sure you comment out this line in CommandBase.java:
Code:
Subsystem.registerDefaultCommands();

- offtopic edit -
I see you're from Cinci. Looking forward to competing with you guys at Queen City this year.
I think we actually might be traveling to purdue for our regional competition. The queen city regional is on easter weekend and we are a christian school so that wouldn't go so well.

And I did look at the gearsbot code and I wasn't sure if we need to set it up the same way because we aren't coding it to go a certain distance. Would I still set up the drivetrain as a PID subsystem?

I think I all I need to do is add a subsystem, command, and modify both the OI and the RobotMap and I should be good. I'll try it out later and see what I come up with.
__________________
2012 Boilermaker Regional Champions (With 1756 & 1501)
Team Captain, Programmer, Lead Driver

Last edited by touchdownjesus4 : 18-01-2012 at 20:50.
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:16.

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