Go to Post Anyone else think we're (including me) a little obsessed? The seasons over and were already onto the next one. - Bjenks548 [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 27-01-2014, 19:21
FRC TEAM 4085 FRC TEAM 4085 is offline
Registered User
AKA: Warren
FRC #4085 (technical difficulties)
Team Role: Scout
 
Join Date: Jan 2014
Rookie Year: 2013
Location: Reynoldsburg Ohio
Posts: 3
FRC TEAM 4085 is an unknown quantity at this point
Question Mecanum-Code

This year we are trying to use mecanum wheels for the first time. However, we are having some programming issues when it comes to using different controllers. We are currently trying to find a code to work an Xbox 360 controller. Below is the current code that we are trying to use, but we can't seem to get it to work. If you have any advice on what we should try or do, please let us know. Also, we are a Java only team, as we have no other experience with other languages.

Code:
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2008. All Rights Reserved.                             */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project.                                                               */
/*----------------------------------------------------------------------------*/

package edu.wpi.first.wpilibj.templates;


import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.buttons.Button;
import edu.wpi.first.wpilibj.buttons.JoystickButton;
import com.sun.sqawk.util.MathUtils;


//Mecanum class. We are using IterativeRobot as SimpleRobot was not working.


public class RobotTemplate extends IterativeRobot {
    //Global Settings:
    //PWN Positions
    private static final int FRONT_LEFT_PWM = 1;
    private static final int FRONT_RIGHT_PWM = 2;
    private static final int REAR_LEFT_PWM = 4;
    private static final int REAR_RIGHT_PWM = 3;
    
    //Joystick Threshold
    private static final double THRESHOLD = 0.2;
    
    
    //Get the joysticks (keep joy* naming system so it can be adjusted later)
    //Joystick joy1 = new Joystick(1);
    Joystick joy2 = new Joystick(2);
    Joystick joy3 = new Joystick(3);
    Joystick mXboxController = new Joystick(1);
    double leftX = mXboxController.getRawAxis(1);
    double leftY = mXboxController.getRawAxis(2);
    double rightX = mXboxController.getRawAxis(4);
    double rightY = mXboxController.getRawAxis(5);
    boolean trigger = mXboxController.getRawButton(6);
    //Get the jaguars
    Jaguar front_right = new Jaguar(FRONT_RIGHT_PWM);
    Jaguar front_left = new Jaguar(FRONT_LEFT_PWM);
    Jaguar rear_right = new Jaguar(REAR_RIGHT_PWM);
    Jaguar rear_left = new Jaguar(REAR_LEFT_PWM);
    
    //Setup RobotDrive
    RobotDrive drive = new RobotDrive(front_right, front_left, rear_right, rear_left);
   
        
    //Button button1L = new JoystickButton(joy1, 1);
    

    
    //When robot starts
    public void robotInit() {
        //Invert only the right side motors. Keep the left side normal.
        
        //Disable the Watchdog as it can cause issues with this version of java.
        
    }
    
    //When robot is disabled
    public void disabledInit() {
        //Stop the motors for safety
        front_left.set(0);
        rear_left.set(0);
        front_right.set(0);
        rear_right.set(0);
        //Log disabled status
        
    }

    //Periodically called during autonomous
    public void autonomousPeriodic() {
        
    }
    
    //When robot is started in autonomous
    public void autonomousInit() {
        //Set the iOS boolean to the opposite of digital input 1.
        
        //Log initiation success
        
    }
    
    //Called at the start of teleop
    public void teleopInit() {
        //Log initiation success
        
    }
    
    //Periodically called during teleop
    public void teleopPeriodic() {
       
       if(mXboxController.getRawButton(6)){
           
        drive.tankDrive(leftY, rightY);
            Timer.delay(0.01);    
        
                    
    }  
        
        else{
           
            double X, Y, Z;
        //Check if using iOS interface or not
        
        {
            //Standard controls
            X = leftX;
            Z = leftY;
            Y = rightX;
        }
        //Threshold
        if( Math.abs(X) < THRESHOLD ){
            X = 0;
        }
        if( Math.abs(Y) < THRESHOLD ){
            Y = 0;
        }
        if( Math.abs(Z) < THRESHOLD ){
            Z = 0;
        }
        //Get the magnitude using the distance formula
        double magnitude = Math.sqrt((X*X)+(Y*Y));
        //Normalize the value
        if( magnitude > 1 ){
            magnitude = 1;
        }
        
        double Direction; //Defineing the direction
        //        Direction = Math.tan(X/Y); //Tan of pheta is equal to the ajacent over the opposite.
                Direction = MathUtils.atan(X/Y); //Figured out how to do it added a Math(Utils).atan for it to find it!
        //Drive
        drive.mecanumDrive_Polar( magnitude, Direction, Z);
           
   
            
}
}

}
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 12:46.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi