View Single Post
  #8   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