View Single Post
  #18   Spotlight this post!  
Unread 14-01-2015, 13:46
Whippet's Avatar
Whippet Whippet is offline
MIT Class of 2020
AKA: Luis Trueba
FRC #4301 (New Tech Narcissists)
Team Role: Alumni
 
Join Date: Feb 2011
Rookie Year: 2011
Location: Cambridge, MA
Posts: 1,187
Whippet has a reputation beyond reputeWhippet has a reputation beyond reputeWhippet has a reputation beyond reputeWhippet has a reputation beyond reputeWhippet has a reputation beyond reputeWhippet has a reputation beyond reputeWhippet has a reputation beyond reputeWhippet has a reputation beyond reputeWhippet has a reputation beyond reputeWhippet has a reputation beyond reputeWhippet has a reputation beyond repute
Send a message via Yahoo to Whippet
Re: Encoders on mecanum drive?

Quote:
Originally Posted by idahorobot View Post
Do you or the community have some code sample to illustrate this?
Code:
/* 
 * This is the experimental code for the 2015 robot.  DO NOT USE FOR COMPETITION!  
 * All code that is useful will be in  a separate project.
 */
package org.usfirst.frc.team4301.robot;


import edu.wpi.first.wpilibj.SampleRobot;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Gyro;



public class Robot extends SampleRobot {
    RobotDrive myRobot;
    Joystick DriverStick;
    Joystick OperatorStick;
    Gyro gyro;

    public Robot() {
        myRobot = new RobotDrive(0, 1, 2, 3);
        myRobot.setExpiration(0.1);
        DriverStick = new Joystick(0);
        gyro = new Gyro(0);
    }

    /**
     * Drive left & right motors for 2 seconds then stop
     */
    public void autonomous() {        
    }

    public void operatorControl() {
        myRobot.setSafetyEnabled(true);
        while (isOperatorControl() && isEnabled()) {
        	//set x, y, and z values
        	double x = DriverStick.getX();
        	double y = DriverStick.getY();
        	double z = DriverStick.getZ();
            myRobot.mecanumDrive_Cartesian(x, y, z, gyro.getAngle());
            if(DriverStick.getTrigger() == true) {
            	gyro.reset();
            }
            Timer.delay(0.005);		// wait for a motor update time
            
        }
    }

    /**
     * Runs during test mode
     */
    public void test() {
    }
}
I have bolded the lines to pay attention to. Replace "4301" and all team-related items with your own code.
__________________
2010: FRC 3043, Build Assistant
2011: FRC 3043, Head of Minibot subteam; FLL 12762, Team Captain
2012: FRC 3043, Electrical; FLL 12762, Team Captain; FTC 5670, Team Captain
2013: FRC 4301, Electrical, Team Co-Captain
2014: FRC 4301, Electrical/Programming, Team Co-Captain
2015: FRC 4301, Electrical/Programming, Team Captain
2016: FRC 4301, Chief Technical Officer; FTC 10860, 10861, and 11004: Mentor. Winner, Hub City Regional (3310 & 4063)

Last edited by Whippet : 14-01-2015 at 13:48.