Go to Post Amazing how great minds think alike! - Jack Jones [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

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Spotlight this post!  
Unread 21-01-2017, 17:00
dmelcer9 dmelcer9 is offline
Registered User
AKA: Daniel
FRC #0810 (Mechanical Bulls)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2012
Location: Smithtown
Posts: 51
dmelcer9 is an unknown quantity at this point
Re: Problems with Java in Eclipse **please help!**

One of the nice things about the FIRST Robotics Library (WPILib) is that you don't need to control all four motors individually!

Take a look at your "robotDrive41" object. It has two methods that you probably care about, arcadeDrive and tankDrive. It's your choice which one to use.

For the purposes of this, I'll use arcade drive in examples, but substitute as necessary.

If you haven't yet, add a joystick in RobotBuilder. You can find it under the "OI" header in RobotBuilder. Drag it under Operator Interface. Alternatively, right click Operator Interface and add the joystick.

In the subsystem class, you can have a method that looks something like this:

Code:
public void arcadeDrive(double moveValue, double rotateValue){
  robotDrive41.arcadeDrive(moveValue, rotateValue);
}
For commands, you only need to have one command that checks the value of the joystick(s) and calls the method you just created in the subsystem.

Before you create the command, you'll want to change a few things (some of these don't change all that well after you create the command and export to Java):

http://imgur.com/V7BAYne

The first thing that's different is the "Requires" line. This line tells the robot that this command is the only command that can use the Drive subsystem when it's running. You'll see why it's really useful in a little bit.

Second is unchecking the "Button on SmartDashboard". It makes no sense to have a button for checking the joysticks.

Third is the parameter, speed. To add a parameter, click on the grey box and then "Add Parameter" in the popup. Make sure that you click enter after changing the name of the parameter. The Type should be double. Click save and close. This speed parameter will be useful later.

Code:
public class DriveCommand extends Command{
  ...
  public void execute(){
    double move= Robot.oi.getJoystick().getX();
    double rotate= -Robot.oi.getJoystick().getY();
I'm going to insert a few notes in here. First, the getY might need to be negated because of an oddity in how joysticks are designed. Secondly, some joysticks are a bit off and the axes may return a (small) value even when they aren't being touched. The following two lines fix that:

Code:
if(Math.abs(move)<.1) move = .0;
if(Math.abs(rotate)<.1) rotate=0;
Lastly, remember the speed parameter? What we'll do is multiply both values by the speed parameter before using the values. So if speed is 1, moving the joystick all the way will make the robot move at full speed. If speed is .5, moving the joystick all the way will make the robot move at half speed. This is really useful for fine maneuvers and lining up.

Code:
move *= m_speed;
rotate *= m_speed;

Robot.drive.arcadeDrive(move, rotate);
Now we have the command set up, but it won't actually run. We need to tell the program that unless something unusual is happening, we want to keep running that drive command. To do this, go into the Drive Subsystem (in Robot Builder), and set the default command to be DriveCommand. Since normally you want the bot to be full speed, set the speed parameter to 1 in Default command parameters.

Make sure to press enter before clicking "Save and close". It will not save otherwise. If unsure, re-open the "Edit parameters" popup to check that the value is still 1.

http://imgur.com/pGeDcWH

Lastly, let's make it so that if you hold down a button, the robot goes at half speed (note that depending on how your robot is mechanically, you may want .6 or .7 speed in the program to actually go half speed. Experiment until it's how you like it).

Drag a button under the joystick (it's under the OI header in RobotBuilder, or you can right click on the joystick "folder" and add the button there).

Name the button something like "SlowDownButton". Set which joystick and button you want it to be bound to. The button should trigger the DriveCommand again, but with a slower speed. Again, when you set the speed, make sure to click enter and all of that. Leave the "When to Run" on whileHeld:

http://imgur.com/fN6oF8P

Export everything, save, and deploy. Reply if you have any questions or issues. Good luck in competition!
Reply With Quote
 


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:15.

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