View Single Post
  #3   Spotlight this post!  
Unread 13-01-2016, 21:57
FRCteam5837 FRCteam5837 is offline
Registered User
FRC #5837
 
Join Date: Jan 2016
Location: Waterloo
Posts: 9
FRCteam5837 is an unknown quantity at this point
Re: JAVA RobotDrive Motors Signal Out of Sync

Here is the current code we are using, for a controller we are using the Logitech X30 flight stick.
Code:

package org.usfirst.frc.team5837.robot;

import edu.wpi.first.wpilibj.CameraServer;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Victor;


public class Robot extends IterativeRobot {
	Victor R_Motor = new Victor(1);
	Victor L_Motor = new Victor(0);
	RobotDrive chassis = new RobotDrive(R_Motor ,L_Motor);
	
	Joystick drive = new Joystick(0);
	
	int autoLoopCounter;
	
	double yAxis = drive.getY();
	double xAxis = drive.getX();
	double slider = drive.getRawAxis(3);
	
	double yMath;
	double xMath;
	double sliderMath;
	
    /**
     * This function is run when the robot is first started up and should be
     * used for any initialization code.
     */
    public void robotInit() {
    	CameraServer server = CameraServer.getInstance();
    	server.setQuality(50);
    	server.startAutomaticCapture("cam0");	
		
    }
	
	/**
     * This function is called once each time the robot enters Disabled mode.
     * You can use it to reset any subsystem information you want to clear when
	 * the robot is disabled.
     */
    public void disabledInit(){

    }
	
	public void disabledPeriodic() {
		
	}

	
    public void autonomousInit() {
    	autoLoopCounter = 0;
    }

    /**
     * This function is called periodically during autonomous
     */
    public void autonomousPeriodic() {
    	
    	
    }

    public void teleopInit() {
    	
    }

    /**
     * This function is called periodically during operator control
     */
    public void teleopPeriodic() {
    
    	xAxis = drive.getX();
    	yAxis = drive.getY();
    	slider = drive.getRawAxis(3);
    	
    	sliderMath = Math.abs((slider-1)/2);
    	
    	if (Math.abs(xAxis) < 0.25) {
    		xMath = 0;
    	}
    	else {
    		xMath = Math.signum(xAxis)*(Math.abs(xAxis) - .25)*1.333*sliderMath;
    	}
    	
    	if (Math.abs(yAxis) < 0.25){
    		yMath = 0;
    	}
    	else {
    		yMath = Math.signum(yAxis)*(Math.abs(yAxis) - .25)*1.333*sliderMath;
    	}
    	if (drive.getRawButton(2)){
       chassis.arcadeDrive(yMath, xMath);
    	}
       
    }
    
    
    public void testPeriodic() {
    }
}