View Single Post
  #11   Spotlight this post!  
Unread 29-01-2015, 23:15
ProgrammerMatt ProgrammerMatt is offline
Programmer-Electrical-Mechanical
FRC #0228 (Gus)
Team Role: Mentor
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Southington
Posts: 138
ProgrammerMatt is just really niceProgrammerMatt is just really niceProgrammerMatt is just really niceProgrammerMatt is just really nice
Re: Issue with Mecanum Test Code

Quote:
Originally Posted by LFRobotics View Post
I uploaded this code and the second I press Enable for teleop the robot goes crazy and all the motors fire. This program is only made to straffe and go forwards/backwards.

Here it is:

Code:
package org.usfirst.frc.team4623.robot;

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.SpeedController;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;

/**
 * The VM is configured to automatically run this class, and to call the
 * functions corresponding to each mode, as described in the IterativeRobot
 * documentation. If you change the name of this class or the package after
 * creating this project, you must also update the manifest file in the resource
 * directory.
 */
public class Robot extends IterativeRobot {
	public XBox stick = new XBox(0);
	
	SpeedController frontLeftMotor = new Jaguar(0);
    SpeedController frontRightMotor = new Jaguar(1);
    SpeedController rearLeftMotor = new Jaguar(2);
    SpeedController rearRightMotor = new Jaguar(3);
	
    /**
     * This function is run when the robot is first started up and should be
     * used for any initialization code.
     */
    public void robotInit() {
    	
    }
    
    /**
     * This function is run once each time the robot enters autonomous mode
     */
    public void autonomousInit() {
    	
    }

    /**
     * This function is called periodically during autonomous
     */
    public void autonomousPeriodic() {
    
    }
    
    /**
     * This function is called once each time the robot enters tele-operated mode
     */
    public void teleopInit(){
    	
    	
    }

    /**
     * This function is called periodically during operator control
     */
    public void teleopPeriodic() {
        
                   mecanumDrive(
                    (XBox.LEFTJOY_X+XBox.LEFTJOY_Y)/2,
                    (XBox.LEFTJOY_Y-XBox.LEFTJOY_X)/2,
                    -(XBox.LEFTJOY_Y-XBox.LEFTJOY_X)/2,
                    -(XBox.LEFTJOY_X+XBox.LEFTJOY_Y)/2);
      
      }
    
    /**
     * This function is called periodically during test mode
     */
    public void testPeriodic() {
    	LiveWindow.run();
    }
    
    public void mecanumDrive(double FL, double RL, double FR, double RR)   {
        frontLeftMotor.set(FL);
        rearLeftMotor.set(RL);
        frontRightMotor.set(FR);
        rearRightMotor.set(RR);
    }
    
}
It is pulling XBox stuff from this class:

Code:
package org.usfirst.frc.team4623.robot;


import edu.wpi.first.wpilibj.Joystick;

/**
 *
 * @author FrankyMonez
 */
public class XBox extends Joystick{
    
    public XBox(int port) {
        super(port);
    }
    
    public static final int 
            A_BUTTON = 1,
            B_BUTTON = 2,
            X_BUTTON = 3,
            Y_BUTTON = 4,
            START_BUTTON = 8,
            BACK_BUTTON = 7,
            LS_BUTTON = 9,
            RS_BUTTON = 10,
            RB_BUTTON = 6,
            LB_BUTTON = 5,
            LEFTJOY_Y = 2,
            LEFTJOY_X = 1,
            RIGHTJOY_Y = 5,
            RIGHTJOY_X = 4,
            LEFT_TRIGGER = 3,
            RIGHT_TRIGGER = 3;
    
    public boolean getButtonA() {
     return getRawButton(A_BUTTON);
}
    
    public boolean getButtonB() {
        return getRawButton(B_BUTTON);
    }
    
    public boolean getButtonX() {
        return getRawButton(X_BUTTON);
    }
    
    public boolean getButtonY() {
        return getRawButton(Y_BUTTON);
    }
    
    public boolean getButtonRB() {
        return getRawButton(RB_BUTTON);
    }
    
    public boolean getButtonLB() {
        return getRawButton(LB_BUTTON);
    }
    
    public boolean getButtonRS() {
        return getRawButton(RS_BUTTON);
    }
    
    public boolean getButtonLS() {
        return getRawButton(LS_BUTTON);
    }
    
    public boolean getButtonStart() {
        return getRawButton(START_BUTTON);
    }
    
    public boolean getButtonBack() {
        return getRawButton(BACK_BUTTON);
    }
    
    public double getLeftJoyY() {
        return getRawAxis(LEFTJOY_Y);
    }
    
    public double getLeftJoyX() {
        return getRawAxis(LEFTJOY_X);
    }
    
    public double getRightJoyY() {
        return getRawAxis(RIGHTJOY_Y);
    }
    
    public double getRightJoyX(){
        return getRawAxis(RIGHTJOY_X);
    }
    
    public double getRightTrigger() {
        return -Math.min(getRawAxis(RIGHT_TRIGGER), 0);
    }
    
    public double getLeftTrigger() {
        return Math.max(getRawAxis(LEFT_TRIGGER), 0);
    }
}
THANKS for the help!
The wpilibj has a built in class for mecanum under robotDrive.
__________________
2015-2016 CSA
Software Engineering Student @ Johnson & Wales University
Team 228, Gus Robotics Inc.
Facebook
FLL Mentor for 1107, Edison Eagles!
2015- CT State Champions
2012- WPI Finalist(Thanks 1884 and 549), Spirt, Best Website
2011- WPI Chairman's award winners!
2010- WPI Champions! (thanks 230 & 20), WPI Engineering Inspiration, CT Best Website, CT VEX Champions (VRC228, VRC228b) (21-1-0)
2009- QCC VEX Champions (VRC228) (11-0-0), Innovate Award (VRC228)
Reply With Quote