Go to Post I am mentored by individuals younger than 18 all the time. - Taylor [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 28-01-2015, 17:29
LFRobotics's Avatar
LFRobotics LFRobotics is offline
Registered User
FRC #4623
 
Join Date: Jan 2014
Location: Little Falls, MN
Posts: 95
LFRobotics is on a distinguished road
Issue with Mecanum Test Code

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!
Reply With Quote
  #2   Spotlight this post!  
Unread 28-01-2015, 20:10
Joey1939's Avatar
Joey1939 Joey1939 is offline
Registered User
AKA: Joey Holliday
FRC #1939 (Kuhnigits)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Kansas City, Missouri
Posts: 142
Joey1939 has a spectacular aura aboutJoey1939 has a spectacular aura aboutJoey1939 has a spectacular aura about
Re: Issue with Mecanum Test Code

Please look at my post on your other thread. You aren't reading the actual joystick values, but instead you are reading static enums.
Reply With Quote
  #3   Spotlight this post!  
Unread 29-01-2015, 10:21
LFRobotics's Avatar
LFRobotics LFRobotics is offline
Registered User
FRC #4623
 
Join Date: Jan 2014
Location: Little Falls, MN
Posts: 95
LFRobotics is on a distinguished road
Re: Issue with Mecanum Test Code

Okay ill try that ASAP and let you know if it works
Reply With Quote
  #4   Spotlight this post!  
Unread 29-01-2015, 11:41
LFRobotics's Avatar
LFRobotics LFRobotics is offline
Registered User
FRC #4623
 
Join Date: Jan 2014
Location: Little Falls, MN
Posts: 95
LFRobotics is on a distinguished road
Re: Issue with Mecanum Test Code

Okay so I changed it to this:

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(
                    (stick.getLeftJoyX()+stick.getLeftJoyY())/2,
                    (stick.getLeftJoyY()-stick.getLeftJoyX())/2,
                    -(stick.getLeftJoyY()-stick.getLeftJoyX())/2,
                    -(stick.getLeftJoyX()+stick.getLeftJoyY())/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);
    }
    
}
But now only the Y axis of the left joystick does anything and it only activates two motors. And then the left trigger activates two motors. Im so confused because I never even took the values for the left trigger. Is my mecanum code even right - like will it even ever work. And if not how do I program it to work?

THANKS!
Reply With Quote
  #5   Spotlight this post!  
Unread 29-01-2015, 12:54
Joey1939's Avatar
Joey1939 Joey1939 is offline
Registered User
AKA: Joey Holliday
FRC #1939 (Kuhnigits)
Team Role: Programmer
 
Join Date: Jan 2014
Rookie Year: 2014
Location: Kansas City, Missouri
Posts: 142
Joey1939 has a spectacular aura aboutJoey1939 has a spectacular aura aboutJoey1939 has a spectacular aura about
Re: Issue with Mecanum Test Code

I recommend using the RobotDrive class. It will handle taking joystick inputs and directly changing them into motor outputs.
Reply With Quote
  #6   Spotlight this post!  
Unread 29-01-2015, 17:39
LFRobotics's Avatar
LFRobotics LFRobotics is offline
Registered User
FRC #4623
 
Join Date: Jan 2014
Location: Little Falls, MN
Posts: 95
LFRobotics is on a distinguished road
Re: Issue with Mecanum Test Code

Okay so I changed it to this:

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

import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Jaguar;
import edu.wpi.first.wpilibj.RobotDrive;
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 {
	
	
	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);
    
    RobotDrive drive = new RobotDrive(0, 1, 2, 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() {
    
			drive.mecanumDrive_Polar(stick.getLeftJoyY(), stick.getLeftJoyX(), 0);         
    	
      }
    
    /**
     * 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);
    }
    
}
And now the DriverStation says this:

Code:
ERROR Unhandled exception instantiating robot org.usfirst.frc.team4623.robot.Robot edu.wpi.first.wpilibj.util.AllocationException: PWM channel 1 is already allocated at [edu.wpi.first.wpilibj.PWM.initPWM(PWM.java:126), edu.wpi.first.wpilibj.PWM.<init>(PWM.java:145), edu.wpi.first.wpilibj.SafePWM.<init>(SafePWM.java:33), edu.wpi.first.wpilibj.Talon.<init>(Talon.java:49), edu.wpi.first.wpilibj.RobotDrive.<init>(RobotDrive.java:115), org.usfirst.frc.team4623.robot.Robot.<init>(Robot.java:26), sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method), sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62), sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45), java.lang.reflect.Constructor.newInstance(Constructor.java:408), java.lang.Class.newInstance(Class.java:433), edu.wpi.first.wpilibj.RobotBase.main(RobotBase.java:197)]
I am sooooo confused - neither of my programs work and I have no idea why
Reply With Quote
  #7   Spotlight this post!  
Unread 29-01-2015, 18:00
LFRobotics's Avatar
LFRobotics LFRobotics is offline
Registered User
FRC #4623
 
Join Date: Jan 2014
Location: Little Falls, MN
Posts: 95
LFRobotics is on a distinguished road
Re: Issue with Mecanum Test Code

The other thing is is that we have cartesian but I can't seem to be able to import cartesian in Eclipse
Reply With Quote
  #8   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
  #9   Spotlight this post!  
Unread 30-01-2015, 20:40
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,586
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: Issue with Mecanum Test Code

Quote:
Originally Posted by LFRobotics View Post
The other thing is is that we have cartesian but I can't seem to be able to import cartesian in Eclipse
It would help to describe what you've tried and what the error messages are.
Reply With Quote
  #10   Spotlight this post!  
Unread 02-02-2015, 14:46
3786KRRobotics 3786KRRobotics is offline
Registered User
FRC #3786
 
Join Date: Feb 2015
Location: Kent, Washington
Posts: 4
3786KRRobotics is an unknown quantity at this point
Re: Issue with Mecanum Test Code

Quote:
Originally Posted by LFRobotics View Post
Code:
	SpeedController frontLeftMotor = new Jaguar(0);
    SpeedController frontRightMotor = new Jaguar(1);
    SpeedController rearLeftMotor = new Jaguar(2);
    SpeedController rearRightMotor = new Jaguar(3);
    
    RobotDrive drive = new RobotDrive(0, 1, 2, 3);
What is most likely happening is that you are instantiating the SpeedControllers with PWM channels of 0,1,2 and 3 and then RobotDrive is attempting to do the same therefore throwing the exception.

RobotDrive has two constructors. One, which you are currently using in your code, takes in integers for the PWM channels of the motor controllers. The other takes in SpeedController objects for the motor controllers.

Both do so in this order:
frontLeftMotor
rearLeftMotor
frontRightMotor
rearRightMotor

If you want control over the motor controllers elsewhere I recommend passing those into the constructor rather than just the PWM channels
Reply With Quote
  #11   Spotlight this post!  
Unread 03-02-2015, 11:24
LFRobotics's Avatar
LFRobotics LFRobotics is offline
Registered User
FRC #4623
 
Join Date: Jan 2014
Location: Little Falls, MN
Posts: 95
LFRobotics is on a distinguished road
Re: Issue with Mecanum Test Code

Okay I have been working tons on this and put up a new post with new code that should work but doesn't
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 18:08.

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