View Single Post
  #1   Spotlight this post!  
Unread 15-02-2015, 20:53
Tweety Tweety is offline
Registered User
AKA: Amzad Chowdhury
no team
Team Role: Mentor
 
Join Date: Nov 2013
Rookie Year: 2009
Location: New York City
Posts: 3
Tweety is an unknown quantity at this point
Strafing Problem

Hi all,
I'm having issues with the mecanum drive code. Problem is that strafing doesn't work. Robot can turn fine and go forward/back. I referred to how the wheels should be moving when it's strafing and it seems like they are just doing something else. Both sides are moving outwards so its just countering itself.

I read somewhere that I have to invert motors. How do I do it in java?


Code:
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.Gyro;
import edu.wpi.first.wpilibj.CANTalon;
import edu.wpi.first.wpilibj.Compressor;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.networktables.NetworkTable;
import edu.wpi.first.wpilibj.networktables2.type.NumberArray;


public class Robot extends IterativeRobot {
    //LEFT STICK = AXIS  RIGHT STICK = ROTATION
    private Joystick leftJoystick = new Joystick(1);
    private Joystick rightJoystick = new Joystick(2);
    private CANTalon frontLeft = new CANTalon(1);
    private CANTalon rearLeft = new CANTalon(2);
    private CANTalon frontRight = new CANTalon(3);
    private CANTalon rearRight = new CANTalon(4);
    private RobotDrive mecDrive = new RobotDrive(frontLeft, rearLeft, frontRight, rearRight);
    private Gyro gyroscope = new Gyro(1);
    
    //Pneumatics
    private Compressor compressor = new Compressor(1);
    private DoubleSolenoid Gripper = new DoubleSolenoid(1,2);
    
    //Nerd Stuff
    NetworkTable table;
    
   
    public void robotInit() {
        compressor.start();
        table = NetworkTable.getTable("");
    }
       
    public void autonomous() {
        
    }
    
    public void operatorControl() {
        double xValue = 0.0;
        double yValue = 0.0;
        double y = 0.0;
        double x = 0.0;
        double rotation = 0.0;
        double gyroAngle = 0.0;
        double throttle  = 0.0;
                
         while(isOperatorControl() && isEnabled()) {

             //EDC
             x = -leftJoystick.getX();
             y = -leftJoystick.getY();
             rotation = -rightJoystick.getX();
             
             throttle = leftJoystick.getThrottle();
             if (throttle < .5) {
            	 yValue = y * .5;
            	 xValue = x * .5;
             }

             gyroAngle = gyroscope.getAngle();
            
             mecDrive.mecanumDrive_Cartesian(xValue, yValue, rotation, gyroAngle);
                     
         }
    
    }
    
    public void test() {
    
    }
}
Reply With Quote