Go to Post it's much easier to build safety in to a system than to add it on a Thursday at a regional. - dtengineering [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 14-11-2013, 09:53
Matt_4505 Matt_4505 is offline
Registered User
FRC #4505
Team Role: Programmer
 
Join Date: Nov 2012
Rookie Year: 2012
Location: United States
Posts: 16
Matt_4505 is on a distinguished road
Tank Drive Issues

Hello,
This year I have been switching my team over to Java and we have started to work with a Command Based control system. I built my drivetrain in RobotBuilder and then added code for the Tank Drive. Unfortunately, when I try to run the code, the left Joystick controls both sides of the robot instead of just the left side.

The Code:

DriveTrain subsystem:

public void tankDrive(double leftJoystickValue, double rightJoystickValue){
robotDrive.tankDrive(leftJoystickValue, rightJoystickValue);
}
public double deadZone (double val) {
return val > 0.25 || val < -0.25? val: 0;
}
public double adjustSpeed (double val){
return Robot.oi.leftJoystick.getRawButton(1)? val*.75: (Robot.oi.rightJoystick.getRawButton(1)? val*.75: val);

}


DriveCommand:

protected void execute() {
Robot.drivetrain.tankDrive(Robot.drivetrain.adjust Speed(Robot.drivetrain.deadZone(Robot.oi.getleftJo ystick().getY())),
Robot.drivetrain.adjustSpeed(Robot.drivetrain.dead Zone(Robot.oi.getrightJoystick().getY())));
}


Thanks
Reply With Quote
  #2   Spotlight this post!  
Unread 14-11-2013, 13:15
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,567
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Tank Drive Issues

I don't see anything in the code that you posted that would output the left joystick to both left and right. Are your joystick declarations correct?
Reply With Quote
  #3   Spotlight this post!  
Unread 14-11-2013, 13:18
BigJ BigJ is offline
Registered User
AKA: Josh P.
FRC #1675 (Ultimate Protection Squad)
Team Role: Engineer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Milwaukee, WI
Posts: 945
BigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond reputeBigJ has a reputation beyond repute
Re: Tank Drive Issues

I'm not entirely sure what is intended to be going on in the adjustSpeed method (chained ternary operators are pretty bad for that), but you're using it for each side's input into your tank drive and it seems to be depending on a specific combination of inputs.

EDIT: nevermind I get it now, my only remaining suspicions are the same as Joe's.
Reply With Quote
  #4   Spotlight this post!  
Unread 14-11-2013, 13:48
otherguy's Avatar
otherguy otherguy is offline
sparkE
AKA: James
FRC #2168 (The Aluminum Falcons)
Team Role: Mentor
 
Join Date: Feb 2010
Rookie Year: 2009
Location: CT
Posts: 430
otherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to beholdotherguy is a splendid one to behold
Re: Tank Drive Issues

To answer your question, I would take a look at the code in the OI class. getrightJoystick() and getleftJoystick() may not be returning what you're expecting.


One suggestion to make your code a little easier to read/use (this isn't goign to solve your problem)...

By changing what the tankDrive method does slightly you can clean up your "DriveCommand" code significantly, without changing how things work.

Code:
//DriveTrain subsystem:

public void tankDrive(double leftJoystickValue, double rightJoystickValue){
    robotDrive.tankDrive(
        Robot.drivetrain.adjustSpeed(Robot.drivetrain.deadZone(leftJoystickValue)),
        Robot.drivetrain.adjustSpeed(Robot.drivetrain.deadZone(rightJoystickValue)));
}

public double deadZone (double val) {
    return val > 0.25 || val < -0.25? val: 0;
}

public double adjustSpeed (double val){
    return Robot.oi.leftJoystick.getRawButton(1)? val*.75: (Robot.oi.rightJoystick.getRawButton(1)? val*.75: val);
}


//DriveCommand:

protected void execute() {
    Robot.drivetrain.tankDrive(
        Robot.oi.getleftJoystick().getY(),
        Robot.oi.getrightJoystick().getY());
}
Maybe it's just my preference, but I prefer logic to be performed by the subsystem. That way if multiple commands call the exposed methods, they always perform in a consistent manner, and it reduces code duplication at the Command level.
__________________
http://team2168.org
Reply With Quote
  #5   Spotlight this post!  
Unread 14-11-2013, 20:10
Pault's Avatar
Pault Pault is offline
Registered User
FRC #0246 (Overclocked)
Team Role: College Student
 
Join Date: Jan 2013
Rookie Year: 2012
Location: Boston
Posts: 618
Pault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond reputePault has a reputation beyond repute
Re: Tank Drive Issues

Agreed that you probably have a problem in your OI. And tell us whether you are using 2 joysticks or a video game controller (ie XBox/PS3 controller).

Also, I am glad to see a team using robot builder. Such an amazing yet underused tool, especially for your first year using Java/C++.
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 22:34.

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