View Single Post
  #9   Spotlight this post!  
Unread 16-12-2012, 00:32
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: Programming an Arcade Drive

Basic arcade drive in Java:

(Everything in red can be renamed.)

Code:
throttle = joystick.getY();
turnValue = joystick.getX();

leftMtr = throttle + turnValue;
rightMtr = throttle - turnValue;

public double getArcadeLeftMotor() {
        return leftMtr;
    }

public double getArcadeRightMotor() {
        return rightMtr;            
    }

plug in getArcadeLeftMotor() and getArcadeLeftMotor() as the left and right channels in a JoystickDrive object
And that's all you need for a very basic arcade drive. You need to experimentally determine what values the joystick outputs at each position using print statements or a software such as Xpadder and adjust what it's doing accordingly. This setup is determinant on the Y axis "up" being a positive value and the X axis "left" being a negative value.

But the basic code is a bit lacking. At high speeds the robot is going to tend to keep going more and it won't turn so well. It also results in situations where you get bad clipping because of the addition and subtaction. So we make the algorithm a bit more complex...

Code:
throttle = joystick.getY();
turnValue = joystick.getX();

leftMtr = throttle + turnValue;
rightMtr = throttle - turnValue;

public double getArcadeLeftMotor() {
        return leftMtr + skim(rightMtr);
    }

    public double getArcadeRightMotor() {
        return rightMtr + skim(leftMtr);            
    }

public double skim(double v) {
    if (v > 1.0) {
        return -((v - 1.0) * RobotMap.TURNING_GAIN);
    } else if (v < -1.0) {
        return -((v + 1.0) * RobotMap.TURNING_GAIN);
    } return 0; 
    }
What this does is take the excess off if it results in a number greater than 1.0 or less than -1.0 and subtract it from the other side of the robot, after applying a multiplier of less than one to reduce it. You can then experiment with the multiplier to find something that feels better than the original code. A multiplier of 0 is equivalent to the original code.

You can use whatever algorithm you want to smooth it out. skim() is just an example, and some teams have found better algorithms entirely. Play around with it until you find something that works well. Good luck.
__________________
Research is what I’m doing when I don’t know what I’m doing.
- Wernher von Braun
Attending: Raleigh NC Regional

Last edited by F22Rapture : 16-12-2012 at 00:38.
Reply With Quote