Go to Post I think the answer you will get will be the same we have been saying since post #2 on page 1. - KenWittlief [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

 
Reply
Thread Tools Rate Thread Display Modes
  #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
  #2   Spotlight this post!  
Unread 27-01-2014, 19:26
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,590
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Mecanum-Code

What behavior do you see?

I noticed that the joysticks are only read once at the beginning of the program, rather then inside telopPeriodic.
Reply With Quote
  #3   Spotlight this post!  
Unread 27-01-2014, 21:10
nyaculak nyaculak is offline
Registered User
FRC #0053 (Area 53)
Team Role: Programmer
 
Join Date: Oct 2011
Rookie Year: 2011
Location: Maryland
Posts: 28
nyaculak will become famous soon enough
Re: Mecanum-Code

Like Joe Ross said, your code only evaluates the value of the axes once, before teleoperated mode is ever started. To fix this, you need to retrieve the values of the axes you wish to use at the beginning of the teleop loop.

Also, for a mecanum drive robot, you want to call a mecanum drive function instead of the tankDrive() function. The RobotDrive defines two mecanum drive functions: mecanumDrive_Cartesian and mecanumDrive_Polar. Take a look at the Javadoc to learn how to implement them.
__________________
2013 MUC DC 3rd Place, FRC DC Regional, FRC Chesapeake Regional
2012 FRC DC Regional, FRC Chesapeake Regional
ERHS Robotics Club
- FRC Team 53 "Area 53"
www.erhsroboticsclub.org
Reply With Quote
  #4   Spotlight this post!  
Unread 28-01-2014, 15:39
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
Re: Mecanum-Code

Quote:
Originally Posted by Joe Ross View Post
What behavior do you see?

I noticed that the joysticks are only read once at the beginning of the program, rather then inside telopPeriodic.
To Joe, The program is not recognizing any inputs at all from the xbox controller but are in fact recognizing from the attack 3 controller with the kit of parts.
Reply With Quote
  #5   Spotlight this post!  
Unread 28-01-2014, 15:42
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
Re: Mecanum-Code

Quote:
Originally Posted by nyaculak View Post
Like Joe Ross said, your code only evaluates the value of the axes once, before teleoperated mode is ever started. To fix this, you need to retrieve the values of the axes you wish to use at the beginning of the teleop loop.

Also, for a mecanum drive robot, you want to call a mecanum drive function instead of the tankDrive() function. The RobotDrive defines two mecanum drive functions: mecanumDrive_Cartesian and mecanumDrive_Polar. Take a look at the Javadoc to learn how to implement them.
We added a fail safe system for if any reason the mecanum code doesn't work or the driver doesn't feel safe using the mecanum code we added tank drive which is a drive style our team feels very comfortable with while the mecanum code is new.
Reply With Quote
  #6   Spotlight this post!  
Unread 28-01-2014, 17:00
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,102
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Mecanum-Code

Quote:
Originally Posted by FRC TEAM 4085 View Post
We added a fail safe system for if any reason the mecanum code doesn't work or the driver doesn't feel safe using the mecanum code we added tank drive which is a drive style our team feels very comfortable with while the mecanum code is new.
Food for thought, here's another option:

Joystick1 drives the vehicle in Arcade mode (Y fore/aft and X is rotate);

Joystick2 controls strafe (X axis controls strafe right/left).


Leave hands off Joystick2 and you've got basic Arcade drive.


Reply With Quote
  #7   Spotlight this post!  
Unread 28-01-2014, 19:26
nyaculak nyaculak is offline
Registered User
FRC #0053 (Area 53)
Team Role: Programmer
 
Join Date: Oct 2011
Rookie Year: 2011
Location: Maryland
Posts: 28
nyaculak will become famous soon enough
Re: Mecanum-Code

Quote:
Originally Posted by FRC TEAM 4085 View Post
We added a fail safe system for if any reason the mecanum code doesn't work or the driver doesn't feel safe using the mecanum code we added tank drive which is a drive style our team feels very comfortable with while the mecanum code is new.
Sorry, I should have looked at the rest of your teleop code.

Quote:
To Joe, The program is not recognizing any inputs at all from the xbox controller but are in fact recognizing from the attack 3 controller with the kit of parts.
You might want to check that the drivers for the Xbox controller are installed (I've never had a problem with it; one would think the Microsoft hardware and software would work well together). You should be able to see the Xbox controller as a device somewhere in the Windows Control Panel. Does the driver station recognize it as a controller when you plug it in?

Also, you'll still want to move the retrieval of the axis values to the beginning of the loop.

Another tip: the tangent of an angle equals opposite over adjacent (y/x).
__________________
2013 MUC DC 3rd Place, FRC DC Regional, FRC Chesapeake Regional
2012 FRC DC Regional, FRC Chesapeake Regional
ERHS Robotics Club
- FRC Team 53 "Area 53"
www.erhsroboticsclub.org
Reply With Quote
  #8   Spotlight this post!  
Unread 29-01-2014, 12:54
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 592
BradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant future
Re: Mecanum-Code

A couple things that might be helpful for you:

This ChiefDelphi post about Mecanum drive and C++
http://www.chiefdelphi.com/forums/sh...ad.php?t=88686

and this ScreenSteps document that essentially extracted the sample program from the above CD post:
http://wpilib.screenstepslive.com/s/...-mecanum-drive
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
Reply With Quote
  #9   Spotlight this post!  
Unread 29-01-2014, 13:07
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,590
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Mecanum-Code

Quote:
Originally Posted by FRC TEAM 4085 View Post
To Joe, The program is not recognizing any inputs at all from the xbox controller but are in fact recognizing from the attack 3 controller with the kit of parts.
I can't see how it's possible for the program you posted to recognize inputs from any joystick. Are you sure that is the program you were testing with the Attack 3?
Reply With Quote
Reply


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 13:11.

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